Skip to content

fix(controller): replace Update with Patch+RetryOnConflict for SA source-names annotation#272

Open
MaxRink wants to merge 2 commits intotelekom:mainfrom
MaxRink:fix/sa-annotation-lost-update
Open

fix(controller): replace Update with Patch+RetryOnConflict for SA source-names annotation#272
MaxRink wants to merge 2 commits intotelekom:mainfrom
MaxRink:fix/sa-annotation-lost-update

Conversation

@MaxRink
Copy link
Copy Markdown
Collaborator

@MaxRink MaxRink commented Apr 15, 2026

Summary

deleteServiceAccountIfUnused used client.Update (full-object replace) when removing the current BindDefinition name from the source-names annotation 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: Replace client.Update with retry.RetryOnConflict(retry.DefaultRetry, ...) + client.Patch(ctx, fresh, client.MergeFrom(orig)).
  • Each retry iteration re-fetches the SA with client.Get to get the latest resourceVersion and annotation state before computing and applying the delta.

Testing

go build ./internal/controller/...

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.

…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.
@MaxRink MaxRink requested a review from a team as a code owner April 15, 2026 11:52
Copilot AI review requested due to automatic review settings April 15, 2026 11:52
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.Update with a retry.RetryOnConflict(...) loop that re-Gets the ServiceAccount each attempt.
  • Switches to client.Patch(..., MergeFrom(...)) to apply a delta instead of full-object replacement.

Comment thread internal/controller/authorization/binddefinition_helpers.go Outdated
Comment thread internal/controller/authorization/binddefinition_helpers.go Outdated
@MaxRink MaxRink force-pushed the fix/sa-annotation-lost-update branch from 2a9a88e to f7cad77 Compare April 15, 2026 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants