From e611de4e7cf1ba49c2f8a365546373165ce9e0de Mon Sep 17 00:00:00 2001 From: Stefan Prodan Date: Mon, 24 Jan 2022 16:00:59 +0200 Subject: [PATCH] Introduce a dedicated manager for status updates to avoid conflicts Signed-off-by: Stefan Prodan --- controllers/kustomization_controller.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/controllers/kustomization_controller.go b/controllers/kustomization_controller.go index 4304af00..d31ff284 100644 --- a/controllers/kustomization_controller.go +++ b/controllers/kustomization_controller.go @@ -84,6 +84,7 @@ type KustomizationReconciler struct { MetricsRecorder *metrics.Recorder StatusPoller *polling.StatusPoller ControllerName string + statusManager string } type KustomizationReconcilerOptions struct { @@ -111,6 +112,7 @@ func (r *KustomizationReconciler) SetupWithManager(mgr ctrl.Manager, opts Kustom } r.requeueDependency = opts.DependencyRequeueInterval + r.statusManager = fmt.Sprintf("gotk-%s", r.ControllerName) // Configure the retryable http client used for fetching artifacts. // By default it retries 10 times within a 3.5 minutes window. @@ -155,7 +157,7 @@ func (r *KustomizationReconciler) Reconcile(ctx context.Context, req ctrl.Reques if !controllerutil.ContainsFinalizer(&kustomization, kustomizev1.KustomizationFinalizer) { patch := client.MergeFrom(kustomization.DeepCopy()) controllerutil.AddFinalizer(&kustomization, kustomizev1.KustomizationFinalizer) - if err := r.Patch(ctx, &kustomization, patch); err != nil { + if err := r.Patch(ctx, &kustomization, patch, client.FieldOwner(r.statusManager)); err != nil { log.Error(err, "unable to register finalizer") return ctrl.Result{}, err } @@ -938,7 +940,7 @@ func (r *KustomizationReconciler) finalize(ctx context.Context, kustomization ku // Remove our finalizer from the list and update it controllerutil.RemoveFinalizer(&kustomization, kustomizev1.KustomizationFinalizer) - if err := r.Update(ctx, &kustomization, client.FieldOwner(r.ControllerName)); err != nil { + if err := r.Update(ctx, &kustomization, client.FieldOwner(r.statusManager)); err != nil { return ctrl.Result{}, err } @@ -1035,6 +1037,5 @@ func (r *KustomizationReconciler) patchStatus(ctx context.Context, req ctrl.Requ patch := client.MergeFrom(kustomization.DeepCopy()) kustomization.Status = newStatus - - return r.Status().Patch(ctx, &kustomization, patch, client.FieldOwner(r.ControllerName)) + return r.Status().Patch(ctx, &kustomization, patch, client.FieldOwner(r.statusManager)) }