Skip to content

fix: purge stale tmp dirs at startup - #2176

Open
andrewb3000 wants to merge 1 commit into
fluxcd:mainfrom
andrewb3000:fix-purge-stale-tmp
Open

andrewb3000 wants to merge 1 commit into
fluxcd:mainfrom
andrewb3000:fix-purge-stale-tmp

Conversation

@andrewb3000

Copy link
Copy Markdown

Fixes #1793

When source-controller exits without running its deferred cleanup, after losing its leader lease or being OOM killed, the temporary directories of the reconciles in flight stay behind. On an emptyDir /tmp they survive container restarts, so a controller that restarts often slowly fills the node's disk.

This is the source-controller counterpart of fluxcd/kustomize-controller#1729.

kustomize-controller's fix matches a fixed name prefix. That doesn't carry over here: temp paths are named after the object (<kind>-<namespace>-<name>-*, or Kind-... in the Bucket reconciler), and the Helm code adds chart-index-*, chart-build-* and *.tgz paths of its own. So instead:

  • At startup the controller creates $TMPDIR/source-controller and points TMPDIR at it, so every temp path, including the ones created by the Helm and Git libraries, lands in one directory.
  • Whatever a previous process left there is renamed aside first (source-controller.stale-<ts>) and removed in the background, with a two minute budget, so startup isn't delayed. A purge cut short by a later crash is picked up on the next start.

Only the controller's own subdirectory is touched, so this is safe when TMPDIR is shared, for example when running the binary locally.

When the controller exits without running its deferred cleanup, after
losing its leader lease or being OOM killed, the temporary directories of
the reconciles in flight stay behind. They survive container restarts on
an emptyDir volume, so a controller that restarts often fills the node.

The controller now keeps its temporary files in a directory of its own
under the system temp dir and points TMPDIR at it, so the files created by
the Helm and Git libraries land there too. At startup, whatever a previous
process left in that directory is moved aside and removed in the
background, the same way kustomize-controller purges its tmp dirs.

Signed-off-by: Andrii Bryndzak <abryndzak@datum.net>
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.

Problem with /tmp file

1 participant