From af2a43f0abfb39e5435d95b8ca6bbf9dc840d6a5 Mon Sep 17 00:00:00 2001 From: "wen.rui" Date: Wed, 13 Sep 2023 19:58:38 +0800 Subject: [PATCH] Use ptr.Equal to compare the value --- pkg/apis/batch/validation/validation.go | 3 +-- pkg/controller/cronjob/cronjob_controllerv2.go | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/pkg/apis/batch/validation/validation.go b/pkg/apis/batch/validation/validation.go index e8612e022d4..730a26a5a04 100644 --- a/pkg/apis/batch/validation/validation.go +++ b/pkg/apis/batch/validation/validation.go @@ -36,7 +36,6 @@ import ( "k8s.io/kubernetes/pkg/apis/batch" api "k8s.io/kubernetes/pkg/apis/core" apivalidation "k8s.io/kubernetes/pkg/apis/core/validation" - "k8s.io/utils/pointer" "k8s.io/utils/ptr" ) @@ -735,7 +734,7 @@ func validateCronJobSpec(spec, oldSpec *batch.CronJobSpec, fldPath *field.Path, allErrs = append(allErrs, apivalidation.ValidateNonnegativeField(int64(*spec.StartingDeadlineSeconds), fldPath.Child("startingDeadlineSeconds"))...) } - if oldSpec == nil || !pointer.StringEqual(oldSpec.TimeZone, spec.TimeZone) { + if oldSpec == nil || !ptr.Equal(oldSpec.TimeZone, spec.TimeZone) { allErrs = append(allErrs, validateTimeZone(spec.TimeZone, fldPath.Child("timeZone"))...) } diff --git a/pkg/controller/cronjob/cronjob_controllerv2.go b/pkg/controller/cronjob/cronjob_controllerv2.go index 5058f38a489..ef623bf3e1b 100644 --- a/pkg/controller/cronjob/cronjob_controllerv2.go +++ b/pkg/controller/cronjob/cronjob_controllerv2.go @@ -48,7 +48,7 @@ import ( "k8s.io/kubernetes/pkg/controller" "k8s.io/kubernetes/pkg/controller/cronjob/metrics" jobutil "k8s.io/kubernetes/pkg/controller/job/util" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" ) var ( @@ -389,7 +389,7 @@ func (jm *ControllerV2) updateCronJob(logger klog.Logger, old interface{}, curr // if the change in schedule results in next requeue having to be sooner than it already was, // it will be handled here by the queue. If the next requeue is further than previous schedule, // the sync loop will essentially be a no-op for the already queued key with old schedule. - if oldCJ.Spec.Schedule != newCJ.Spec.Schedule || !pointer.StringEqual(oldCJ.Spec.TimeZone, newCJ.Spec.TimeZone) { + if oldCJ.Spec.Schedule != newCJ.Spec.Schedule || !ptr.Equal(oldCJ.Spec.TimeZone, newCJ.Spec.TimeZone) { // schedule changed, change the requeue time, pass nil recorder so that syncCronJob will output any warnings sched, err := cron.ParseStandard(formatSchedule(newCJ, nil)) if err != nil { @@ -494,7 +494,7 @@ func (jm *ControllerV2) syncCronJob( logger := klog.FromContext(ctx) if cronJob.Spec.TimeZone != nil { - timeZone := pointer.StringDeref(cronJob.Spec.TimeZone, "") + timeZone := ptr.Deref(cronJob.Spec.TimeZone, "") if _, err := time.LoadLocation(timeZone); err != nil { logger.V(4).Info("Not starting job because timeZone is invalid", "cronjob", klog.KObj(cronJob), "timeZone", timeZone, "err", err) jm.recorder.Eventf(cronJob, corev1.EventTypeWarning, "UnknownTimeZone", "invalid timeZone: %q: %s", timeZone, err)