Documentation
¶
Overview ¶
Package prune implements scheduled host-health cleanup: a "prune" job kind run by the jobs runner, fed by a per-host scheduler that fires on a configurable interval or disk high-water threshold. It never reaps in-use resources.
Index ¶
Constants ¶
const ( ScopeDangling = "dangling" // dangling image layers ScopeAllImages = "all-images" // also unused tagged images ScopeContainers = "containers" // exited containers ScopeBuildCache = "build-cache" // dangling build cache (libpod prunes it via the images-prune endpoint, which also reaps dangling image layers) ScopeVolumes = "volumes" // unused (unattached) volumes, protect-filtered )
Scope tokens. Dangling is the only default; the rest are opt-in.
const ProtectLabel = "podman-api.protect"
ProtectLabel marks a volume that must never be reaped by the volumes scope. The volume prune passes a "label!" filter so volumes carrying it are excluded.
NOTE: internal/podman/real_prune_integration_test.go duplicates this string (the podman package cannot import prune — prune imports podman) and is the only test that exercises the real filter. If you rename this, update that copy.
const TickInterval = time.Minute
TickInterval is how often the scheduler re-evaluates every host. It is the granularity of both the interval and threshold gates.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Defaults ¶
type Defaults struct {
Enabled bool
Interval time.Duration
DiskThreshold int // percent 0..100; 0 disables the threshold trigger
Scope []string
DryRun bool
}
Defaults are the global flag-derived policy defaults a per-host config merges over.
type Handler ¶
type Handler struct {
Client podman.Client
// Jobs, when set, enables a run-time safety re-check: before running the
// volumes scope the handler re-queries for an active migrate/evacuate and
// skips volumes if one is in flight. The scheduler also drops the volumes
// scope at enqueue time, but a job can sit queued while a move starts, so the
// guarantee belongs here too.
Jobs store.JobStore // optional
Metrics Metrics // optional
}
Handler implements jobs.Handler for the "prune" kind.
type HostPolicy ¶
HostPolicy pairs a host id with its resolved policy. The caller (main) builds this slice once at startup and again on SIGHUP reload.
type Payload ¶
Payload is the job-args shape the scheduler enqueues and the handler reads. It carries a snapshot of the resolved policy so a mid-flight config reload cannot change a running job's behavior.
type Policy ¶
type Policy struct {
Enabled bool
Interval time.Duration // zero disables the interval trigger
DiskThreshold int // percent 0..100; 0 disables the threshold trigger
Scope []string
DryRun bool
}
Policy is a fully-resolved, validated per-host prune policy. Defaults and Policy are intentionally the same shape: Defaults carries unvalidated flag-derived values, Policy is the post-Resolve, post-validate form.
type Scheduler ¶
type Scheduler struct {
Store store.JobStore
Client podman.Client
Now func() time.Time
// contains filtered or unexported fields
}
Scheduler enqueues prune jobs on a schedule. Store/Client/Now are injected so the tick logic is unit-testable without real time or a real podman host.
func (*Scheduler) Start ¶
func (s *Scheduler) Start(ctx context.Context, hostsFn func() []HostPolicy)
Start launches the ticker loop until ctx is cancelled. hostsFn returns the current host policies on each tick (so SIGHUP reloads are picked up). An immediate first pass runs before the ticker so a host already over threshold (or past its interval) at boot is handled without waiting a full tick. Use Wait to block until the loop has exited after cancellation.