absurdum reductus

Your Deployment Broke Weeks Ago and Nothing Noticed

Three critical alerts fired at once: the directory, mail retrieval and outgoing mail were all down, and everything about it said infrastructure. It was two image tags that had been deleted from our registry weeks earlier, by a retention policy working exactly as designed. Nothing had failed when they went. A month before, we had written down that this would happen, naming the same two images, in a place nobody would look.


Three alarms and the wrong suspects#

The alerts were ServiceDown for LDAPS, IMAP and SMTP. The outgoing mail pod was running the whole time; it went down only because it binds to the directory, which was not there. The other two pods sat in Init:ImagePullBackOff with zero restarts. That combination means the main container had never started, so the application was not crashing. Something the pod needed before it could begin was missing.

The onset was its own small puzzle. Our Prometheus does not expose ALERTS_FOR_STATE, so we bracketed it by asking for ALERTS at a series of offsets: empty twelve hours back, present nine hours back. That put the start in a three-hour window around 14:45 UTC, about thirteen hours before the services came back.

So the obvious suspects lined up: a network fault, or a registry that might not be reachable. Each was a reasonable guess. The pull error ruled both out:

failed to resolve reference "registry.example.com/team/dir-init:0.1.6": not found

(Registry host and image path replaced; the tag and the wording are as logged.) not found is not a timeout and not a TLS failure. Nothing was unreachable. The registry answered promptly that the thing we asked for did not exist. That is a different investigation, and it took one kubectl describe to start it.

Nothing failed when the tag disappeared#

Both broken pods had an init container pinned to an exact tag of one of our own images. The registry project those images came from keeps the five most recently pushed artifacts per repository and deletes the rest. It had kept ten until mid-July, when we tightened it to reclaim space after that project filled the registry’s volume.

Put a fixed pin next to a keep-the-last-N rule and you have built a clock. Every push of that image moves the floor up by one. The pin does not move. Eventually the floor passes the pin, the tag stops existing, and nothing happens. The running containers already have their layers. Git still holds a valid manifest. CI renders it happily. The cluster reports every pod Running, and every dashboard is green. The deployment is broken and nothing in the system is able to say so, because the only way to observe the fault is to try to pull.

By the day of the outage, the directory’s init container wanted 0.1.6 and the oldest tag the registry still held was 0.1.7. The mail server’s wanted 0.1.2; the oldest survivor was 0.1.13. A routine reschedule forced a fresh pull, and it collected the whole debt at once.

The pull policy decides how long the grace period lasts. With IfNotPresent, the Kubernetes default for a pinned tag that is not latest, a node that already has the image keeps starting it; only a pod landing on a node without the image fails. Both of ours were set to Always, for which the Kubernetes documentation says “every time the kubelet launches a container, the kubelet queries the container image registry to resolve the name”. Once the tag is gone, such a pod cannot survive any restart, on any node.

That is the defect worth naming. Not “a tag got deleted”: tags are supposed to be deleted, that is what the policy is for. The defect is that the time between “this is broken” and “this stops working” is bounded only by how often the pod happens to be rescheduled, and on a stable cluster nothing makes that short. It is not an oversight in any one component. It is a property of the combination, and no component owns the combination.

We had already written this down#

We restored service by moving both pins to current tags. Then we went looking for how long this had been knowable, and the answer was: a month.

Thirty-four days earlier, while setting up retention on the registry of our other site, we had audited the live pins against the proposed floor before choosing a number. The audit found two workloads below the keep-five line, both with imagePullPolicy: Always. They were the directory and the mail server, pinned to the same two images. The comment that went on that retention policy said, correctly, that pruning them “breaks the next restart, not merely a cold node”. So that site chose to keep ten instead. Its two pins were the seventh and eighth most recent pushes of their repositories. Under five they would have been deleted; under ten they stayed. That decision, not any tool, is why the other site did not have the same outage.

The same knowledge was in three more places. Our knowledge base recorded the audit, as a caveat near the end of a long entry whose subject was keeping a pull-through cache warm. The retention policy on our own registry carried a comment saying that a pin older than the last five pushes will be pruned, and that “a stuck-old pin needs its own bump”. And the dependency bot’s configuration for the failing site noted that six image pins were invisible to it. That note was in the description of a rule holding a certificate exporter at its old major version.

Every one of those statements pointed at the real risk. None of them was filed under the symptom. Nobody whose pod cannot pull its image goes looking in a note about cache warming, or in a hold on a certificate exporter, or in the comment block above a retention rule they did not change. The other site acted on the audit because it was written in the same change that chose its number. Everyone else would have needed to already know.

A correct prediction filed under the wrong subject is indistinguishable from no prediction. What we changed is small: the trap now has its own entry in the knowledge base, tagged with what you see when it fires, and the directory’s pin and the check below both carry a pointer to it.

Seeing the pin is not the same as moving it#

The obvious engineering fix is to keep pins fresh automatically, and there was a real gap to close. We use Renovate with regex custom managers, because our values files are not named in the way its built-in Helm manager recognises. All three of our managers matched the two-line form:

repository: registry.example.com/team/app
tag: 0.4.2

Init containers and sidecars are written inline, as image: registry.example.com/team/dir-init:0.1.6, and no manager matched that. We counted eight such pins; the note in the configuration had said six. We added a second pattern for the inline form to each existing manager, and Renovate’s next run opened bumps for three pins it had never seen before.

That was necessary. It was not sufficient, and we learned so twenty-five days later, when the mail server went down again the same way.

The image registry at that site is a mirror: a project that copies another registry’s project on a schedule. The pin was current now, and Renovate could see it. But on the mirror, the policy’s “most recently pushed” means most recently copied, and copy order has nothing to do with version order. When the mail server failed the second time, the mirror held five older versions, 0.1.17 through 0.1.21. It did not hold 0.1.22, the one we had pinned, and the source registry still had it. The directory’s pin was in the same state; its pod was still running only because nothing had restarted it yet. Eight references to a third image would have failed at their next scheduled run.

So we dropped the pins to tags the mirror still held, and raised the mirror’s retention back to ten, which at least stops it from being shallower than the registry it copies. Neither change is the fix. On a mirror, the version tells you nothing about how close a pin is to the floor.

The check that asks the right question#

“Can the bot see this pin?” fires on coverage. “Is there a newer tag?” fires on freshness. Neither fires on the actual condition, which is this: does every pinned artifact still resolve, and how many more pushes until the floor reaches it?

That question has to be asked of the registry, not of the repository. Here is its core, as a small script over what Harbor’s artifacts endpoint returns for one repository. It ranks the pinned tag by push time, because push time is what the retention rule ranks by, and it warns when push order and version order disagree:

#!/bin/sh
# headroom.sh FILE TAG KEEP
# FILE: the JSON from Harbor's
#   GET /api/v2.0/projects/<p>/repositories/<r>/artifacts?with_tag=true
# TAG:  the pinned tag.  KEEP: the policy's "most recently pushed" count.
f=$1 tag=$2 keep=$3
rank=$(jq -r --arg t "$tag" '
  sort_by(.push_time) | reverse | map([.tags[]?.name])
  | to_entries | map(select(.value | any(. == $t)))
  | if length == 0 then "" else .[0].key + 1 end' "$f")
[ -n "$rank" ] || { echo "$tag: MISSING"; exit 1; }
echo "$tag: push rank $rank, headroom $((keep - rank))"
newest=$(jq -r '.[].tags[]?.name' "$f" | sort -V | tail -n 1)
latest=$(jq -r 'max_by(.push_time).tags[0].name' "$f")
[ "$newest" = "$latest" ] ||
  echo "  newest version $newest is not the latest push ($latest):" \
       "push order is not version order here"

Against an invented mirror fixture, five artifacts where the newest version happened to be copied first, with jq 1.8.1:

$ sh headroom.sh mirror.json 0.1.22 5
0.1.22: push rank 5, headroom 0
  newest version 0.1.22 is not the latest push (0.1.20): push order is not version order here
$ sh headroom.sh mirror.json 0.1.2 5
0.1.2: MISSING

The newest release is the next thing the policy deletes. That is the shape of the second outage, in two lines.

The version we run for real walks every pin in our deployment repositories and does this for each. Its first sweep checked 113 pins and found two missing, both in configuration nothing deploys any more, and seven with at most one push of headroom, one of them on a path that something deploys.

The instrument lies, so make it say so#

Two things make the answer less clean than that, and both bit us while we were building it.

A pull-through cache project, the kind that fronts Docker Hub or another public registry, does not answer the artifacts endpoint the way a local project does. Ours returned an empty or untagged list for images that were running perfectly well, so during the investigation two healthy images read as missing. And a mirror is rebuilt one artifact at a time while a copy runs, so a sample taken minutes into a sync reported thirteen live pins missing, and all of them were there when we looked again an hour later. Nothing had been deleted.

A negative from a narrow instrument is not evidence. The check classifies each project before believing an absence, treats a recently written repository as mid-copy, and reports both cases as unknown rather than as a pass or a failure. That honesty has a price. On the run we made while writing this, it checked 134 pins, and for 73 of them it can say that they resolve now but not how close the floor is: 47 behind a pull-through cache and 26 on a mirror.

And it is still run by hand. The one live pin it reports as a push away from the floor is the same pin it reported eighteen days earlier. A check for a failure whose whole problem is that it is silent for weeks does not do its job when somebody remembers to run it. Putting it on a schedule is the part we have not finished.

The rule#

If you pin an artifact in a registry that deletes old artifacts, you have set a deadline, and nothing in your repository, your pipeline or your cluster will tell you when it passes. Only the registry knows. Ask it, on a schedule, how many pushes each pin has left. Wherever it cannot tell you, make it say that rather than pass.

And when you write down a trap like this one, file it under what the next person will see when it fires. We had the right sentence a month early, and it did nothing for us.