Files
cozystack/hack/testdata/run-migrations/migration
Aleksei Sviridkin 3a07885b70 fix(platform): resume a retried migration Job from the stamped version
The migration hook Job gets CURRENT_VERSION once, at render time, and a
failed pod is retried with that same environment. Each migration that
finished has stamped the cozystack-version ConfigMap by then, yet the
retry started from the rendered version and ran those migrations again.
Migrations are written to run once, so a re-run is not safe in general.

The runner now starts from the version stamped in the ConfigMap. A
failed read aborts the pod, since falling back would bring the re-run
back and the Job retries anyway. The rendered value is kept only when
the ConfigMap holds no integer version, which is also the case where
the chart could not derive a real one from it. An all-digit stamp past
the shell's integer range aborts too: its comparison fails inside an
if, out of reach of set -e, and the Job would go green having run
nothing, while the chart renders that stamp as 0.

Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
2026-10-02 21:54:46 +03:00

11 lines
394 B
Bash
Executable File

#!/bin/sh
# Stand-in for a platform migration, copied to /migrations/<n> by
# hack/run-migrations.bats: it records that it ran and stamps n+1 through the
# real helper, or fails before stamping when FAKE_FAIL_AT names it.
set -eu
. "$(dirname "$0")/lib/cozystack-version.sh"
n=$(basename "$0")
echo "$n" >> /work/ran
[ "${FAKE_FAIL_AT:-}" != "$n" ] || exit 1
stamp_cozystack_version $((n + 1))