Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion internal/controller/dataprotectionapplication_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ func (r *DataProtectionApplicationReconciler) Reconcile(ctx context.Context, req
logger.Error(err, "unable to fetch DataProtectionApplication CR")
return result, nil
}
// origDpa snapshots status before reconciliation mutates it, so the final
// status update is a merge patch (no resourceVersion check) instead of a
// full update, avoiding optimistic-lock conflicts when the informer cache
// still lags behind a status write this controller (or another actor)
// already made to the object.
origDpa := r.dpa.DeepCopy()

// set client to pkg/client for use in non-reconcile functions
oadpclient.SetClient(r.Client)
Expand Down Expand Up @@ -149,7 +155,7 @@ func (r *DataProtectionApplicationReconciler) Reconcile(ctx context.Context, req
}
}

statusErr := r.Client.Status().Update(ctx, r.dpa)
statusErr := r.Client.Status().Patch(ctx, r.dpa, client.MergeFrom(origDpa))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Preserve the status patch error.

When err is already non-nil, statusErr is discarded. Combine both errors so the original reconciliation failure remains available and the status persistence failure is not silently ignored.

As per path instructions, **/*.go: “Never ignore error returns.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/controller/dataprotectionapplication_controller.go` at line 158,
Update the status patch handling in the reconciliation method containing
statusErr so any existing err is combined with statusErr instead of being
overwritten or discarded. Preserve both the original reconciliation failure and
the status persistence failure, and ensure the Status().Patch error is never
ignored.

Source: Path instructions

if err == nil { // Don't mask previous error
err = statusErr
}
Expand Down