Conversation
monotek
marked this pull request as ready for review
September 1, 2026 16:25
monotek
marked this pull request as draft
September 9, 2026 13:03
image-automation-controller can lose a push race when many independent ImageUpdateAutomation objects push to the same branch. Recovering cheaply requires catching a working directory up to the new remote tip without a full re-clone, regardless of why the previous push failed. Add FetchAndReset(ctx, branch), which fetches branch via a scoped refspec and hard-resets the current worktree onto the fetched tip, swallowing NoErrAlreadyUpToDate. No changes to the Reader/Writer/Client interfaces; it is a new method on the concrete gogit.Client type. Assisted-by: Claude Sonnet 5/claude-sonnet-5 Signed-off-by: André Bauer <monotek23@gmail.com>
monotek
force-pushed
the
retry-push-conflict-fetch-reset
branch
from
September 9, 2026 13:10
c1457b1 to
3299da0
Compare
monotek
marked this pull request as ready for review
September 9, 2026 14:05
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.
Why
In deployments with many independent
ImageUpdateAutomation(IUA) objects pushing to the same branch of one GitOps repo (e.g. one IUA per service/region, all on independent reconcile timers), push rejections become common once write concurrency is high enough. Todayimage-automation-controllerhas no in-process retry for a failed push — the next attempt only happens on the next scheduled reconcile, or via controller-runtime's per-item exponential-backoff requeue (750ms doubling, capped at 15min). Under contention, a single IUA can lose several races in a row, each costing a full backoff cycle, turning a sub-minute git operation into a delay of tens of minutes.A companion PR (fluxcd/image-automation-controller#1090) adds a retry-with-backoff loop there, analogous to a
git pull --rebase && git pushretry loop reusing the same local clone across attempts (no re-clone). go-git has no rebase API, so the equivalent here is: fetch (cheap, incremental) → hard-reset onto the new remote tip → let the caller recompute and recommit → push again. That retry loop needs a way to catch a working directory up to the new remote tip without a full re-clone (todaygogit.Clientonly exposesClone, notFetch).What
(*gogit.Client).FetchAndReset(ctx, branch): fetchesbranchfrom the remote via a scoped refspec and hard-resets the current worktree onto the fetched tip. Never touches the remote. Swallows go-git'sNoErrAlreadyUpToDate. MirrorsSwitchBranch's plain(ctx, branchName)signature — no new config struct, since there's exactly one purpose and one caller today.repository.Reader/Writer/Clientinterfaces —image-automation-controllerholds a concrete*gogit.Client, so this is purely an additive new method on the concrete type.Testing
TestFetchAndReset: a stale client with its own unpushed local commit recovers onto the winner's pushed tip, working tree content included; a second call with nothing new is a no-op.make test-gitpasses,go vet/gofmtclean.