Docs / Retention & cleanup
Retention & cleanup
Storage should shrink on its own. A retention policy says what stays; everything else is cleaned up on a schedule.
How rules work
A policy is a list of keep-rules attached to a repository. An artifact version survives if any rule keeps it. Versions kept by no rule become candidates for deletion. Rules are evaluated against tags, age and version order — never against guesswork.
Example policy
# retention.yaml — attached to platform/api-gateway
policy: nightly-cleanup
repository: platform/api-gateway
schedule: daily
dry_run: true
rules:
- type: keep-latest # always keep the 20 newest versions
count: 20
- type: keep-tagged # protect anything matching these tag patterns
patterns:
- "stable"
- "release-*"
- type: keep-referenced # keep versions pinned by a deployment record
within: 90d
- type: expire-untagged # untagged leftovers older than two weeks go
older_than: 14d
Dry run first
With dry_run: true the policy only reports what it would delete. Review the report, then switch the flag off:
# Preview the effect of a policy without deleting anything
kestrel retention preview --file retention.yaml
# Apply the policy for real
kestrel retention apply --file retention.yaml
Compliance-friendly keeps
For repositories that must retain releases, use a keep rule with a long horizon instead of cleanup rules:
policy: release-archive
repository: platform/api-gateway
rules:
- type: keep-tagged
patterns:
- "release-*"
minimum_age_to_delete: 730d # nothing tagged release-* goes before two years
Every deletion is written to the audit log with the actor, the rule that allowed it, and the artifact digest. See Access & audit.