Prune deleted environments (opt-in)#20
Merged
Merged
Conversation
Closes the last open hard part: an environment deleted from the control repo was never removed from compilers — its symlink and version dirs lingered forever. This is the delete-submodule-symlink half of what PE's file sync does; codavox already had the other half (r10k purges the env from staging and the publisher stops advertising it), so the gap was purely on the agent. With --prune-environments the agent, after each poll, removes any environment the publisher no longer serves: the symlink goes immediately so new compiles fail loudly, and the environment's versions are reaped by --min-age so an in-flight run's code-content still resolves until the age passes. Deletion is destructive, so it is guarded the way PE guards its purge: - Off by default. Deleting an operator's code is opt-in, mirroring r10k's own purge_levels being a setting you enable. - Only after a successful poll. A failed fetch returns before pruning, so a publisher outage is never read as 'every environment was deleted.' - Never on an empty advertisement. A publisher serving zero environments is far more likely misconfigured than a real mass deletion, so it prunes nothing and logs a warning; deleting the last environment stays manual. Wired through agent.Config.Prune, the --prune-environments flag, and the agent.prune_environments config key. reap is refactored into reapVersions so a deleted environment reaps with no current and no keep-count, only the age guard. Tests (internal/agent/prune_test.go, run under -race in CI): the deletion path and all three guards, plus min-age protection of a recent version. Docs: agent.md, deploying.md (the r10k purge_levels requirement), configuration.md, and design.md (environment deletion moved from open to addressed). Signed-off-by: Michael Harp <mike@mikeharp.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.
Closes the last open "hard part": an environment deleted from the control repo was never removed from compilers — its symlink and version dirs lingered forever.
This is the
delete-submodule-symlinkhalf of what PE's file sync does. codavox already had the other half (r10k purges the env from staging,publishstops advertising it), so the gap was purely on the agent.Behavior
With
--prune-environments, after each poll the agent removes any environment the publisher no longer serves:--min-age→ an in-flight run'scode-contentstill resolves the version until the age passes.Guards (the point of the feature)
Deleting an operator's code is dangerous, so it's guarded the way PE guards its purge:
purge_levelsbeing a setting you enable.(r10k's own second guard — don't purge on a failed deploy — already applies on the deploy side.)
Tests — new, and they run in CI
internal/agent/prune_test.go, in-process (no binary build, notesting.Short()skip), so they run under-racein CI's unit-test job every run:Wiring & docs
agent.Config.Prune, the--prune-environmentsflag, and theagent.prune_environmentsconfig key.reaprefactored intoreapVersions(a deleted env reaps with no current and no keep-count, age guard only). Docs:agent.md,deploying.md(the r10kpurge_levelsrequirement, since codavox only observes r10k's output),configuration.md,config.example.yaml, anddesign.md(env deletion moved from open → addressed).Verified:
go test -race ./...,golangci-lint0 issues, gofmt/vet/markdownlint clean.🤖 Generated with Claude Code