Skip to content

Commit b20e934

Browse files
committed
test(platform): enforce go-forward version stamps route through the helper
The helper header and run-migrations.sh claimed every migration-driven stamp routes through the helper, but migrations 1-41 still stamp the cozystack-version ConfigMap label-less and are backfilled by migration 42. Scope the comments to go-forward stamps (migration 42 onward and the bootstrap path), and add a unittest asserting no migration numbered >= 42 nor run-migrations.sh stamps cozystack-version without the helper, so the no-drift invariant is enforced rather than aspirational. Assisted-By: Claude <[email protected]> Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent 3117d02 commit b20e934

3 files changed

Lines changed: 33 additions & 4 deletions

File tree

‎hack/cozystack-version-stamp.bats‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,25 @@ EOF
103103
exit 1
104104
fi
105105
}
106+
107+
@test "no go-forward stamp bypasses the helper (migrations >= 42 and run-migrations.sh)" {
108+
# The helper exists so go-forward stamps cannot drift back to a label-less
109+
# 'kubectl create configmap cozystack-version' (which drops the no-delete
110+
# label). Migrations 1-41 are frozen and backfilled by 42, so they are
111+
# exempt; migration 42 onward and the bootstrap path must use the helper.
112+
mig_dir=packages/core/platform/images/migrations/migrations
113+
for f in "$mig_dir"/*; do
114+
n=$(basename "$f")
115+
case "$n" in *[!0-9]*) continue ;; esac # skip lib/ and other non-numeric
116+
[ "$n" -ge 42 ] || continue
117+
if grep -Eq 'create configmap.*cozystack-version' "$f"; then
118+
echo "migration $n stamps cozystack-version without the helper" >&2
119+
exit 1
120+
fi
121+
done
122+
if grep -Eq 'create configmap.*cozystack-version' \
123+
packages/core/platform/images/migrations/run-migrations.sh; then
124+
echo "run-migrations.sh stamps cozystack-version without the helper" >&2
125+
exit 1
126+
fi
127+
}

‎packages/core/platform/images/migrations/migrations/lib/cozystack-version.sh‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@
1010
# stamp must re-emit the label by hand.
1111
#
1212
# Centralizing the manifest here means migration 45+ cannot drift back to a
13-
# label-less apply: each migration sources this file and calls the helper
14-
# instead of copy-pasting a heredoc.
13+
# label-less apply: every go-forward stamp (migration 42 onward and the
14+
# bootstrap path in run-migrations.sh) sources this file and calls the helper
15+
# instead of copy-pasting a heredoc. Migrations 1-41 predate the no-delete
16+
# label and stamp label-less on purpose; migration 42 backfills the label on
17+
# any upgrade path through them, so they are left frozen. The
18+
# cozystack-version-stamp.bats suite pins this — no migration numbered >= 42
19+
# (nor run-migrations.sh) may stamp cozystack-version without the helper.
1520
#
16-
# Sourced, not executed. Each migrations/<N> script does:
21+
# Sourced, not executed. Each migrations/<N> script (42+) does:
1722
# . "$(dirname "$0")/lib/cozystack-version.sh"
1823
# and run-migrations.sh sources /migrations/lib/cozystack-version.sh.
1924

‎packages/core/platform/images/migrations/run-migrations.sh‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ echo "Starting migrations from version $CURRENT_VERSION to $TARGET_VERSION"
1414
if ! kubectl get configmap --namespace "$NAMESPACE" cozystack-version >/dev/null 2>&1; then
1515
echo "ConfigMap cozystack-version does not exist, creating it with version $TARGET_VERSION"
1616
# Stamp via the shared helper so the bootstrap ConfigMap carries the
17-
# platform.cozystack.io/no-delete label like every migration-driven stamp.
17+
# platform.cozystack.io/no-delete label, matching every go-forward stamp
18+
# (migration 42 onward; migrations 1-41 stamp label-less and are backfilled
19+
# by migration 42, so they are intentionally left as-is).
1820
stamp_cozystack_version "$TARGET_VERSION"
1921
echo "ConfigMap created with version $TARGET_VERSION"
2022
exit 0

0 commit comments

Comments
 (0)