Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

Commit 860b370

Browse files
committed
fix: Fix race condition in CRD operator status writer
1 parent 5166454 commit 860b370

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

pkg/kubernetes/controllers/operator.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,16 +363,30 @@ func (c *OpController) Start(ctx context.Context) error {
363363

364364
func (c *OpController) updateStatus(ctx context.Context, op *operator.Operator) {
365365
key := types.NamespacedName{Name: op.GetName()}
366+
367+
// Fetch the Operator CRD once to get the generation, then capture the status snapshot.
368+
// This ensures we're applying the same status on all retry attempts, preventing conflicts
369+
// caused by the status changing between retries (e.g., new errors being pushed).
370+
spec := opv1a1.Operator{}
371+
if err := c.k8sClient.Get(ctx, key, &spec); err != nil {
372+
c.log.Error(err, "failed to get operator for status update")
373+
return
374+
}
375+
376+
newStatus := op.GetStatus(spec.GetGeneration())
377+
366378
attempt := 0
367379
if err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
368380
attempt++
369381

382+
// Refetch the Operator to get the latest resourceVersion
370383
spec := opv1a1.Operator{}
371384
if err := c.k8sClient.Get(ctx, key, &spec); err != nil {
372385
return err
373386
}
374387

375-
spec.Status = op.GetStatus(spec.GetGeneration())
388+
// Use the status snapshot captured before the retry loop
389+
spec.Status = newStatus
376390

377391
c.log.V(2).Info("updating status", "attempt", attempt, "status", util.Stringify(spec.Status))
378392

0 commit comments

Comments
 (0)