imageretention

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: MIT Imports: 19 Imported by: 0

README

Image Retention

This feature automatically deletes cached converted images after they have been unused for a configurable amount of time.

The retention window is server-wide and controlled by:

images:
  auto_delete:
    enabled: false
    unused_for: 720h
    allowed: []

When auto-delete is enabled:

  • The server runs a retention sweep on startup and then every minute.
  • Only converted cached images under data_dir/images are eligible for deletion.
  • Shared OCI cache data under data_dir/system/oci-cache is not modified by this feature; see lib/ocicachegc for a separate mark-and-sweep collector that reclaims orphaned blobs from that directory.
  • An image repository must also match at least one allowed pattern before any retention state is recorded or deletion is attempted.

An image is considered in use if any persisted instance metadata or snapshot record still references it. As long as at least one such reference exists, the image is protected from deletion.

The retention timer starts only after the last persisted reference disappears and the image repository is allowed by policy. At that point the server records unused_since for the image digest. Once unused_since + unused_for has elapsed, the cached image digest is deleted.

Allow-list patterns match normalized repository names such as docker.io/library/alpine. A lone * pattern allows deletion for every repository.

New instance creation clears any stale unused state for the resolved image before the new instance metadata is written. This helps prevent races where an image is being reused right as retention cleanup runs.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Controller

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

Controller tracks unused cached images and deletes them after a retention window.

func NewController

func NewController(p *paths.Paths, imageManager images.Manager, unusedFor time.Duration, allowed []string, logger *slog.Logger, meter metric.Meter) (*Controller, error)

NewController creates a new image retention controller.

func (*Controller) MarkUsed

func (c *Controller) MarkUsed(ctx context.Context, imageName, digest string) error

MarkUsed clears retention state for a digest that is about to be referenced by a new instance.

func (*Controller) Run

func (c *Controller) Run(ctx context.Context) error

Run executes one sweep immediately, then continues sweeping every minute until ctx is cancelled.

func (*Controller) Sweep

func (c *Controller) Sweep(ctx context.Context) error

Sweep performs one reconciliation pass of image retention state.

type Metrics

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

Metrics holds the OTel instruments for image retention.

func (*Metrics) RecordDelete

func (m *Metrics) RecordDelete(ctx context.Context, status string)

RecordDelete records the outcome of an image delete attempt.

func (*Metrics) RecordSweep

func (m *Metrics) RecordSweep(ctx context.Context, status string, duration time.Duration, staleReferences int)

RecordSweep records the outcome and duration of a retention sweep.

Jump to

Keyboard shortcuts

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