Registry retention¶
A registry that every release pushes to only grows. A node-local registry
fills the node’s disk (a few hundred MB per release for an app with several
images); a hosted registry fills a quota. piceli artifacts retention tells
you which manifests a registry must keep and which it can drop, and with your
approval deletes the rest.
Maturity: experimental
New in 0.13.0; it may change in a minor release, with a changelog entry. See the Roadmap.
The in-cluster registry in one command¶
For the registry of Registry.in_cluster (see In-cluster registry), name
the declared cluster and Piceli works out the rest: the registry, the
port-forward to its Service, the cluster read (every namespace) and the list
of every manifest the registry stores, tagged or not. No receipts, no pins.
# 1. Plan: the deletions and the plan hash (exit 3); changes nothing.
piceli artifacts retention --cluster infra.py:my_cluster --delete
# 2. Delete exactly that plan (refused if anything changed since).
piceli artifacts retention --cluster infra.py:my_cluster --delete --approve <digest>
# 3. Free the disk: the registry's garbage collector, dry run first, at a time
# when no cluster build Job runs and nothing pushes.
kubectl --kubeconfig FILE --context NAME -n piceli-system \
exec deploy/piceli-registry -- \
registry garbage-collect --dry-run /etc/distribution/config.yml
kubectl --kubeconfig FILE --context NAME -n piceli-system \
exec deploy/piceli-registry -- \
registry garbage-collect /etc/distribution/config.yml
# 4. The claim's use afterwards.
piceli registry status infra.py:my_cluster
--cluster takes infra.py:CLUSTER (a piceli.infra.Cluster declared with
registry=Registry.in_cluster(...), reached through its credential profile),
the composition module itself (infra.py), a pipeline delivering to
Registry.in_cluster (its target names the cluster) or that value (then with
--kubeconfig FILE --context NAME). Without --delete it only reports
(exit 0). With --cluster:
kept: every digest a pod in any namespace uses (spec image and
imageID) and every workload template; each Deployment’s and StatefulSet’s rollback target (below); what Piceli itself uses now: the controller (piceli-gitops) and UI Deployments and the builder image inpiceli-gitops-config; the digests in environment records and the controller’s status; pins and, with--receiptsand--keep N, releases; and the platform manifests and referrers of everything kept;collectable: everything else in the registry, with or without a tag or a receipt: old controller and builder copies, digest-only images nothing names any more, older rollout history.
--keep defaults to 0 and tagged manifests no receipt mentions are
collectable (--collect-unledgered is implied): the cluster is the
inventory. The approval command is printed in full
(approve_command). The receipt’s garbage_collect.commands repeat step 3
for this registry’s namespace and name. Piceli has no registry gc command:
the collector must not run while a push is in flight, and a push through a
port-forward from a laptop cannot be seen from the cluster, so that moment is
yours to choose.
Rollback targets. kubectl rollout undo returns a workload to its
previous release, so that release’s images stay: a Deployment’s newest
scaled-down ReplicaSet that is not its current revision, and a StatefulSet’s
newest ControllerRevision that is not its update revision (and, while a
rollout runs, its current revision). Older history is collectable. Piceli’s
own controller, UI and registry (labelled piceli.io/component gitops,
ui or cluster, or app.kubernetes.io/name=piceli-cluster-registry) have
none: their old copies go. Rows of kept rollback targets carry the reason
rollback; the delete refuses any plan that names one.
Listing the storage. The registry API lists tags, not untagged
manifests, and Piceli pushes by digest. So retention runs one read-only
command in the registry pod over pods/exec:
find /var/lib/registry/docker/registry/v2/repositories \
-path '*/_manifests/revisions/sha256/*/link' -type f
(no shell, nothing written), and reads each listed manifest through the API.
When the listing is refused or no registry pod runs, the report says
"storage_listing": {"read": false, "reason": "registry-storage-unreadable"}
and only manifests something still names are found; nothing else changes.
Permissions of the credential that runs it:
What |
Resources and verbs |
|---|---|
The cluster read (all namespaces) |
|
The storage listing (registry namespace) |
|
The port-forward (registry namespace) |
|
|
|
What is kept¶
A manifest (an image, or an image index with its per-platform manifests) is kept when any of these holds; everything else is collectable.
Rule |
Source |
|---|---|
One of the last |
the publish receipts ( |
Pinned |
|
Live: a workload uses or will pull it, or an environment names it |
read from the cluster ( |
Rollback target: the previous release of a Deployment or StatefulSet |
read from the cluster with the live workloads: the newest scaled-down ReplicaSet that is not the Deployment’s current revision; the newest ControllerRevision that is not the StatefulSet’s update revision (see rollback targets) |
A child or a referrer of a kept manifest |
the platform manifests of a kept index; its SBOM, provenance and signatures (OCI referrers and |
Unledgered: tagged, but no receipt mentions it |
kept by default; |
A release’s receipt names a repository and a digest, never a host, so the same
receipts serve a registry reached directly, through --via-forward, or by a
node address. piceli deploy writes one delivery receipt per image into
<state_dir>/deliveries/: pass that directory. “Release k” is, for every
repository, its k-th newest distinct digest, so --keep 3 keeps each
image’s last three digests; images that change together line up, and an image
that did not change in a release keeps its newest digest.
Live means what runs or is referenced now, never that a receipt exists.
Three kinds of objects still name an image but will never pull it again, so
they do not make it live: a pod that Succeeded or Failed, a Job with a
true Complete or Failed condition, and a ReplicaSet a Deployment owns
that is scaled to zero with no pod left (its rollout history). The newest
such ReplicaSet is still kept, as the workload’s rollback target; older ones
are not. A component that moved to another registry (say a controller now
pulled from a hosted registry by another digest) leaves its old copy
collectable.
Manifests without a tag or receipt. The registry API lists tags, not
untagged manifests, and images delivered to Registry.in_cluster are pushed
by digest. So besides the catalog, tags and receipts, retention looks up
every digest the cluster still names (live or not: finished pods and Jobs,
rollout history, environment records) in the repository its reference
names. A manifest found that way and used by nothing live is collectable,
with why: ["not-live"] and the objects that still name it in seen_in.
--keep 0 keeps no release: only live, pinned and unledgered (tagged,
no receipt) manifests and their children and referrers stay. It needs the
cluster read (--kubeconfig with --context); with only --live-file, or
none, it is refused (retention-invalid), because the live inventory is then
the only protection. It never deletes anything live: live digests and the
index and platform manifests of a live multi-platform image are kept by
construction, and the delete refuses any plan that names one.
Budget mode. --budget 10GiB keeps more releases than --keep, newest
first, while everything kept (pinned and live digests included) stays within
the budget. Blobs are deduplicated: layers shared between releases, and
between images, count once. It never keeps fewer than --keep releases and
stops at the first release that does not fit. Sizes: B, KB/MB/GB/TB
(powers of 1000), KiB/MiB/GiB/TiB (powers of 1024).
Report, then delete¶
# Report only: reads the registry and the cluster, changes nothing (exit 0).
piceli artifacts retention --to oci://127.0.0.1:5000/shop \
--receipts dist/receipts/ --keep 3 --budget 10GiB \
--kubeconfig ~/k/my-cluster.yaml --context my-cluster \
--via-forward service/registry --namespace registry --forward-remote-port 5000
# Delete: the same command with --delete prints the plan and its hash (exit 3)...
piceli artifacts retention … --delete
# ...review the `collectable.deletions`, then approve exactly that hash.
piceli artifacts retention … --delete --approve <digest>
The report is one JSON object: policy, live (how many digests were read
and from where, by kind: pod, deployment, … environment, controller),
releases (kept or not, and why), one row per manifest with its tags, bytes,
kept, reasons (release, budget, pinned, live, rollback,
referenced, unledgered, unreferenced) and live_by, kept.bytes,
collectable.reclaimable_bytes and the digest of the plan. Each entry of
collectable.deletions names exactly what would be removed: repository,
digest, bytes (the manifest and its layers, before deduplication), why
it is not kept (old-release or over-budget for a release past the policy,
not-live when only finished or rollout-history objects name it,
unledgered, else unreferenced) and seen_in (for example
replicaset:history, controllerrevision:history, pod:finished,
job:finished). live.rollback counts the rollback targets. --out FILE
also writes it.
To remove every image nothing uses on a registry reached through a
port-forward (--to takes a repository prefix: run it once per top-level
prefix, such as shop for shop/api and shop/worker; for the in-cluster
registry prefer --cluster, which
also finds manifests nothing names):
# Plan: prints the deletions and the hash (exit 3), changes nothing.
piceli artifacts retention --to oci://127.0.0.1:5000/shop \
--receipts <state_dir>/deliveries/ --keep 0 \
--kubeconfig ~/k/my-cluster.yaml --context my-cluster \
--via-forward service/piceli-registry --namespace piceli-system \
--forward-remote-port 5000 --delete
# Apply exactly that plan.
piceli artifacts retention … --delete --approve <digest>
Deleting is approval-gated like every Piceli change. The digest covers the
registry and the exact list of (repository, digest) deletions, and the plan
is computed again when you pass --approve: if a release landed, a pin
changed or a workload started using one of the digests since you reviewed it,
the hash differs and nothing is deleted (retention-not-approved).
Safety rules that hold whatever the options:
A digest a running workload uses is never deleted.
--deleteneeds a live source (retention-live-unknownotherwise): an unknown inventory never licenses a deletion. Tag-only pod images keep the digest their tag names.Children are deleted after their index; a kept index never loses a child.
A registry that refuses deletes answers with
registry-delete-disabled(HTTP 405): enableREGISTRY_STORAGE_DELETE_ENABLED=true(the node-local registry already does). The receipt lists what was deleted before the refusal.Credentials come only from
--credentials FILEor--docker-config FILE; plain HTTP is only for a loopback registry.
Reclaiming the space¶
Deleting a manifest removes the reference, not the layers: the registry frees
disk when its garbage collector runs. The report’s reclaimable_bytes
(and the receipt’s reclaimed_bytes) are the deduplicated bytes of the blobs
and manifests that no kept manifest references, which is what the collector
frees.
Piceli’s in-cluster registry (
Registry.in_cluster): run the registry’s collector inside its pod, with the same explicit kubeconfig and context, at a time when no deploy, cluster build or mirror is pushing:kubectl --kubeconfig ~/k/my-cluster.yaml --context my-cluster \ -n piceli-system exec deploy/piceli-registry -- \ registry garbage-collect /etc/distribution/config.yml
Add
--dry-runfirst to see what it would remove. Never add--delete-untagged: images are pushed by digest, untagged, and it would delete every one of them. Piceli’s registry configuration has no blob descriptor cache, so no restart is needed afterwards;piceli registry statusshows the claim’s usage. (For another name or namespace, use the registry’s Deployment name and namespace.)Piceli’s node-local registry: apply
registry.garbage_collection( delete_untagged=False)(see Node-local registry). Keepdelete_untagged=False: images pushed by digest have no tag, and--delete-untaggedwould delete them all.distribution/registry:registry garbage-collect /etc/docker/registry/config.ymlinside the registry container, with pushes stopped or the registry read-only.Hosted registries collect on their own schedule; some (Docker Hub, GHCR) have their own retention settings instead of the delete API.
What it cannot see¶
Repositories are found from the receipts,
--repository(repeatable) and, when the registry serves it,/v2/_catalog, under the prefix of--to.Manifests that nothing tags, no receipt names and no object of the cluster names any more are invisible to the registry API; a blob garbage collection without
--delete-untaggedleaves them alone. With--topass their digests with--live-fileonly to keep them, never to find them; with--clusterthe storage listing finds them.A live digest read from a
--live-file(or an environment record) without a repository is looked up in every repository under--to.Space shared with repositories outside
--tois not counted as reclaimable for that registry’s other users.Live workloads are read from the cluster you name. Workloads in namespaces you did not scan, on other clusters, or created after the report are not seen: pin their digests (
--pin) or scan every namespace (the default).
How often¶
Run the report after every release, and delete with the approved plan when it shows collectable manifests or the registry is over its budget (for a node-local registry: weekly, or from the release routine right after a successful release, followed by the garbage-collection Job).
Error codes¶
Code |
When |
|---|---|
|
a malformed |
|
|
|
|
|
(reported in |
|
|
|
the registry refuses |
The registry errors of Artifact delivery and operation telemetry (registry-unauthorized,
registry-unreachable, …) apply as well.