stale

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: Apache-2.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package stale gives every image an explainable staleness verdict.

Signals (base drift, supersession, untagged, age, pulls, EOL roots and label policy) combine into one of four verdicts through a policy file. Every verdict carries the reasons that produced it; there is no opaque score.

Index

Constants

View Source
const (
	Fresh     = "fresh"
	Drifting  = "drifting"
	Stale     = "stale"
	Abandoned = "abandoned"
)

Verdicts, from best to worst.

Variables

Verdicts lists every verdict in display order.

Functions

func Recompute

func Recompute(ctx context.Context, db *sql.DB, policy Policy, now time.Time) ([]string, error)

Recompute evaluates every image in the index and updates the staleness table. Verdicts depend on the time as well as the index, so every image is evaluated, but only rows whose verdict, reasons or day counts changed are written. It returns the digests it wrote or removed.

Types

type Evaluator

type Evaluator struct {
	Policy  Policy
	History History
	Repos   RepoImages
	Now     time.Time
	// HavePulls is whether any pull data exists in the index.
	HavePulls bool
	// contains filtered or unexported fields
}

Evaluator turns facts into verdicts under one policy.

func (*Evaluator) Evaluate

func (e *Evaluator) Evaluate(f Facts) Result

Evaluate computes the verdict and reasons for one image.

type Facts

type Facts struct {
	Digest      string
	IndexDigest string
	Repo        string
	Created     time.Time
	Tags        int
	Descendants int
	Labels      map[string]string
	RootRefs    []string
	// LastPulled is the last pull time, or zero if there is no pull data.
	LastPulled time.Time
	// Pushed is when the registry says the image was pushed, or zero.
	Pushed time.Time
	// Parent describes the image's preferred parent, if it has one.
	Parent *ParentFacts
}

Facts are what the index knows about one image, as input to Evaluate.

type History

type History map[string][]model.TagEvent

History is tag history grouped by repo:tag, each list oldest first.

func NewHistory

func NewHistory(events []model.TagEvent) History

NewHistory groups and sorts tag events.

type Override

type Override struct {
	Repo       string            `yaml:"repo"`
	Labels     map[string]string `yaml:"labels"`
	Thresholds Thresholds        `yaml:"thresholds"`
}

Override applies different thresholds to images matching a repo glob and label values.

type ParentFacts

type ParentFacts struct {
	Digest      string
	IndexDigest string
	Repo        string
	Created     time.Time
	Phantom     bool
}

ParentFacts describe an image's parent for base-drift detection.

type Policy

type Policy struct {
	Thresholds Thresholds `yaml:"thresholds"`
	// DeprecatedLabels are label keys that mark an image stale when set to
	// a true value (true, yes, 1).
	DeprecatedLabels []string `yaml:"deprecated_labels"`
	// ExpiresLabels are label keys holding a date (YYYY-MM-DD or RFC 3339)
	// after which the image is stale.
	ExpiresLabels []string `yaml:"expires_labels"`
	// EOLRoots are root refs or digests, with * globs, whose OS is past
	// end of life, such as docker.io/library/debian:buster*.
	EOLRoots []string `yaml:"eol_roots"`
	// AssumeUnpulled treats images as unpulled when the registry gives no
	// pull data, so untagged leaves can still be called abandoned.
	AssumeUnpulled *bool      `yaml:"assume_unpulled"`
	Overrides      []Override `yaml:"overrides"`
}

Policy configures how signals become verdicts.

func DefaultPolicy

func DefaultPolicy() Policy

DefaultPolicy returns the starting thresholds from the spec. They are defaults to tune, not recommendations.

func LoadPolicy

func LoadPolicy(file string) (Policy, error)

LoadPolicy reads a policy file over the defaults. An empty path returns the defaults.

func ParsePolicy

func ParsePolicy(data []byte) (Policy, error)

ParsePolicy parses policy YAML over the defaults and validates it.

func (Policy) For

func (p Policy) For(repo string, labels map[string]string) Thresholds

For returns the thresholds that apply to an image, with matching overrides applied in order.

func (Policy) Validate

func (p Policy) Validate() error

Validate checks that thresholds are usable and globs are well formed.

type RepoImages

type RepoImages map[string][]time.Time

RepoImages lists the creation times of the images in each repo, for approximating drift before tag history began.

type Result

type Result struct {
	Digest               string   `json:"digest"`
	Verdict              string   `json:"verdict"`
	Reasons              []string `json:"reasons"`
	BaseDriftGenerations int      `json:"base_drift_generations"`
	BaseDriftDays        *int     `json:"base_drift_days,omitempty"`
	BaseTag              string   `json:"base_tag,omitempty"`
	SupersededDays       *int     `json:"superseded_days,omitempty"`
	Untagged             bool     `json:"untagged"`
	AgeDays              *int     `json:"age_days,omitempty"`
	LastPulledDays       *int     `json:"last_pulled_days,omitempty"`
	EOLBase              bool     `json:"eol_base"`
	LabelPolicy          bool     `json:"label_policy"`
	Inferred             bool     `json:"inferred"`
}

Result is a verdict with the signals behind it.

type Thresholds

type Thresholds struct {
	// StaleGenerations is how many generations of base drift make an
	// image stale. One generation less makes it drifting.
	StaleGenerations int `yaml:"stale_generations"`
	// SupersededDays is how long an image can be superseded under a tag
	// before it is stale rather than drifting.
	SupersededDays int `yaml:"superseded_days"`
	// AbandonedPullDays is how long an untagged leaf can go unpulled
	// before it is abandoned.
	AbandonedPullDays int `yaml:"abandoned_pull_days"`
}

Thresholds are the numbers a verdict is decided by. Zero values in an override leave the base policy's value in place.

Jump to

Keyboard shortcuts

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