From 8ec066bf37939b23a1ba684e281e6b2ad99a7527 Mon Sep 17 00:00:00 2001 From: Stefan Prodan Date: Wed, 4 Nov 2020 13:04:01 +0200 Subject: [PATCH] Use latest generation when updating final status Signed-off-by: Stefan Prodan --- controllers/kustomization_controller.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/controllers/kustomization_controller.go b/controllers/kustomization_controller.go index 29d5a445..bf0aef5a 100644 --- a/controllers/kustomization_controller.go +++ b/controllers/kustomization_controller.go @@ -252,7 +252,7 @@ func (r *KustomizationReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro } // update status - if err := r.Status().Update(ctx, &reconciledKustomization); err != nil { + if err := r.updateStatus(ctx, req, reconciledKustomization.Status); err != nil { log.Error(err, "unable to update status after reconciliation") return ctrl.Result{Requeue: true}, err } @@ -1033,6 +1033,16 @@ func (r *KustomizationReconciler) newKustomizationClient(kustomization kustomize return client, statusPoller, err } +func (r *KustomizationReconciler) updateStatus(ctx context.Context, req ctrl.Request, newStatus kustomizev1.KustomizationStatus) error { + var kustomization kustomizev1.Kustomization + if err := r.Get(ctx, req.NamespacedName, &kustomization); err != nil { + return err + } + + kustomization.Status = newStatus + return r.Status().Update(ctx, &kustomization) +} + func containsString(slice []string, s string) bool { for _, item := range slice { if item == s {