Documentation
¶
Overview ¶
Package cacheprune reclaims disk held by the daemon's own caches, from inside the running daemon.
It exists because `ephemerd cache clear` used to be an offline `rm -rf`-style sweep of directories under the data dir, which required stopping the daemon and could not distinguish in-use data from garbage. Two of those directories cannot be cleared that way at all without leaving the node broken or leaking:
- the BuildKit cache is indexed by BuildKit's own bbolt DB, which holds references to the snapshots backing every cache record. Deleting the containerd image records, leases, or the directory out from under it leaves the snapshots pinned and reclaims nothing (confirmed on a production node: records and leases removed, disk unchanged, until the snapshots were removed too). Pruning has to go through BuildKit.
- the containerd store holds images a running job needs.
So the CLI asks the daemon, and the daemon prunes through the manager that owns each cache.
Index ¶
Constants ¶
const ( // TargetBuildKit prunes the BuildKit build cache through BuildKit's // own cache manager, plus the job-scoped build result records that // dead jobs left in the shared buildkit containerd namespace. TargetBuildKit = "buildkit" // TargetContainerd runs the disk-pressure image collector's eviction // over the containerd image store. TargetContainerd = "containerd" )
Target names, matching the entries `ephemerd cache list` reports.
Variables ¶
This section is empty.
Functions ¶
func AllTargets ¶
func AllTargets() []string
AllTargets lists every target this package can prune, in a stable order.
func ResolveTargets ¶
ResolveTargets normalizes a requested target list against the supported set. An empty request means "everything". Returns the accepted targets in AllTargets order (deduplicated) and any unrecognized names.
Pure — this is the whole request-validation rule, testable without a daemon.
Types ¶
type Interface ¶
Interface is the daemon-side pruner the control server calls. Kept as an interface so pkg/scheduler does not have to depend on BuildKit.
type Pruner ¶
type Pruner struct {
// Client is the containerd client. Required for the buildkit
// dead-record sweep and for reporting.
Client *containerdclient.Client
// BuildKit is the embedded solver. Nil means dind/buildkit is
// disabled on this node; the buildkit target then only sweeps dead
// job records.
BuildKit *buildkit.Server
// BuildKitNamespace is the containerd namespace build output lands in.
BuildKitNamespace string
// Policy is the configured steady-state GC policy. A non-"all" prune
// applies it on demand, so an operator-triggered prune and the
// automatic one collect the same things.
Policy buildkit.GCConfig
// ImageGC is the disk-pressure image collector, used for the
// containerd target. Nil disables that target.
ImageGC *imagegc.Collector
Log *slog.Logger
}
Pruner implements Interface against a live daemon's managers.
type Result ¶
type Result struct {
Name string
// BytesFreed is the space reclaimed where the underlying manager
// reports it. Zero means "not reported", not necessarily "nothing" —
// containerd's image deletion does not return a byte count.
BytesFreed int64
// RecordsRemoved counts metadata records dropped.
RecordsRemoved int64
// Err is set when this target failed. Other targets still run.
Err error
}
Result reports the outcome of pruning one target.