Retry object updates on conflict in receiver tests - #1352
Merged
Conversation
The receiver tests updated objects right after an Eventually block that observes the Ready condition. The reconciler commits its changes with multiple sequential patch requests (conditions first, then the rest of the status), so a trailing status patch can still bump the resourceVersion after the condition became visible. When that patch lands between the test's Get and Update, the Update fails with an optimistic concurrency conflict. Re-read the object and retry the update inside an Eventually block so transient conflicts with in-flight reconciles resolve instead of failing the test. Assisted-by: Claude Code/claude-fable-5 Signed-off-by: Jojin <jojin.kb@gmail.com>
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.
Fixes #473
Problem
Several receiver test steps mutate an object immediately after an
Eventuallyblock that keys off a condition. The reconciler's deferred patch (patch.SerialPatcher) commits its changes with multiple sequential API requests: the conditions patch first, then metadata/spec, then the remaining status fields (observedGeneration,lastHandledReconcileAt,webhookPath). TheEventuallycan therefore return as soon as the conditions patch lands, while the trailing status patch is still in flight. If that patch commits between the test'sGetandUpdate, theUpdatefails with an optimistic concurrency conflict ("the object has been modified"), producing the intermittent patch errors described in the issue.Changes
Converted the four remaining plain
Get+ mutate +Updatesequences ininternal/controller/receiver_controller_test.goto the read-modify-write retry idiom already used in other Flux controllers (e.g. kustomize-controller):Sites changed:
TestReceiverReconciler_Reconcile/ "fails with secret not found error"TestReceiverReconciler_Reconcile/ "handles reconcileAt"TestReceiverReconciler_Reconcile/ "finalizes suspended object"TestReceiverReconciler_EventHandler/ "doesn't update the URL on spec updates"Audit of the remaining mutation sites in the test suite:
client.RawPatch(types.MergePatchType, ...)calls in the receiver tests do not send aresourceVersionand cannot conflict — this is the workaround the issue refers to as the "other option".Eventually/Getbefore patching, andpatch.Helperissues its spec/metadata patch without an optimistic lock, so they cannot fail with conflict errors either.No controller code is changed.
Testing