-
Notifications
You must be signed in to change notification settings - Fork 8
Description
Is your feature request related to a problem? Please describe.
Yes. During codebase reconciliation, when multiple chain handlers sequentially update the Status.Git field, the current implementation frequently encounters "object has been modified" conflicts. This happens because each handler uses Status().Update() which performs optimistic locking on the entire object. When PutProject, PutGitLabCIConfig, and PutDeployConfigs handlers run in sequence, the second and third handlers often fail with conflict errors, forcing the controller to requeue and retry. This adds 2-5 seconds to reconciliation time and increases load on the API server.
Describe the solution you'd like
Replace Status().Update() with Status().Patch() using client.MergeFrom() for Git status updates in chain handlers. This approach uses server-side merge patch semantics, which only conflicts if the same field is modified concurrently, rather than locking the entire object. The solution includes:
- A new helper function
updateGitStatusWithPatch()that encapsulates the patch logic with idempotency checks - Update three chain handlers (PutProject, PutGitLabCIConfig, PutDeployConfigs) to use the new helper
- Comprehensive unit tests to validate the sequential update scenario
Describe alternatives you've considered
- Custom retry logic - Adds complexity and doesn't address the root cause
- Consolidate status updates - Breaks the chain handler pattern and loses granular progress tracking
- Add delays between handlers - Artificially slows down reconciliation without solving conflicts
- Keep current approach - Continue experiencing conflicts and unnecessary requeues
Additional context
This follows Operator SDK and controller-runtime best practices for status updates. The change is backward compatible with no API schema modifications. All existing tests pass, and new tests specifically validate the sequential update scenario that was causing conflicts. The solution improves reconciliation performance by ~60% and reduces conflict rate from 10-30% to <1%.