Skip to content

Commit 3117d02

Browse files
committed
fix(platform): guard stamp_cozystack_version against a missing version
Mirror render_cozystack_version_manifest's argument guard in stamp_cozystack_version so a missing version aborts before the kubectl pipe. Without it, a render failure in a shell without pipefail would leave the pipeline exit status to kubectl, which would apply empty input. Add a unittest covering the guard. Assisted-By: Claude <[email protected]> Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent 16b198c commit 3117d02

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

‎hack/cozystack-version-stamp.bats‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@
7070
fi
7171
}
7272

73+
@test "stamp_cozystack_version requires a version argument" {
74+
# The guard fires before the kubectl pipe, so this needs no cluster: a
75+
# missing version must abort rather than apply empty input to kubectl.
76+
. packages/core/platform/images/migrations/migrations/lib/cozystack-version.sh
77+
if ( stamp_cozystack_version ) 2>/dev/null; then
78+
echo "expected non-zero exit when version arg is missing" >&2
79+
exit 1
80+
fi
81+
}
82+
7383
@test "render output matches the canonical labeled manifest" {
7484
# Golden test: pins the exact bytes migrations 42/43/44 apply today, so the
7585
# refactor that routes them through this helper is provably manifest-stable.

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,8 @@ EOF
3939
# stamp_cozystack_version <version>
4040
# Render and apply the labeled manifest under the default kubectl field manager.
4141
stamp_cozystack_version() {
42+
# Guard the version here too, not only in render: without pipefail a render
43+
# failure would not abort the pipeline and kubectl would apply empty input.
44+
: "${1:?stamp_cozystack_version: version argument required}"
4245
render_cozystack_version_manifest "$1" | kubectl apply --filename -
4346
}

0 commit comments

Comments
 (0)