Skip to content

Commit

Permalink
Introduce a dedicated manager for status updates to avoid conflicts
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Prodan <[email protected]>
  • Loading branch information
stefanprodan committed Jan 24, 2022
1 parent ad94bd6 commit e611de4
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions controllers/kustomization_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ type KustomizationReconciler struct {
MetricsRecorder *metrics.Recorder
StatusPoller *polling.StatusPoller
ControllerName string
statusManager string
}

type KustomizationReconcilerOptions struct {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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))
}

0 comments on commit e611de4

Please sign in to comment.