cleanup

package
v1.27.0 Latest Latest
Warning

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

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

Documentation

Overview

Package cleanup reclaims podman disk that lerd itself created — the orphaned PHP/FrankenPHP images that rebuilds leave behind — and nothing else. An image is only ever eligible when it is provably lerd's: a dev.lerd.* label, or the lerd-php*-fpm-base repo name only lerd's pre-built base images use. So it can never touch images, containers, or volumes belonging to anything else.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(p Plan) (reclaimed int64)

Apply removes every target in the plan and returns the disk reclaimed. A target that fails to remove (e.g. it became referenced since Inspect) is skipped, so one stuck image can't abort the whole sweep.

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. Returns the number of images reaped and bytes freed; err is non-nil only when the image scan itself failed, so the watcher can tell a transient failure (retry) from "nothing to do" (throttle). All-zero with nil err when disabled or clean.

Types

type Plan

type Plan struct {
	Targets []Target
}

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

func Inspect

func Inspect(deep bool) (Plan, error)

Inspect returns the safe-tier cleanup plan. It reclaims two kinds of lerd image a rebuild leaves behind:

  • 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.

When deep is true it also reclaims the more aggressive tier: catalog service images no service references any more (see deepTargets). If the protected set can't be built, the deep tier is skipped rather than risk a wrong removal.

func (Plan) ReclaimBytes

func (p Plan) ReclaimBytes() int64

ReclaimBytes is the total disk the plan would free.

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