Skip to content

Harbor Post-upgrade Smoke Check and Rollback

A failed Harbor upgrade is rolled back by an in-cluster Job, with no person and no Git change. The Job restores the backup the upgrade gate took of the old version, pins the old chart and starts it. This is Renovate architecture §11 item 4, built as for Gitea. Helm's own rollback is not enough: Harbor's core migrates the database one way on start, and harbor-db upgrades PostgreSQL in place and deletes the old data directory.

Every node pulls platform images from Harbor, so the rollback pulls nothing from Harbor. Its images come from Docker Hub. The database image it restores with is the backup's goharbor/harbor-db, which the nodes ran until the upgrade. Unlike Gitea's rollback, it needs no Flux source switch: Flux's source is Gitea, not Harbor.

Everything lives in components/harbor/rollback/ and is applied by the Flux Kustomization harbor-postupgrade (cluster/hetzner-mgmt/harbor/kustomization.yaml). The scripts, smoke.py and the pod templates are in components/harbor/backup/, in the gate's ConfigMap harbor-backup-scripts.

The flow

Renovate PR merged (chart.spec.version and both TARGET_VERSIONs bumped)
  └─▶ harbor-preupgrade: backs up the old version, writes latest.env
        ├─▶ harbor: HelmRelease upgrade (Helm rollback as remediation)
        └─▶ harbor-postupgrade: Job harbor-smoke, recreated for the new TARGET_VERSION
              ├─ Ready on TARGET_VERSION, healthy, the smoke image pulls, within 45m ─▶ collation check
              │     ├─ every database's collation version unchanged ─▶ pass
              │     └─ changed ─▶ fail, no rollback ─▶ Taskbase task: reindex (see below)
              └─ not ─▶ resume Job harbor-rollback, fail
                    ├─▶ harbor-postupgrade not Ready ─▶ Flux alert ─▶ Taskbase task: revert the chart in Git
                    └─▶ harbor-rollback: guard ▸ hold ▸ pin old chart, writers at 0 ▸ restore ▸ writers back ▸ check

The smoke check

The Job harbor/harbor-smoke runs smoke.py upgrade <TARGET_VERSION>. Harbor passes when all three hold:

  • the HelmRelease harbor is Ready at its current generation, and its latest Helm release is deployed on chart TARGET_VERSION. When Helm's remediation has rolled the chart back, this fails: the old core may now run on a database the new one migrated, or on an empty one;
  • GET /api/v2.0/health on http://harbor.harbor.svc reports every component healthy. It answers 200 either way, so the check reads each component's status;
  • the smoke artifact the gate recorded pulls, with every blob matching its digest. The init container fetch-latest reads it from latest.env. The pull runs only when that file's TARGET_VERSION equals the Job's, i.e. this upgrade's gate wrote it. If the store cannot be read, the check runs without the pull and says so, rather than roll back over a store outage.

It retries every 15 seconds for 45 minutes. That covers the lag from the gate to the upgrade, the HelmRelease's upgrade and its remediation, each with the HelmRelease's spec.timeout of 15 minutes. Helm's default of 5 minutes was too short for an upgrade that restarts harbor-database (#2274).

When the upgrade fails after the new core has migrated the database, Helm's remediation rollback cannot start the old core (no migration found for version N). helm-controller then repeats the rollback until this check gives up. If the new version was only slow, roll forward before that happens: see Harbor: Helm rollback fails with no migration found for version N in the ops runbook.

The Job carries TARGET_VERSION and kustomize.toolkit.fluxcd.io/force: Enabled, like the gate. TARGET_VERSION must equal chart.spec.version in components/harbor/base/helmrelease.yaml and TARGET_VERSION in components/harbor/backup/job.yaml. All three are in Renovate's harbor group.

harbor-postupgrade dependsOn harbor-preupgrade, not harbor: a broken upgrade leaves harbor not Ready, and Flux applies a Kustomization only after its dependencies are Ready (Flux: Dependencies).

On failure the smoke Job resumes harbor-rollback (spec.suspend: false) and fails. The failed Job fails harbor-postupgrade, and the Flux alert taskbase-platform turns that into a Taskbase task (Failure alerts to Taskbase). That task is the follow-up: unless the Job's log ends with the collation check, revert the upgrade commit, so chart.spec.version and both TARGET_VERSIONs are back at CHART_VERSION from latest.env (also on the hold's annotation), and record what failed.

The collation check

After a PostgreSQL major, which harbor-db runs in place with pg_upgrade, or a new C library in its image, a database's collation can sort text differently. Its indexes on text are then wrong, and robot permissions and lists misbehave (found in the upgrade to chart 1.19.2). Once smoke.py has passed (it is an init container), the Job's container collation runs collation.sh (in components/harbor/backup/scripts/) with a PostgreSQL client against harbor-database, as postgres. It only reads:

SELECT datname, datcollversion, pg_database_collation_actual_version(oid) FROM pg_database WHERE datallowconn

It logs every database's recorded and actual version. When a recorded version differs from the actual one, it fails the Job without starting a rollback: Harbor passed, and a reindex fixes the indexes, which a restore would not. As in PostgreSQL itself, a database with no recorded version (a C or POSIX collation) is not compared. The failure fails harbor-postupgrade, and the Flux alert raises the Taskbase task. Its remedy, which the log also prints with the databases' names:

kubectl --context admin@mgmt-cluster -n harbor exec harbor-database-0 -c database -- reindexdb -U postgres --all
kubectl --context admin@mgmt-cluster -n harbor exec harbor-database-0 -c database -- psql -U postgres -c 'ALTER DATABASE <db> REFRESH COLLATION VERSION'   # each database it names
kubectl --context admin@mgmt-cluster -n harbor delete job harbor-smoke && flux --context admin@mgmt-cluster reconcile kustomization harbor-postupgrade   # runs the whole check again

Do not revert the upgrade for a collation mismatch.

The client is the postgres image, and its major may differ from the one harbor-db runs. The query reads only catalog columns and a function that both run on the server (PostgreSQL 15 and later), and psql works with older servers. Unlike the pg_dump in Gitea's backup pods, it needs no Renovate cap. Any change to this image changes harbor-smoke's pod template, so the merge recreates the Job and runs the whole check against the running Harbor. That run is the new image's first test: no drill runs this container. If Harbor does not pass smoke within its deadline, the Job starts harbor-rollback, so merge such a change only while Harbor is healthy.

If the collation image cannot be pulled, no rollback starts: smoke has already passed, and the container waits in ImagePullBackOff until the Job's activeDeadlineSeconds (1 hour) fails it. harbor-postupgrade then fails with timeout waiting for: [Job/harbor/harbor-smoke status: 'InProgress']. Before merging a new tag, check that its index lists a linux/amd64 image. Docker Hub published every postgres:19* tag with an empty index on 2026-11-20, so postgres:19.0-alpine failed with no match for platform in manifest and was reverted to 18.7 (incident report).

The rollback Job

harbor/harbor-rollback is deployed suspended, with kustomize.toolkit.fluxcd.io/ssa: IfNotPresent, for the reasons given for Gitea. Its steps run in order:

  1. fetch-latest: reads <cluster>/harbor/latest.env from the store: prefix, chart version, database image, the target the gate backed up before, and the smoke artifact.
  2. guard: refuses, before anything changes, when the backup is not this upgrade's. Its TARGET_VERSION must equal the HelmRelease's chart.spec.version, and the backup must be newer than the start of the harbor-preupgrade Job.
  3. restore (rollback.sh restore):
    • Hold. Suspends the harbor Flux Kustomization and annotates it with platform.skatzi.com/harbor-rollback-pin: <old chart version>, then suspends the HelmRelease. It then waits until Helm has no action in flight. Writes use the field manager harbor-rollback.
    • Pin the old chart, writers at 0. One patch sets chart.spec.version to the backup's and core, jobservice and registry replicas to 0, and clears suspend. Once the HelmRelease is Ready, harbor-database must run the backup's image (DB_IMAGE), or the Job stops. The order matters. A restore into the new database image would be lost: the old image starts on a data directory the new one has upgraded by creating an empty cluster beside it.
    • Restore, in the pod harbor-rollback-restore (templates/rollback-pod.yaml): the same steps as the restore check. The database being replaced is kept as registry_replaced_<stamp>. The blobs are laid out on the pod's work volume and checked as in the restore check, then restore-registry (registry-s3.sh restore, rclone sync --checksum --backup-dir) makes registry/docker/ in the bucket equal to them. Every object it replaces or removes, such as a blob pushed after the gate or a tag link the failed version moved, moves to rollback-aside/<stamp>/docker/ in the same bucket, outside the registry's root directory; rclone check then compares the bucket with the backup. The bucket, endpoint, region and root directory come from the HelmRelease's values; unless the storage type is s3, the step stops before the hold.
    • Writers back. A second patch puts replicas back to what Git sets (null where Git sets nothing, so the chart default applies). It then waits for the HelmRelease and harbor-core. The harbor Kustomization stays suspended: that is the pin.
  4. check: smoke.py check against the restored Harbor, with the smoke artifact from latest.env. A failing check fails the Job; the restore itself is done by then.

The hold, and how it ends

While the harbor Kustomization is suspended, nothing in Git reaches Harbor's HelmRelease. The hold ends when Git carries the pinned chart again. The follow-up's revert changes TARGET_VERSION, so the gate runs again. Harbor already runs that chart, so it passes without a backup, and latest.env keeps naming the backup that was restored. Then harbor-smoke is recreated. It finds the pin equal to its TARGET_VERSION, removes the annotation and the suspension, and checks Harbor as usual. When the check passes, it deletes the finished harbor-rollback Job, and Flux recreates it suspended within one interval (10 minutes).

If Git moves to yet another chart while the hold is in place, harbor-smoke fails with Harbor is held at chart <version> by harbor-rollback and starts no rollback. Revert to the pinned chart first.

Data

  • Lost: pushes and deletes between the gate's dump and the upgrade. The failed state that holds them is kept.
  • Kept until a person removes them: the database registry_replaced_<stamp> in harbor-database, and the failed blob store's replaced objects under rollback-aside/<stamp>/ in the bucket skatzi-harbor-registry. When the upgrade had brought a new PostgreSQL major, the migrated cluster also stays on harbor-database-pvc, as pgdata/pg<new major> next to the restored one. Remove them once the follow-up has been merged:

    kubectl --context admin@mgmt-cluster -n harbor exec harbor-database-0 -- psql -U postgres -c 'DROP DATABASE registry_replaced_<stamp>'
    rclone purge registry:skatzi-harbor-registry/rollback-aside/<stamp>   # with the harbor-registry-s3 keys, configured as in registry-s3.sh
    kubectl --context admin@mgmt-cluster -n harbor exec harbor-database-0 -- rm -rf /var/lib/postgresql/data/pgdata/pg<new major>   # only after a major change
    

RBAC

Account Where Can
harbor-smoke harbor get the HelmRelease harbor; get, patch and delete the Job harbor-rollback (start or remove it, not alter its pods)
harbor-smoke flux-system get and patch the Kustomization harbor (to lift the hold)
harbor-rollback harbor get/patch the HelmRelease harbor; read harbor-database and harbor-core; read the Job harbor-preupgrade; create, read and delete pods and read their logs
harbor-rollback flux-system get/patch the Kustomization harbor
harbor-preupgrade harbor read and scale core, jobservice and registry; read harbor-database and the HelmRelease; create, read and delete pods and PVCs
harbor-preupgrade, harbor-restore-drill harbor-scratch create, change and delete the chart's kinds (pods, services, ConfigMaps, Secrets, PVCs, Deployments, StatefulSets) there: the scratch copy

Checking it on the cluster

kubectl --context admin@mgmt-cluster -n harbor get job harbor-smoke harbor-rollback   # smoke Complete; rollback suspended, 0 pods
kubectl --context admin@mgmt-cluster -n harbor logs job/harbor-smoke --all-containers
kubectl --context admin@mgmt-cluster -n harbor logs job/harbor-rollback --all-containers --prefix   # after a rollback
kubectl --context admin@mgmt-cluster -n flux-system get kustomization harbor \
  -o jsonpath='{.spec.suspend} {.metadata.annotations.platform\.skatzi\.com/harbor-rollback-pin}'   # the hold

A rollback that is not suspended and not running has already run. Until that Job is deleted, a failed smoke check starts no rollback and says so. To re-arm it: kubectl --context admin@mgmt-cluster -n harbor delete job harbor-rollback && flux --context admin@mgmt-cluster reconcile kustomization harbor-postupgrade.

To test the smoke check's and the collation check's logic: python3 -m unittest discover -s components/harbor/backup/scripts -p 'test_*.py'.

Manual fallback

When harbor-rollback refuses or fails, its log names the step:

  • guard refused: nothing has changed. Decide which backup to restore, then follow the manual restore.
  • restore failed before the restore pod: the hold is in place. If the HelmRelease is on the old chart with the writers at 0, continue with step 3 of the manual restore, otherwise with step 2.
  • The restore pod failed: before restore-db nothing has changed. After it, the replaced database is registry_replaced_<stamp>; until restore-registry started, the bucket is unchanged; after it, the objects it replaced or removed are under rollback-aside/<stamp>/ in the bucket. Finish the manual restore from the same PREFIX.
  • Writers back or check failed: the data is restored. Fix what the log names and finish with step 5 of the manual restore.

In every case, leave the harbor Kustomization suspended until Git carries the restored chart version. Then let harbor-smoke lift the hold, or lift it by hand:

kubectl --context admin@mgmt-cluster -n flux-system annotate kustomization harbor platform.skatzi.com/harbor-rollback-pin-
flux --context admin@mgmt-cluster resume kustomization harbor