feat(agent): overlay GC and mount namespace cleanup#28
Merged
miguelgila merged 3 commits intomainfrom Mar 3, 2026
Merged
Conversation
Add periodic overlay GC to reaper-agent that lists K8s namespaces via the API, compares against on-disk overlay directories, and removes artifacts for namespaces that no longer exist. This prevents orphaned overlay dirs from accumulating on nodes after namespace deletion. Key behaviors: - Safety check: skips cleanup if running containers reference the namespace - Handles named overlay groups (<ns>--<name> pattern) - Unmounts namespace bind-mounts before removal (umount2 MNT_DETACH) - Configurable via --overlay-gc-interval (default 300s) and --overlay-gc-enabled - Exposes 3 new Prometheus metrics (runs, cleaned, namespaces gauge) Also fixes a bug in container GC where it would remove overlay infrastructure directories (overlay/, merged/, ns/) as "orphaned state dirs" because they lack state.json. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…nd-mounts Add periodic detection and cleanup of stale `/run/reaper/ns/*` bind-mount files to the reaper-agent. Stale ns files occur when helper processes crash, nodes partially reboot, or overlay dirs are manually cleaned. Detection uses `/proc/self/mountinfo` with a `/proc/1/mountinfo` fallback (via hostPID) to reliably identify mount points even in nested container environments. Safety checks prevent removing ns files referenced by running containers, and non-blocking flock prevents races with the runtime. Cleanup runs before each overlay GC pass, piggybacks on existing `--overlay-gc-enabled` and `--overlay-gc-interval` flags. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #28 +/- ##
==========================================
- Coverage 87.18% 86.83% -0.36%
==========================================
Files 6 6
Lines 320 319 -1
==========================================
- Hits 279 277 -2
- Misses 41 42 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Summary
/run/reaper/ns/*bind-mount files that occur when helper processes crash, nodes partially reboot, or overlay dirs are manually cleanedmountPropagation: HostToContainerto the agent's run-reaper volume mount for mount-point visibilityMount namespace cleanup details
/proc/self/mountinfowith/proc/1/mountinfofallback (hostPID)enter_overlay()--overlay-gc-enabledand--overlay-gc-intervalflagsreaper_agent_ns_cleanup_runs_total,reaper_agent_ns_cleaned_totalTest plan
cargo clippy --target x86_64-unknown-linux-gnu --all-targets— cleancargo test— all unit tests pass./scripts/run-integration-tests.sh --agent-only— 13/13 agent tests pass🤖 Generated with Claude Code