From 9b83ae722c98a546080be32884b39c66028953fa Mon Sep 17 00:00:00 2001 From: hendrikKahl Date: Fri, 26 Aug 2022 11:26:53 +0200 Subject: [PATCH] fix loss of Status subresource information Signed-off-by: hendrikKahl --- .../controller/reconciler/testrun_control.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/testmachinery/controller/reconciler/testrun_control.go b/pkg/testmachinery/controller/reconciler/testrun_control.go index 78d7c11800..e08abc4f39 100644 --- a/pkg/testmachinery/controller/reconciler/testrun_control.go +++ b/pkg/testmachinery/controller/reconciler/testrun_control.go @@ -160,6 +160,16 @@ func (r *TestmachineryReconciler) createWorkflow(ctx context.Context, rCtx *reco rCtx.tr.Status.Workflow = rCtx.wf.Name rCtx.tr.Status.Phase = tmv1beta1.RunPhaseRunning + // update status first because otherwise it would be lost during the patch call + rCtx.tr.Status.ObservedGeneration = rCtx.tr.Generation + if err := r.Status().Update(ctx, rCtx.tr); err != nil { + log.Error(err, "unable to update testrun status") + return reconcile.Result{}, err + } + + beforePatch := rCtx.tr.DeepCopy() + patch := client.MergeFrom(beforePatch) + // add finalizers for testrun trFinalizers := sets.NewString(rCtx.tr.Finalizers...) if !trFinalizers.Has(tmv1beta1.SchemeGroupVersion.Group) { @@ -170,8 +180,7 @@ func (r *TestmachineryReconciler) createWorkflow(ctx context.Context, rCtx *reco } rCtx.tr.Finalizers = trFinalizers.UnsortedList() - // update here to add finalizers - if err := r.Update(ctx, rCtx.tr); err != nil { + if err := r.Patch(ctx, rCtx.tr, patch); err != nil { return reconcile.Result{}, nil }