fix(controller): replace Update with Patch+RetryOnConflict for SA source-names annotation#272
Open
MaxRink wants to merge 2 commits intotelekom:mainfrom
Open
fix(controller): replace Update with Patch+RetryOnConflict for SA source-names annotation#272MaxRink wants to merge 2 commits intotelekom:mainfrom
MaxRink wants to merge 2 commits intotelekom:mainfrom
Conversation
…otation Raw client.Update on ServiceAccount in the delete-path annotation removal had no conflict retry and no MergeFrom guard, causing lost-update races when two BindDefinition reconciles modify the same source-names annotation concurrently. Replace with retry.RetryOnConflict + client.Patch(MergeFrom) so each attempt re-fetches the SA and applies only the annotation delta, avoiding resourceVersion conflicts and annotation clobbering.
There was a problem hiding this comment.
Pull request overview
This PR aims to make updates to the ServiceAccount source-names annotation concurrency-safe when a ServiceAccount is retained (shared by multiple BindDefinitions), avoiding lost updates during concurrent reconciles.
Changes:
- Replaces
client.Updatewith aretry.RetryOnConflict(...)loop that re-Gets the ServiceAccount each attempt. - Switches to
client.Patch(..., MergeFrom(...))to apply a delta instead of full-object replacement.
2a9a88e to
f7cad77
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
deleteServiceAccountIfUnusedusedclient.Update(full-object replace) when removing the current BindDefinition name from thesource-namesannotation on a retained ServiceAccount. This had no conflict retry and no MergeFrom delta, so two concurrent BindDefinition reconciles targeting the same SA would race — one write wins, the other's annotation update is silently lost, potentially leaving a stale BD name in the annotation and later causing premature SA deletion.Changes
internal/controller/authorization/binddefinition_helpers.go: Replaceclient.Updatewithretry.RetryOnConflict(retry.DefaultRetry, ...)+client.Patch(ctx, fresh, client.MergeFrom(orig)).client.Getto get the latestresourceVersionand annotation state before computing and applying the delta.Testing
Build clean. Existing controller integration tests pass via
make test.Risk
Low — the change is a targeted replacement of the mutation strategy; logic and non-fatal error handling is preserved.