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 ¶
const ( Fresh = "fresh" Drifting = "drifting" Stale = "stale" Abandoned = "abandoned" )
Verdicts, from best to worst.
Variables ¶
Verdicts lists every verdict in display order.
Functions ¶
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.
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 ¶
History is tag history grouped by repo:tag, each list oldest first.
func NewHistory ¶
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 ¶
LoadPolicy reads a policy file over the defaults. An empty path returns the defaults.
func ParsePolicy ¶
ParsePolicy parses policy YAML over the defaults and validates it.
type RepoImages ¶
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.