diskgc

package
v0.11.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 12, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package diskgc is the disk-pressure auto-reclaim loop. When host disk usage crosses a threshold it reclaims DANGLING docker images + build cache — the superseded builds that pile up as apps redeploy and are the usual reason a box fills up — and alerts the operator.

It only ever removes GARBAGE: `docker image prune -f` never touches a tagged image or one used by a container (running or stopped), and a Mooring rollback rebuilds its image, so this can't break a rollback or delete app data. It rides the one-docker-child semaphore via TryAcquire (skip-don't-queue), so it never delays a deploy.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pruner

type Pruner interface {
	PruneImagesHeld(ctx context.Context, onLine func(string)) error
	PruneBuildCacheHeld(ctx context.Context, keep string, onLine func(string)) error
}

Pruner runs the reclaim commands under a semaphore the CALLER already holds (satisfied by dockerexec.Runner). Both methods are the *Held variants: diskgc.Check holds the one docker slot across both prunes, so a non-Held call that re-Acquires the same slot would deadlock.

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

Runner is the disk-pressure watcher.

func New

func New(sample Sampler, prune Pruner, sem Sem, thresholdPct int, interval time.Duration, keep string, buildCacheGC bool, alert func(level, title, detail string), log *slog.Logger) *Runner

New builds a Runner. alert may be nil. buildCacheGC=false skips the build-cache prune (honors the operator's build_cache_keep_enabled:false opt-out); the dangling-image prune always runs.

func (*Runner) Check

func (r *Runner) Check(ctx context.Context) bool

Check reclaims if disk usage is at/over the threshold and the docker slot is free. Returns true if it ran a prune this call.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context)

Run checks a couple of minutes after boot, then every interval, until ctx is done.

type Sampler

type Sampler func() (used, total uint64, ok bool)

Sampler returns current host disk usage. ok=false means unavailable (skip this tick).

type Sem

type Sem interface {
	TryAcquire() bool
	Release()
}

Sem is the one-docker-child gate (satisfied by dockerexec.Semaphore).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL