cleanup

package
v1.28.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package cleanup reclaims podman disk lerd's own image rebuilds leave behind. The safe tier only ever removes what is provably lerd's: an image with a dev.lerd.* label, or the lerd-php*-fpm-base repo name only lerd's pre-built base images use. The deep tier additionally reaps every dangling image, which is untagged and unreferenced by definition so removing it strands nothing, and catalog service images no service references any more. Neither tier ever touches a tagged image in use, a container, or a named volume.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(p Plan) (removed int, reclaimed int64)

Apply removes every target in the plan and returns how many images were actually removed and the disk reclaimed (a skipped target counts toward neither). It sweeps in repeated passes, retrying targets that failed until a full pass frees nothing new: podman refuses a parent image while a child is still present, so removing a dangling build chain listed parent-first needs the children gone first. A target that never succeeds (e.g. it became referenced since Inspect) is simply left, so one stuck image can't abort the sweep.

func SweepDeep added in v1.28.0

func SweepDeep() (images int, bytes int64, err error)

SweepDeep runs the deep tier: the managed tier plus every remaining dangling image on the host, foreign leftovers included. Interactive only, never run unattended.

func SweepManaged added in v1.28.0

func SweepManaged() (images int, bytes int64, err error)

SweepManaged runs the managed tier (safe orphans plus lerd's unused catalog images), the daily watcher's sweep: it reclaims an upgrade's leftovers unattended without ever touching a foreign dangling image.

func SweepRefs

func SweepRefs(refs ...string)

SweepRefs reaps the exact image references lerd is dropping (the superseded version after a service update, the removed service's images after a remove). Each ref is one lerd itself recorded, so it is provably lerd's; a ref another service still references (in the protected set) is skipped. Reaping precise refs rather than a whole repo means a user's own same-repo image is never touched. Gated by auto_cleanup.

func SweepSafe

func SweepSafe() (images int, bytes int64, err error)

SweepSafe runs the safe-tier cleanup immediately when auto_cleanup is on. It is the event hook for the moment a PHP image rebuild orphans the old image, reaping it at once instead of waiting for the daily watcher.

Types

type HeldByContainers added in v1.28.0

type HeldByContainers struct {
	Count int
	Bytes int64
}

HeldByContainers tallies reclaimable disk a restart would free.

type Plan

type Plan struct {
	Targets []Target
	// Held counts dangling images a running container still holds that would
	// otherwise be reaped. They can't be removed now, but a restart recreates the
	// container on the current image and releases them, so the caller can hint it.
	Held HeldByContainers
}

Plan is the set of lerd-owned resources that are safe to reclaim.

func Inspect

func Inspect(scope Scope) (Plan, error)

Inspect returns the cleanup plan. The always-safe tier reclaims what is provably lerd's:

  • derived images lerd built and then orphaned: lerd tags every live build with a fixed :local tag, so a rebuild re-points the tag and leaves the old image dangling — the unambiguous "superseded" signal.
  • pre-built base images nothing live is built on: a base for an old Containerfile hash, or for a PHP version no longer installed.

Both removals are refcount-safe: layers a live image still shares are kept.

ScopeManaged widens this to lerd's catalog upgrade leftovers, ScopeDeep to every remaining dangling image (foreign included). An image a container holds is always skipped, and the catalog reap is skipped if the protected set fails.

func (Plan) ReclaimBytes

func (p Plan) ReclaimBytes() int64

ReclaimBytes is the total disk the plan would free.

type Scope added in v1.28.0

type Scope int

Scope selects how wide a cleanup reaches. The levels are ordered and additive, so each tier includes everything the tier before it removes.

const (
	// ScopeSafe reclaims only images provably lerd's own: orphaned derived builds
	// and unreferenced base images.
	ScopeSafe Scope = iota
	// ScopeManaged additionally reclaims catalog service images no service
	// references any more (upgrade leftovers). Still lerd-scoped, so it is safe to
	// run unattended; this is the daily watcher's tier.
	ScopeManaged
	// ScopeDeep additionally reclaims every remaining dangling image on the host,
	// foreign ones included. Interactive only (`lerd cleanup --deep`).
	ScopeDeep
)

type Target

type Target struct {
	Kind  string // "image"
	ID    string // short image ID
	Desc  string // human description for the plan output
	Bytes int64
}

Target is one reclaimable resource.

Jump to

Keyboard shortcuts

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