Plain migration Job
- Deciders: David Bauer, Julian Bäume
- Date: 2026-06-12
Status
Accepted
Context
A Kubernetes Job runs node src/migrate.ts to apply pending Umzug migrations before (or alongside) a rollout. The natural first design is a Helm pre-install,pre-upgrade hook, with the database credentials Secret co-hooked at a negative weight so the Job can mount it before the main Deployment exists.
In production this hook-based design causes real problems: upgrades delete the Secret on the regular→hook transition and recreate it at the start of every subsequent upgrade (any Pod restarting in that gap fails to mount it), and both resources drop out of helm diff/drift detection while they're hooks. A post-* hook doesn't fix this either: operators deploy with --atomic --wait, so the Deployment must become Ready before any post-hook fires - but Pods can't become Ready until the migration has run, so the post-hook never gets a chance to run. Tying the Job's name to .Release.Revision to force a fresh Job per deploy was considered and rejected too: under ArgoCD, helm template always pins Release.Revision to 1, so the suffix would never rotate between syncs, and ArgoCD would try to patch the immutable Job.spec.template in place and fail.
Decision
Run the migration Job as a plain regular-resource Job, not a Helm hook, with its metadata.name rotated via a sha256-truncated suffix derived from a caller-provided migration.jobId, falling back to .Release.Revision when unset:
{{- $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 "-" }}The database credentials Secret drops its hook annotations entirely. CI sets migration.jobId to CI_JOB_ID, so a pipeline retry re-runs the migration even when nothing else changed (dev/preview databases run on ephemeral storage and lose schema on Pod restart, per ADR-0008). ArgoCD callers must set migration.jobId explicitly, since Release.Revision is pinned to 1 under helm template and would otherwise never rotate.
Consequences
Positive
- No regular↔hook transitions;
helm diffand drift detection see the Secret and Job like any other resource, at all times. --atomic --waitbehaves consistently: Helm waits for both Deployment readiness and Job completion, and a failed migration triggers a clean--atomicrollback.- One code path handles both first install and every subsequent upgrade.
Negative
- The Job and the Deployment apply concurrently, so new Pods briefly
CrashLoopBackOffagainst the SDK's pending-migrations startup guard until the Job completes; old Pods keep serving via the rolling update in the meantime, so this is not user-visible. - Migration failures now surface after the Deployment has already been applied, rather than before touching it as the pre-hook design did;
--atomicrecovers cleanly, but an operator watching mid-deploy briefly sees a degraded Deployment.
Alternatives considered
resource-policy: keepbridge release to repair the regular→hook transition once: leaves the recreation window, drift blindness, and--atomicdeadlock unresolved for every subsequent upgrade.- Asymmetric
pre-upgrade+post-install: works for upgrades under--atomic, but deadlocks on first install for the same readiness-ordering reason plainpost-*does. - Init container that polls for pending migrations: pays a per-Pod-lifecycle tax for the life of the chart, and interacts poorly with Istio (the init container runs before the
istio-proxysidecar is ready). Trades a transient, well-understood deploy symptom for permanent infrastructure cost. image.tagas the rotation suffix: rejected - stable tags freeze the suffix and blockRelease.Revisionfrom ever rotating it; volatile tags rotate viaRelease.Revisionanyway, so this adds no benefit over the two-tierjobId/Release.Revisionscheme actually adopted.
References
helm/booking/templates/migrate-job.yaml- ADR-0008 (why
jobIdmatters for ephemeral preview databases)

