Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix logs & annotations
  • Loading branch information
hexi.ghx committed Feb 21, 2023
commit f53e20f99815f40757c1b0f5c721a4365ffea3f6
4 changes: 2 additions & 2 deletions pkg/controller/cronexecutor.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ func (ce *CronHPAExecutor) FindJob(job CronJob) (bool, FailedFindJobReason) {
entries := ce.Engine.Entries()
for _, e := range entries {
if e.Job.ID() == job.ID() {
// clean up out of date jobs when it reach maxOutOfDateTimeout
// clean up out of date jobs when it reached maxOutOfDateTimeout
if e.Next.Add(maxOutOfDateTimeout).After(time.Now()) {
return true, ""
}
log.Warningf("The job %s is out of date and need to be clean up.", job.Name())
log.Warningf("The job %s(job id %s) in cronhpa %s namespace %s is out of date.", job.Name(), job.ID(), job.CronHPAMeta().Name, job.CronHPAMeta().Namespace)
return false, JobTimeOut
}
}
Expand Down
9 changes: 6 additions & 3 deletions pkg/controller/cronhorizontalpodautoscaler_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func (r *ReconcileCronHorizontalPodAutoscaler) Reconcile(request reconcile.Reque
if errors.IsNotFound(err) {
// Object not found, return. Created objects are automatically garbage collected.
// For additional cleanup logic use finalizers.
log.Infof("GC start for: cronHPA %s in %s namespace is not found", request.Name, request.Namespace)
go r.CronManager.GC()
return reconcile.Result{}, nil
}
Expand Down Expand Up @@ -118,10 +119,12 @@ func (r *ReconcileCronHorizontalPodAutoscaler) Reconcile(request reconcile.Reque
}
continue
}
// if nothing changed
skip = true
}
}

// need remove this condition because this is not job spec
if !skip {
if cJob.JobId != "" {
err := r.CronManager.delete(cJob.JobId)
Expand All @@ -131,7 +134,7 @@ func (r *ReconcileCronHorizontalPodAutoscaler) Reconcile(request reconcile.Reque
}
}

// need remove this condition because this is not job spec
// if job nothing changed then append to left conditions
if skip {
leftConditions = append(leftConditions, cJob)
}
Expand Down Expand Up @@ -190,11 +193,11 @@ func (r *ReconcileCronHorizontalPodAutoscaler) Reconcile(request reconcile.Reque
noNeedUpdateStatus = false
instance.Status.Conditions = updateConditions(instance.Status.Conditions, jobCondition)
}
// conditions doesn't changed and no need to update.
// conditions are not changed and no need to update.
if !noNeedUpdateStatus || len(leftConditions) != len(conditions) {
err := r.Update(context.Background(), instance)
if err != nil {
log.Errorf("Failed to update cron hpa %s status,because of %v", instance.Name, err)
log.Errorf("Failed to update cron hpa %s in namespace %s status, because of %v", instance.Name, instance.Namespace, err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func (ch *CronJobHPA) ScalePlainRef() (msg string, err error) {
scale, err = ch.scaler.Scales(ch.TargetRef.RefNamespace).Get(context.Background(), targetGR, ch.TargetRef.RefName, v1.GetOptions{})
if err == nil {
found = true
log.Infof("%s %s in namespace %s has been scaled successfully. job: %s replicas: %d", ch.TargetRef.RefKind, ch.TargetRef.RefName, ch.TargetRef.RefNamespace, ch.Name(), ch.DesiredSize)
log.Infof("%s %s in namespace %s has been scaled successfully. job: %s replicas: %d id: %s", ch.TargetRef.RefKind, ch.TargetRef.RefName, ch.TargetRef.RefNamespace, ch.Name(), ch.DesiredSize, ch.ID())
break
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/cronmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func (cm *CronManager) GC() {
}
return true
}

log.Warningf("Failed to find job %s of cronHPA %s in %s in cron engine and resubmit the job.", job.Name(), hpa.Name, hpa.Namespace)
cm.cronExecutor.AddJob(job)
}
Expand Down