Repository navigation
refactor(git): key worker checkouts by GitBranch UID and reclaim orphans - #453
Merged
Merged
Conversation
Local clones move from /tmp/gitops-reverser-workers/{provider UID}/{branch-component}
to /tmp/gitops-reverser-workers/{GitBranch UID}. A GitBranch pins its branch, the
claim gives a repository branch to one GitBranch, and EnsureWorker keeps one live
worker per GitBranch, so its UID is a complete name for the checkout. The branch
name no longer appears in the path, so branchPathComponent goes.
EnsureWorker reads the UID from the claim holder it already checks. A provider
recreated against another URL keeps the GitBranch, so its replacement worker reuses
the directory after the old worker has removed the clone in it.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 10 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
A retiring worker removes its own checkout, but a GitBranch deleted while no
worker ran for it, across a restart that kept the disk, left its directory
behind. The worker sweep now also deletes every directory under the state root
that no live worker uses and no existing GitBranch names. It runs under
lifecycleMu, so no worker starts while it reads, and a GitBranch List that fails
deletes nothing. Checkouts from the previous {provider UID}/{branch} layout go
the same way.
Because the sweep deletes whatever its own cluster does not name, a test binary
that runs a WorkerManager must not share the default root: SetWorkerStateRoot
gives internal/git and internal/controller their own from TestMain.
The chart README shows how to keep checkouts across pod replacement by mounting
a PersistentVolumeClaim through the existing volumes/volumeMounts values.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.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.
Stacked on #451.
Local clones live under
/tmp/gitops-reverser-workers/{GitBranch UID}instead of/tmp/gitops-reverser-workers/{provider UID}/{branch-component}.Why the GitBranch UID is enough
GitBranchpins its branch:spec.branchis immutable.GitBranchat a time, andEnsureWorkerkeeps at most one live worker perGitBranch(it removes the old one before starting a replacement, underlifecycleMu). No two live workers share a directory.GitBranchdeleted and recreated under its name gets a new directory.branchPathComponent(which keptrelease/v1from nesting insiderelease) goes away.EnsureWorkerreads the UID from the claim holder that it already checks, soWorkerRequestand the GitTarget reconciler are unchanged.What changes in behavior
The repository is the one thing the
GitBranchUID does not pin. AGitProviderrecreated against another URL keeps theGitBranch, so the replacement worker now uses the same directory. Before, the new provider UID gave it a new directory. This is safe:EnsureWorkerstops the old worker and removes its clone before the replacement starts.PrepareBranchFrom, which repointsoriginand fetches and resets.RepoIdentity.ProviderUIDstays: it still detects that a provider was recreated, which triggers the replacement.Checkouts no GitBranch names are reclaimed
A retiring worker removes its own checkout. A GitBranch deleted while no worker ran for it, across a restart that kept the disk (a container restart inside its pod), left its directory behind.
ReconcileWorkers(every minute, and after every GitTarget delete) now also deletes every directory under the root that no live worker uses and no existing GitBranch names:lifecycleMu, so no worker starts while it reads the directories.Listthat fails deletes nothing.{provider UID}/{branch}layout are removed too.Because the sweep deletes whatever its own cluster does not name, a test binary that runs a WorkerManager must not share the default root.
SetWorkerStateRootgivesinternal/gitandinternal/controllertheir own root fromTestMain. Before this,TestReconcileWorkers_KeepsAWorkerASiblingStillNeedsswept the real/tmp/gitops-reverser-workers.Persisting checkouts across pod replacement
/tmpis anemptyDir: checkouts survive a container restart, but a new pod clones every branch again. No new chart value is needed for this. The chart README shows how to mount a PersistentVolumeClaim at/tmp/gitops-reverser-workersthrough the existingvolumes/volumeMountsvalues.ReadWriteOnceis enough, because the chart runs one replica and the default strategy stops the old pod first.Tests
TestRepoRootPath_IsOneDirectoryPerGitBranchreplaces the provider-incarnation and branch-component tests.TestWorkerLifecycle_AReplacementStartsFromAnEmptyCheckoutreplaces the test that the predecessor's checkout and the replacement's are different directories. They are now the same directory, and the old clone is gone before the new worker starts.TestReconcileWorkers_ReclaimsCheckoutsNoGitBranchNamesand..._ReclaimsNothingWhenTheGitBranchesCannotBeReadcover the sweep.removeLocalStateacts only for a worker with aGitBranchUID, which every manager-started worker has.newTestBranchWorkersets aGitBranchUID.task lintandtask testpass. Localtask test-e2epasses on both commits (109 of 168 specs, the default filter). One run on the second commit died in BeforeSuite on the known audit warm-up signature after a k3d node restart; it passed aftertask clean-cluster.🤖 Generated with Claude Code