diff --git a/pkg/controller/jobframework/reconciler.go b/pkg/controller/jobframework/reconciler.go index 152bcdef2b..fa274f2c2f 100644 --- a/pkg/controller/jobframework/reconciler.go +++ b/pkg/controller/jobframework/reconciler.go @@ -325,7 +325,7 @@ func (r *JobReconciler) ReconcileGenericJob(ctx context.Context, req ctrl.Reques log.Error(err, "couldn't get the parent job workload") return ctrl.Result{}, err } else if parentWorkload == nil || !workload.IsAdmitted(parentWorkload) { - if err := clientutil.Patch(ctx, r.client, object, true, func() (bool, error) { + if err := clientutil.Patch(ctx, r.client, object, func() (bool, error) { job.Suspend() return true, nil }); err != nil { @@ -855,7 +855,7 @@ func (r *JobReconciler) startJob(ctx context.Context, job GenericJob, object cli return err } } else { - if err := clientutil.Patch(ctx, r.client, object, true, func() (bool, error) { + if err := clientutil.Patch(ctx, r.client, object, func() (bool, error) { return true, job.RunWithPodSetsInfo(info) }); err != nil { return err @@ -899,7 +899,7 @@ func (r *JobReconciler) stopJob(ctx context.Context, job GenericJob, wl *kueue.W return nil } - if err := clientutil.Patch(ctx, r.client, object, true, func() (bool, error) { + if err := clientutil.Patch(ctx, r.client, object, func() (bool, error) { job.Suspend() if info != nil { job.RestorePodSetsInfo(info) diff --git a/pkg/controller/jobs/job/job_controller.go b/pkg/controller/jobs/job/job_controller.go index 4bf84f91f4..a337479744 100644 --- a/pkg/controller/jobs/job/job_controller.go +++ b/pkg/controller/jobs/job/job_controller.go @@ -170,7 +170,7 @@ func (j *Job) Stop(ctx context.Context, c client.Client, podSetsInfo []podset.Po stoppedNow := false if !j.IsSuspended() { - if err := clientutil.Patch(ctx, c, object, true, func() (bool, error) { + if err := clientutil.Patch(ctx, c, object, func() (bool, error) { j.Suspend() if j.ObjectMeta.Annotations == nil { j.ObjectMeta.Annotations = map[string]string{} @@ -194,7 +194,7 @@ func (j *Job) Stop(ctx context.Context, c client.Client, podSetsInfo []podset.Po } } - if err := clientutil.Patch(ctx, c, object, true, func() (bool, error) { + if err := clientutil.Patch(ctx, c, object, func() (bool, error) { j.RestorePodSetsInfo(podSetsInfo) delete(j.ObjectMeta.Annotations, StoppingAnnotation) return true, nil diff --git a/pkg/controller/jobs/pod/pod_controller.go b/pkg/controller/jobs/pod/pod_controller.go index 67e6231470..d500ac82bf 100644 --- a/pkg/controller/jobs/pod/pod_controller.go +++ b/pkg/controller/jobs/pod/pod_controller.go @@ -239,7 +239,7 @@ func (p *Pod) Run(ctx context.Context, c client.Client, podSetsInfo []podset.Pod return nil } - if err := clientutil.Patch(ctx, c, &p.pod, true, func() (bool, error) { + if err := clientutil.Patch(ctx, c, &p.pod, func() (bool, error) { ungate(&p.pod) return true, podset.Merge(&p.pod.ObjectMeta, &p.pod.Spec, podSetsInfo[0]) }); err != nil { @@ -260,7 +260,7 @@ func (p *Pod) Run(ctx context.Context, c client.Client, podSetsInfo []podset.Pod return nil } - if err := clientutil.Patch(ctx, c, pod, true, func() (bool, error) { + if err := clientutil.Patch(ctx, c, pod, func() (bool, error) { ungate(pod) roleHash, err := getRoleHash(*pod) @@ -511,7 +511,7 @@ func (p *Pod) Finalize(ctx context.Context, c client.Client) error { return parallelize.Until(ctx, len(podsInGroup.Items), func(i int) error { pod := &podsInGroup.Items[i] - return clientutil.Patch(ctx, c, pod, false, func() (bool, error) { + return clientutil.Patch(ctx, c, pod, func() (bool, error) { return controllerutil.RemoveFinalizer(pod, PodFinalizer), nil }) }) @@ -851,7 +851,7 @@ func (p *Pod) removeExcessPods(ctx context.Context, c client.Client, r record.Ev // Finalize and delete the active pods created last err := parallelize.Until(ctx, len(extraPods), func(i int) error { pod := extraPods[i] - if err := clientutil.Patch(ctx, c, &pod, false, func() (bool, error) { + if err := clientutil.Patch(ctx, c, &pod, func() (bool, error) { removed := controllerutil.RemoveFinalizer(&pod, PodFinalizer) log.V(3).Info("Finalizing excess pod in group", "excessPod", klog.KObj(&pod)) return removed, nil @@ -891,7 +891,7 @@ func (p *Pod) finalizePods(ctx context.Context, c client.Client, extraPods []cor err := parallelize.Until(ctx, len(extraPods), func(i int) error { pod := extraPods[i] var removed bool - if err := clientutil.Patch(ctx, c, &pod, false, func() (bool, error) { + if err := clientutil.Patch(ctx, c, &pod, func() (bool, error) { removed = controllerutil.RemoveFinalizer(&pod, PodFinalizer) log.V(3).Info("Finalizing pod in group", "Pod", klog.KObj(&pod)) return removed, nil diff --git a/pkg/controller/jobs/statefulset/statefulset_reconciler.go b/pkg/controller/jobs/statefulset/statefulset_reconciler.go index e6c39fce72..4e8f414dfa 100644 --- a/pkg/controller/jobs/statefulset/statefulset_reconciler.go +++ b/pkg/controller/jobs/statefulset/statefulset_reconciler.go @@ -81,7 +81,7 @@ func (r *Reconciler) finalizePods(ctx context.Context, pods []corev1.Pod) error if p.Status.Phase != corev1.PodSucceeded && p.Status.Phase != corev1.PodFailed { return nil } - err := clientutil.Patch(ctx, r.client, p, true, func() (bool, error) { + err := clientutil.Patch(ctx, r.client, p, func() (bool, error) { removed := controllerutil.RemoveFinalizer(p, pod.PodFinalizer) if removed { log.V(3).Info("Finalizing pod in group", "pod", klog.KObj(p), "group", p.Labels[pod.GroupNameLabel]) diff --git a/pkg/controller/tas/topology_ungater.go b/pkg/controller/tas/topology_ungater.go index 0847b62f7f..1cd77b869c 100644 --- a/pkg/controller/tas/topology_ungater.go +++ b/pkg/controller/tas/topology_ungater.go @@ -196,7 +196,7 @@ func (r *topologyUngater) Reconcile(ctx context.Context, req reconcile.Request) err = parallelize.Until(ctx, len(allToUngate), func(i int) error { podWithUngateInfo := &allToUngate[i] var ungated bool - e := utilclient.Patch(ctx, r.client, podWithUngateInfo.pod, true, func() (bool, error) { + e := utilclient.Patch(ctx, r.client, podWithUngateInfo.pod, func() (bool, error) { log.V(3).Info("ungating pod", "pod", klog.KObj(podWithUngateInfo.pod), "nodeLabels", podWithUngateInfo.nodeLabels) ungated = utilpod.Ungate(podWithUngateInfo.pod, kueuealpha.TopologySchedulingGate) if podWithUngateInfo.pod.Spec.NodeSelector == nil { diff --git a/pkg/util/client/client.go b/pkg/util/client/client.go index 2eb198f7dd..1e3f0c559b 100644 --- a/pkg/util/client/client.go +++ b/pkg/util/client/client.go @@ -32,14 +32,14 @@ func CreatePatch(before, after client.Object) (client.Patch, error) { } // Patch applies the merge patch of client.Object. -// If strict is true, the resourceVersion will be part of the patch, make this call fail if +// The resourceVersion will be part of the patch, make this call fail if // client.Object was changed. -func Patch(ctx context.Context, c client.Client, obj client.Object, strict bool, update func() (bool, error)) error { +func Patch(ctx context.Context, c client.Client, obj client.Object, update func() (bool, error)) error { objOriginal := obj.DeepCopyObject().(client.Object) - if strict { - // Clearing ResourceVersion from the original object to make sure it is included in the generated patch. - objOriginal.SetResourceVersion("") - } + + // Clearing ResourceVersion from the original object to make sure it is included in the generated patch. + objOriginal.SetResourceVersion("") + updated, err := update() if err != nil || !updated { return err