Gitea Post-upgrade Smoke Check and Rollback¶
A failed Gitea 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 that version and starts it. This is Renovate architecture §11 item 4. Rolling back takes a restore because Gitea's database migrations run one way: Helm's own rollback starts the old image on a database the new version has already migrated, and the old version refuses to start on it.
Everything lives in components/gitea/rollback/ and is applied by the Flux Kustomization gitea-postupgrade (cluster/hetzner-mgmt/gitea/kustomization.yaml). The rollback's shell scripts and its pod templates are in components/gitea/backup/ next to the gate's, because they share the gate's ConfigMap gitea-backup-scripts.
The flow¶
Renovate PR merged (image.tag and both TARGET_VERSIONs bumped)
└─▶ gitea-preupgrade: backs up the old version, writes latest.env
├─▶ gitea: HelmRelease upgrade (15m timeout, Helm rollback as remediation)
└─▶ gitea-postupgrade: Job gitea-smoke, recreated for the new TARGET_VERSION
├─ Gitea reports TARGET_VERSION within 45m ─▶ pass
└─ it does not ─▶ resume Job gitea-rollback, fail
├─▶ gitea-postupgrade not Ready ─▶ Flux alert ─▶ Taskbase task: revert the version in Git
└─▶ gitea-rollback: guard ▸ source to GitHub ▸ hold ▸ restore ▸ pin ▸ resume ▸ source to Gitea
The smoke check¶
The Job gitea/gitea-smoke runs smoke.py upgrade <TARGET_VERSION>. It passes when GET /api/healthz answers 200 and GET /api/v1/version with the Gitea token reports TARGET_VERSION, both against the in-cluster service gitea-http:3000, so the gateway is not part of the check. The token is the push mirror's and the backup gate's: OpenBao ${cluster_name}/gitea/github-mirror, property gitea-token, synced to Secret gitea/gitea-token by this component. It retries every 15 seconds for 45 minutes. If Gitea refuses the token (HTTP 401 or 403), the check fails at once without starting gitea-rollback: Gitea answers, only the credential is wrong, and restoring the backup would not fix it. That covers the lag from the gate to the upgrade, the HelmRelease's 15-minute upgrade timeout and its remediation. A migration that needs longer fails the HelmRelease anyway.
The Job carries TARGET_VERSION and kustomize.toolkit.fluxcd.io/force: Enabled, like the gate. TARGET_VERSION must equal image.tag in components/gitea/base/helmrelease.yaml and TARGET_VERSION in components/gitea/backup/job.yaml. All three carry # renovate: datasource=docker depName=gitea/gitea, so Renovate's gitea group bumps them in one PR. A chart-only update does not recreate the Job. It has no data migration, and Helm's rollback covers it.
gitea-postupgrade dependsOn gitea-preupgrade, not gitea. A broken upgrade leaves gitea not Ready, and Flux applies a Kustomization only after its dependencies are Ready (Flux: Dependencies). A smoke check that depended on gitea would therefore never run in the case it exists for. It starts once the gate has passed, at the same time as the upgrade, and waits.
On any other failure the smoke Job resumes gitea-rollback (spec.suspend: false) and fails. The failed Job fails gitea-postupgrade, and the Flux alert taskbase-platform turns that into a Taskbase task in this repository (Failure alerts to Taskbase). That task is the follow-up: revert the whole upgrade commit, so that image.tag, both TARGET_VERSIONs and chart.spec.version in components/gitea/base/helmrelease.yaml are back at the versions before the upgrade (VERSION and CHART_VERSION in latest.env, also on the hold's annotations), and record in it what failed. Renovate's gitea group bumps the chart and the image in one PR; reverting only the image would bring back the new chart on the restored data. The failing gitea HelmRelease and Kustomization raise tasks for the same revision too.
The rollback Job¶
gitea/gitea-rollback is deployed suspended, with kustomize.toolkit.fluxcd.io/ssa: IfNotPresent: Flux creates it and never changes it. With the default policy, Flux would set suspend: true back on a running rollback, and suspending a Job deletes its running pods (Kubernetes: suspending a Job). Its steps run in order, as init containers. Each must succeed before the next starts:
fetch-latest: reads<cluster>/gitea/latest.envfrom the store: prefix, version, image, chart version and the target the gate backed up before.guard: refuses, before anything changes, when the backup is not this upgrade's. ItsTARGET_VERSIONmust equal the HelmRelease'simage.tag, and the backup must be newer than the start of thegitea-preupgradeJob. On a fresh cluster the gate has nothing to back up, andlatest.envstill names an older backup.fallback: switches Flux to the GitHub copy with the hold (switch-git-source.py bootstrap-cluster, see Flux: switching to the fallback and back). The script is read from thegit-source-switchConfigMap and runs with theconfigmap-patcherRole. A refused switch (a stale mirror) is logged and the restore goes on, because the restore needs no Flux source.restore(rollback.sh restore):- Hold. Suspends the
giteaFlux Kustomization and annotates it withplatform.skatzi.com/gitea-rollback-pin: <old version>andplatform.skatzi.com/gitea-rollback-pin-chart: <old chart version>, then suspends thegiteaHelmRelease. It then waits until Helm has no action in flight. Writes use the field managergitea-rollback: kustomize-controller keeps fields that Git does not set and another manager owns, unless that manager iskubectl(kustomize-controller source). - Stop. Scales
deployment/giteato 0 and waits for its pods to go. - Restore, in the pod
gitea-rollback-restore(templates/rollback-pod.yaml):fetchandunpackas in the restore check, including the checksums andgit fsck.prepare-dbrenames the failed database togitea_rollback_<stamp>and creates an emptygitea.restore-dbrunspg_restoreand checks the row counts.restore-filesmoves the failed/datato<stamp>/on the PVCgitea-rollback-asideand copies the backup intogitea-shared-storage. - Pin and resume. One patch to the HelmRelease sets
chart.spec.versionandvalues.image.tagto the backup's and clearssuspend. Once the HelmRelease is Ready at that generation, and only if the Deployment's image is the backup's version, it scales Gitea back up and waits for it to be ready. ThegiteaKustomization stays suspended: that is the pin. Without the pin, Flux would apply the failed version from Git again.
- Hold. Suspends the
switch-back: once Gitea reports the restored version, switches Flux back togitea-platformand clears the hold (--release).
The hold, and how it ends¶
While the gitea Kustomization is suspended, nothing in Git reaches Gitea's HelmRelease. gitea-act-runner and gitea-push-mirror wait too, because they depend on gitea. Their workloads keep running.
The hold ends when Git carries the pinned version again: the old image.tag and TARGET_VERSIONs and the old chart.spec.version. The follow-up's revert changes TARGET_VERSION, so the gate runs again. Gitea already runs that version, so it passes without a backup, and latest.env keeps naming the backup that was restored. Then gitea-smoke is recreated. It finds the pin annotation equal to its TARGET_VERSION, removes both annotations and the suspension, and checks Gitea as usual. It cannot see the chart version in Git, so it only names the pinned chart in its log: a revert that leaves the new chart lets Flux upgrade the chart under the old image on the restored data. When the check passes, it deletes the finished gitea-rollback Job, and Flux recreates it suspended within one interval (10 minutes), ready for the next upgrade.
If Git moves to yet another version while the hold is in place, gitea-smoke fails with Gitea is held at <version> (chart <chart version>) by gitea-rollback and starts no rollback. Revert to the pinned version first.
Data¶
- Lost: writes made between the gate's dump and the upgrade. The gate resumes Gitea after the dump, and the backup does not hold what was pushed after it. The failed state that holds them is kept.
-
Kept until a person removes them: the failed database
gitea_rollback_<stamp>ingitea-postgresql, and the failed/dataon the PVCgitea-rollback-aside. Remove them once the follow-up has been merged and nothing needs to be recovered from them:
RBAC¶
| Account | Where | Can |
|---|---|---|
gitea-smoke |
gitea |
get, patch and delete the Job gitea-rollback. A Job's pod template cannot be changed, so it can only start or remove the rollback, not alter it. |
gitea-smoke |
flux-system |
get and patch the Kustomization gitea (to lift the hold) |
gitea-rollback |
gitea |
get/patch the HelmRelease gitea; read and scale deployment/gitea; read the Job gitea-preupgrade; create, read and delete pods and read their logs; create and read PVCs |
gitea-rollback |
flux-system |
get/patch the Kustomization gitea; read the ConfigMap git-source-switch; the configmap-patcher Role that the source switch needs |
The rollback runs the switch script itself rather than creating Jobs from the git-source-fallback and git-source-restore templates. Creating Jobs in flux-system would let it run pods as Flux's controllers, which can change anything in the cluster.
Checking it on the cluster¶
kubectl --context admin@mgmt-cluster -n gitea get job gitea-smoke gitea-rollback # smoke Complete; rollback suspended, 0 pods
kubectl --context admin@mgmt-cluster -n gitea get job gitea-rollback -o jsonpath='{.spec.suspend}' # true
kubectl --context admin@mgmt-cluster -n gitea logs job/gitea-smoke
kubectl --context admin@mgmt-cluster -n gitea logs job/gitea-rollback --all-containers --prefix # after a rollback
kubectl --context admin@mgmt-cluster -n flux-system get kustomization gitea \
-o jsonpath='{.spec.suspend} {.metadata.annotations.platform\.skatzi\.com/gitea-rollback-pin} {.metadata.annotations.platform\.skatzi\.com/gitea-rollback-pin-chart}' # 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 in its log. If it ran but did not finish, restore by hand (below), then delete it: kubectl --context admin@mgmt-cluster -n gitea delete job gitea-rollback && flux --context admin@mgmt-cluster reconcile kustomization gitea-postupgrade.
To test the smoke check's logic: python3 -m unittest components/gitea/rollback/test_smoke.py.
Rehearsing it¶
A rehearsal restores a fresh backup of the running version onto the same version. Gitea is down for the gate's dumps and again for the restore, and anything written between the gate's dump and the restore is lost, so run it in a maintenance window. Wait until no Actions job is running or waiting (action_run_job.status 5 or 6 in Gitea's database) and no Renovate run is in progress, since Renovate's pushes start CI. Then:
- Force a backup of the running version:
kubectl --context admin@mgmt-cluster -n gitea annotate deployment gitea platform.skatzi.com/preupgrade-force=true, thenkubectl --context admin@mgmt-cluster -n gitea delete job gitea-preupgrade, and wait for Flux to rerun the gate (Forcing a backup). Without the annotation the gate passes without a backup, because Gitea already runsTARGET_VERSION. Itsgatelog starts withForced by the annotation …, itspublishlog printslatest.env, whosePREFIXstamp must be from this run, and the annotation is gone afterwards. kubectl --context admin@mgmt-cluster -n gitea patch job gitea-rollback --type merge -p '{"spec":{"suspend":false}}', and follow the log as above.- Once the Job has completed, lift the hold:
kubectl --context admin@mgmt-cluster -n gitea delete job gitea-smoke && flux --context admin@mgmt-cluster reconcile kustomization gitea-postupgrade. The smoke log shows the hold released and the rollback Job deleted. Reconcile again to have Flux recreategitea-rollbacksuspended now, rather than within the next interval. - Leave the aside copies to a person (see Data).
The first rehearsal, on hetzner-mgmt on 2026-11-01 (#1384), restored 1.27.3 onto 1.27.3 from 20261101T161223Z-1.27.3-to-1.27.3. The gate took 15 minutes, with Gitea down for 7 of them. The rollback Job took 9 minutes, with Gitea down for about 9. Every step logged what this page describes. Repository and user counts, and the highest Actions run, issue and comment IDs, were the same before and after. Helm made no new revision. Things that are expected:
- After each source switch, many Kustomizations show
dependency '…' is not readyfor a few minutes, because the switch requests a reconcile of every Kustomization influx-system. It clears on its own; it took about 7 minutes after the switch back. gitea-rollbackstays the field manager of the HelmRelease'sspec.suspend: falseafter the hold is lifted. Git does not set that field, and the value is the default.- A
github-push-mirrorrun during the restore waits for Gitea, then passes.
Manual fallback¶
When gitea-rollback refuses or fails, its log names the step. The state it leaves is safe to pick up by hand:
guardrefused: nothing has changed. Decide which backup to restore, then follow the manual restore.restorefailed before the restore pod: the hold is in place and Gitea may be scaled to 0. Continue with the manual restore. Its step 1 is already done.- The restore pod failed: its log, in the Job's log, names the step. Before
prepare-dbnothing has changed. After it, the failed database is kept asgitea_rollback_<stamp>, and afterrestore-filesstarted, the failed files are undergitea-rollback-aside. Finish the manual restore from the samePREFIX. -
Pin or resume failed: the data is restored. Patch the HelmRelease as
rollback.shdoes, withVERSIONandCHART_VERSIONfromlatest.env, then scale Gitea up:kubectl --context admin@mgmt-cluster -n gitea patch helmrelease gitea --type merge --field-manager=gitea-rollback -p \ '{"spec":{"suspend":false,"chart":{"spec":{"version":"<CHART_VERSION>"}},"values":{"image":{"tag":"<VERSION>"}}}}' kubectl --context admin@mgmt-cluster -n gitea scale deployment gitea --replicas=1 -
switch-backfailed: Gitea is restored, but Flux is still on GitHub with the hold. Rungit-source-restoreonce Gitea is healthy (Flux: switching to the fallback and back).
In every case, leave the gitea Kustomization suspended until Git carries the restored image and chart versions. Then either let gitea-smoke lift the hold, or lift it by hand: