Skip to content

cmd/buildkitd: apply an operator gc policy when the config disables gc without a gcpolicy - #41

Closed
piob-io wants to merge 1 commit into
masterfrom
operator-gc-policy
Closed

piob-io wants to merge 1 commit into
masterfrom
operator-gc-policy

Conversation

@piob-io

@piob-io piob-io commented Oct 6, 2026 •

Copy link
Copy Markdown

Summary

buildkitd now also reads /etc/buildkit/operator.toml (appdefaults.ConfigDir), independent of whatever --config the client passes. It is a normal buildkitd config file, but only the gc / gcpolicy keys of each worker are taken from it, and they are applied only to a worker whose own config is gc = false and has no gcpolicy. Everything else is left alone:

client config                 operator.toml         result
gc = false, no gcpolicy   +   gc=true + gcpolicy  → gc=true, operator gcpolicy
gc = false, own gcpolicy  +   anything            → unchanged
gc = true  (any)          +   anything            → unchanged
gc unset                  +   anything            → unchanged (builtin default policy)
anything                  +   file missing/empty  → unchanged

Purpose: let the environment that ships buildkitd impose a garbage-collection floor on clients that start the daemon with gc = false and rely on an external prune (or none), without changing those clients.

Rules in config.ApplyOperatorGC(dst *GCConfig, op GCConfig, pruneInUse bool) (applied bool, err error):

  • operator gc = false, or gc = true without a gcpolicy → error, nothing applied
  • a size-based operator rule (reservedSpace / maxUsedSpace / minFreeSpace / keepBytes) is refused while pruneInUse is in effect (cache: make in-use pruning opt-out and guard DiskUsage against pruned parents #34 made in-use pruning the default; with a size bound it can remove records that still have refs). Time-only rules (keepDuration) never prune in-use records (keepBytes == 0 short-circuits the candidate check in pruneOnce), so they are always accepted.
  • any problem with the operator file is logged (bklog warn) and the daemon starts with the client's config unchanged — a bad floor can never block startup.

applyOperatorConfig runs after setDefaultConfig/applyMainFlags and the log setup, for both the OCI and containerd worker sections (containerd has PruneInUse hard-coded to true).

Verified with the built binary: v1-shaped config (gc=false, no policy) + operator file → buildctl debug workers -v shows GC Policy rule#0: All: true, Keep duration: 192h; a config with its own gcpolicy keepDuration=24h keeps 24h and logs nothing about the operator; no operator file → no GC policy, as before.

Link to Devin session: https://app.devin.ai/sessions/e59c0c1861c64b12abae47b044b215d2
Open in Devin Desktop: https://app.devin.ai/desktop/session/e59c0c1861c64b12abae47b044b215d2?variant=devin
Requested by: @piob-io


View with [code]smith QA with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


View with [code]smith QA with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled. (Staging)

@devin-ai-integration

Copy link
Copy Markdown

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

…c without a gcpolicy

buildkitd now also reads /etc/buildkit/operator.toml, independent of
--config. Only the gc and gcpolicy keys of each worker are taken from it,
and only for a worker whose own config sets gc = false and declares no
gcpolicy; a config that enables gc or carries its own policy is never
changed. This lets the environment that ships buildkitd impose a garbage
collection floor on clients that start the daemon with gc disabled.

A size-based operator rule is refused unless the worker config sets
pruneInUse = false, since a size-bounded prune with pruneInUse may remove
records that still have live refs; time-based rules are always accepted.
Problems with the operator file are logged and the daemon starts with the
client config unchanged.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant