Run database migration via a plain Job with a content-rotated name
- Deciders: Maik Schäfer, Julian Bäume
- Date: 2026-05-20
Status
Accepted (supersedes 0019)
Context
The migrate Job was previously a pre-install,pre-upgrade Helm hook, with the chart-managed DB Secret co-hooked at weight -10 so the Job could mount it. In production this design caused upgrades to delete the Secret on the regular→hook transition, recreate it at the start of every subsequent upgrade (any Pod restarting in the gap fails to mount), and dropped both resources out of helm diff / drift detection. A post-* revert wasn't viable either: ops deploys with --atomic --wait, the Deployment must become Ready before any post-hook fires, and Pods can't become Ready until the migration runs — so the post-hook never gets to run.
Tying the Job name to .Release.Revision was considered but rejected: under Argo CD helm template pins it to 1, so the suffix would never rotate between syncs and Argo would try to patch the immutable Job.spec.template.
Decision
Use a plain regular-resource Job. Rotate its metadata.name via a sha256-truncated suffix derived from migration.jobId (caller-provided), or fall back to .Release.Revision when unset. Drop hook annotations from the DB Secret.
{{- $ident := .Values.migration.jobId | default (.Release.Revision | toString) }}
{{- $suffix := $ident | toString | sha256sum | trunc 8 }}
name: {{ printf "%s-migrate-%s" (include "ox-common.names.fullname" .) $suffix | trunc 63 | trimSuffix "-" }}CI sets migration.jobId to CI_JOB_ID so a pipeline retry re-runs the migration even when nothing else has changed (dev databases run on ephemeral storage and lose schema on Pod restart). Argo callers set it explicitly, since Release.Revision is pinned to 1 under helm template (see Context).
Consequences
Positive
- No regular↔hook transitions;
helm diffand drift detection see the Secret and Job again. --atomic --waitis consistent: Helm waits for both Deployment readiness and JobComplete; a failed migration triggers--atomicrollback.- Single code path for first install and upgrades.
Negative
- The Job and Deployment apply concurrently, so new Pods briefly CrashLoopBackOff against
checkPendingMigrationsuntil the Job finishes. Old Pods continue serving via the rolling update; no user-visible impact. - Migration failures surface after the Deployment is applied (vs. the pre-hook design which failed before touching it).
--atomicrecovers cleanly; mid-deploy operators briefly see a degraded Deployment.
Alternatives Considered
resource-policy: keepbridge release to repair the regular→hook transition: leaves the recreation window, drift blindness, and--atomicdeadlock untouched.- Asymmetric
pre-upgrade+post-install: works for upgrades under--atomic, deadlocks on first install for the same reasonpost-*does. - Init container that polls for migrations: pays per-Pod-lifecycle tax on every restart for the chart's lifetime, interacts poorly with Istio (init runs before
istio-proxyis ready). Trades a transient deploy symptom for permanent infrastructure. image.tagas an intermediate fallback for the suffix: stable tags would freeze it and blockRelease.Revisionfrom rotating; volatile tags rotate viaRelease.Revisionanyway. No gain over the two-tier scheme.
References
- Cross-chart counterpart: switchboard ADR 0008, core-ui MR !6551
- Superseded ADR: 0019
- Superseded commit:
727d323

