Skip to content

fix: sweep stale kustomization-* tmp dirs at startup - #1726

Open
AruneshDwivedi wants to merge 1 commit into
fluxcd:mainfrom
AruneshDwivedi:fix/stale-tmp-dirs
Open

fix: sweep stale kustomization-* tmp dirs at startup#1726
AruneshDwivedi wants to merge 1 commit into
fluxcd:mainfrom
AruneshDwivedi:fix/stale-tmp-dirs

Conversation

@AruneshDwivedi

Copy link
Copy Markdown

fix: sweep stale kustomization-* tmp dirs at startup

The kustomize-controller creates a temp dir per reconcile and registers a deferred os.RemoveAll. Deferred functions do not run when the process exits ungracefully (SIGKILL, OOMKill, or leader lease lost causing os.Exit(1)), and nothing cleans stale dirs on startup. This leaves orphaned kustomization-* directories in /tmp that accumulate across restarts.

In production, this was observed consuming 1.5GB of orphaned artifacts sitting in a pod's /tmp five days after a crash. When /tmp is mounted as emptyDir: {medium: Memory}, the leak becomes an OOM loop: the pages stay charged to the pod cgroup, so each OOMKill leaves less headroom for the next start.

This PR adds a sweepStaleTmpDirs() function that scans /tmp for kustomization-* directories and removes them before the manager starts reconciling. It runs on the main goroutine before mgr.Start(), so it does not block reconciliation.

Fixes #1723

[BUGFIX] Clean up orphaned kustomization-* temp directories left by ungraceful exits at controller startup.

Deferred os.RemoveAll calls in reconcile do not run on SIGKILL or
os.Exit(1), leaving orphaned kustomization-* directories in /tmp.
These accumulate across restarts and can consume significant ephemeral
storage (or memory when /tmp is tmpfs).

Add sweepStaleTmpDirs() called before mgr.Start() to clean leftover
dirs from ungraceful exits.

Signed-off-by: Arunesh Dwivedi <arunesh@example.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Kustomize-controller leaks /tmp/kustomization-* dirs after ungraceful exit

1 participant