From f0c4e21d74461ff780cf780fce8c323253b054ab Mon Sep 17 00:00:00 2001 From: John Collier Date: Tue, 13 Feb 2024 13:44:57 -0500 Subject: [PATCH 1/2] [KFLUXBUGS-1105]: Retrieve Component before updating status Signed-off-by: John Collier --- controllers/webhooks/component_webhook.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/controllers/webhooks/component_webhook.go b/controllers/webhooks/component_webhook.go index 356acafeb..dff09e361 100644 --- a/controllers/webhooks/component_webhook.go +++ b/controllers/webhooks/component_webhook.go @@ -86,13 +86,19 @@ func (r *ComponentWebhook) UpdateNudgedComponentStatus(ctx context.Context, obj // Add the component to the status if it's not already present if !util.StrInList(compName, nudgedComp.Status.BuildNudgedBy) { - nudgedComp.Status.BuildNudgedBy = append(nudgedComp.Status.BuildNudgedBy, compName) // Update the Component's status - retry on conflict - err = retry.RetryOnConflict(retry.DefaultRetry, func() error { - err = r.client.Status().Update(ctx, nudgedComp) + retry.RetryOnConflict(retry.DefaultRetry, func() error { + currentNudgedComp := &appstudiov1alpha1.Component{} + err := r.client.Get(ctx, types.NamespacedName{Namespace: comp.Namespace, Name: nudgedCompName}, currentNudgedComp) + if err != nil { + return err + } + currentNudgedComp.Status.BuildNudgedBy = append(currentNudgedComp.Status.BuildNudgedBy, compName) + err = r.client.Status().Update(ctx, currentNudgedComp) return err }) + } } From 7f15d5cb96cf4ced29de32cb44262990f436a1e9 Mon Sep 17 00:00:00 2001 From: John Collier Date: Tue, 13 Feb 2024 14:26:22 -0500 Subject: [PATCH 2/2] Add log Signed-off-by: John Collier --- controllers/webhooks/component_webhook.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/controllers/webhooks/component_webhook.go b/controllers/webhooks/component_webhook.go index dff09e361..81fa08bdd 100644 --- a/controllers/webhooks/component_webhook.go +++ b/controllers/webhooks/component_webhook.go @@ -88,7 +88,7 @@ func (r *ComponentWebhook) UpdateNudgedComponentStatus(ctx context.Context, obj if !util.StrInList(compName, nudgedComp.Status.BuildNudgedBy) { // Update the Component's status - retry on conflict - retry.RetryOnConflict(retry.DefaultRetry, func() error { + err := retry.RetryOnConflict(retry.DefaultRetry, func() error { currentNudgedComp := &appstudiov1alpha1.Component{} err := r.client.Get(ctx, types.NamespacedName{Namespace: comp.Namespace, Name: nudgedCompName}, currentNudgedComp) if err != nil { @@ -98,6 +98,9 @@ func (r *ComponentWebhook) UpdateNudgedComponentStatus(ctx context.Context, obj err = r.client.Status().Update(ctx, currentNudgedComp) return err }) + if err != nil { + componentlog.Error(err, "error setting build-nudged-by in status") + } }