Documentation
¶
Overview ¶
Package retention implements a restic-style retention engine that works with any named+timestamped items (registry tags, forge releases, etc). Policies are additive — an item survives if ANY rule wants to keep it.
Index ¶
- func ApplyPolicies(candidates []Item, policy config.RetentionPolicy) []bool
- func ApplyTimeBucket(candidates []Item, keepSet []bool, count int, bucket BucketFn)
- func TemplateToPattern(tmpl string) string
- func TemplatesToPatterns(templates []string) []string
- func TruncateToDay(t time.Time) time.Time
- func TruncateToMonth(t time.Time) time.Time
- func TruncateToWeek(t time.Time) time.Time
- func TruncateToYear(t time.Time) time.Time
- type BucketFn
- type Item
- type Result
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyPolicies ¶
func ApplyPolicies(candidates []Item, policy config.RetentionPolicy) []bool
ApplyPolicies evaluates all retention rules and returns a keep/prune decision for each candidate. candidates must be sorted newest-first. Policies are additive: an item is kept if ANY rule marks it.
func ApplyTimeBucket ¶
ApplyTimeBucket keeps the newest item in each of the last N distinct time buckets. candidates must be sorted newest-first.
func TemplateToPattern ¶
TemplateToPattern converts a single tag template to a regex pattern.
func TemplatesToPatterns ¶
TemplatesToPatterns converts StageFreight tag templates into regex patterns suitable for config.MatchPatterns.
Template variables like {sha:8}, {version}, {branch} are replaced with regex wildcards (.+) so the pattern matches any resolved value.
Examples:
"dev-{sha:8}" → "^dev-.+$"
"{version}" → "^.+$"
"latest" → "^latest$"
"!{branch}-rc" → "!^.+-rc$"
func TruncateToDay ¶
TruncateToDay truncates a time to the start of its day.
func TruncateToMonth ¶
TruncateToMonth truncates a time to the first day of its month.
func TruncateToWeek ¶
TruncateToWeek truncates a time to the start of its ISO week (Monday).
Types ¶
type Result ¶
type Result struct {
Matched int // items matching the pattern set
Kept int // items kept by policy
Deleted []string // items successfully deleted
Skipped []string // items skipped (digest shared with protected item)
Errors []error // errors from individual deletes
}
Result captures what the retention engine did.
func Apply ¶
func Apply(ctx context.Context, store Store, patterns []string, policy config.RetentionPolicy) (*Result, error)
Apply lists all items from the store, filters them by patterns (using config.MatchPatterns), sorts by creation time descending, applies restic-style retention policies, and deletes items not kept.
patterns uses the same syntax as branches/git_tags in the config:
["^dev-"] → only items starting with "dev-" ["^dev-", "!^dev-keep"]→ dev- items, excluding dev-keep* [] → ALL items are candidates