Files
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

31 lines
1.2 KiB
Bash
Executable File

#!/bin/sh
# Fake kubectl for hack/run-migrations.bats. It serves the three calls
# run-migrations.sh and lib/cozystack-version.sh make against the
# cozystack-version ConfigMap, backed by a state file so a stamp made by one
# pod is what the next pod reads.
#
# FAKE_STATE file holding the stamped version; absent => no ConfigMap
# FAKE_READ_FAIL non-empty => reading .data.version exits 1 with this stderr
set -u
case "$*" in
*"apply --filename -"*)
v=$(sed -n 's/^ version: "\([0-9]*\)"$/\1/p')
[ -n "$v" ] || { echo "fake kubectl: no version in the applied manifest" >&2; exit 1; }
printf '%s' "$v" > "$FAKE_STATE"
;;
*"get configmap"*"cozystack-version"*"jsonpath"*)
if [ -n "${FAKE_READ_FAIL:-}" ]; then echo "$FAKE_READ_FAIL" >&2; exit 1; fi
[ -f "$FAKE_STATE" ] || { echo 'Error from server (NotFound): configmaps "cozystack-version" not found' >&2; exit 1; }
cat "$FAKE_STATE"
;;
*"get configmap"*"cozystack-version"*)
[ -f "$FAKE_STATE" ] || { echo 'Error from server (NotFound): configmaps "cozystack-version" not found' >&2; exit 1; }
echo "cozystack-version"
;;
*)
echo "fake kubectl: unexpected call: $*" >&2
exit 1
;;
esac