diff --git a/pkg/controller/cronhorizontalpodautoscaler_controller.go b/pkg/controller/cronhorizontalpodautoscaler_controller.go index e352e999..15395cc1 100644 --- a/pkg/controller/cronhorizontalpodautoscaler_controller.go +++ b/pkg/controller/cronhorizontalpodautoscaler_controller.go @@ -108,23 +108,11 @@ func (r *ReconcileCronHorizontalPodAutoscaler) Reconcile(context context.Context for _, cJob := range conditions { skip := false for _, job := range instance.Spec.Jobs { - if cJob.Name == job.Name { - // schedule has changed or RunOnce changed - if cJob.Schedule != job.Schedule || cJob.RunOnce != job.RunOnce || cJob.TargetSize != job.TargetSize { - // jobId exists and remove the job from cronManager - if cJob.JobId != "" { - err := r.CronManager.delete(cJob.JobId) - if err != nil { - log.Errorf("Failed to delete expired job %s in cronHPA %s namespace %s,because of %v", cJob.Name, instance.Name, instance.Namespace, err) - } - } - continue - } - // if nothing changed + if cJob.Name == job.Name && cJob.Schedule == job.Schedule && cJob.RunOnce == job.RunOnce && cJob.TargetSize == job.TargetSize { skip = true + break } } - // need remove this condition because this is not job spec if !skip { if cJob.JobId != "" { @@ -133,10 +121,7 @@ func (r *ReconcileCronHorizontalPodAutoscaler) Reconcile(context context.Context log.Errorf("Failed to delete expired job %s in cronHPA %s namespace %s, because of %v", cJob.Name, instance.Name, instance.Namespace, err) } } - } - - // if job nothing changed then append to left conditions - if skip { + } else { leftConditions = append(leftConditions, cJob) } }