Skip to content

Commit 7215e98

Browse files
test(platform): cover every group snapshot CRD and a failed migration record
Pin the v1beta2 storage version on all three group snapshot CRDs, not only volumegroupsnapshots, so a chart update that changes the class or content CRD fails the suite. Migration 61 must stamp the version even when it cannot write its diagnostic record, and the suite now drives that path. Assisted-by: LLM Signed-off-by: Mattia Eleuteri <[email protected]>
1 parent 3310870 commit 7215e98

3 files changed

Lines changed: 56 additions & 2 deletions

File tree

‎hack/migration-61-snapshot-crds.bats‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ run_migration() {
4242
-e NAMESPACE="${NAMESPACE-}" \
4343
-e FAKE_CRD_FAIL="${FAKE_CRD_FAIL-}" \
4444
-e FAKE_DELETE_FAIL="${FAKE_DELETE_FAIL-}" \
45+
-e FAKE_RECORD_FAIL="${FAKE_RECORD_FAIL-}" \
4546
"$TESTIMG" "/migrations/$1" || _run_migration_rc=$?
4647
return "$_run_migration_rc"
4748
}
@@ -65,7 +66,7 @@ DOCKERFILE
6566
FAKE_CMDLOG="$WORK/cmdlog"
6667
: > "$FAKE_CMDLOG"
6768
export NAMESPACE=cozy-system
68-
unset FAKE_CRD_FAIL FAKE_DELETE_FAIL || true
69+
unset FAKE_CRD_FAIL FAKE_DELETE_FAIL FAKE_RECORD_FAIL || true
6970
return 0
7071
}
7172

@@ -133,6 +134,20 @@ crd_field() {
133134
rm -rf "$WORK"
134135
}
135136

137+
@test "a failed record of the kept CRDs still stamps the version" {
138+
prep
139+
echo '{"volumegroupsnapshots.groupsnapshot.storage.k8s.io": 2}' > "$WORK/state/objects.json"
140+
export FAKE_RECORD_FAIL="Error from server (InternalError): etcdserver: request timed out"
141+
rc=0
142+
run_migration 61 >"$WORK/out" 2>&1 || rc=$?
143+
cat "$WORK/out"; cat "$FAKE_CMDLOG"
144+
[ "$rc" -eq 0 ]
145+
grep -qF "failed to record the CRDs needing attention" "$WORK/out"
146+
if grep -qF "RECORD" "$FAKE_CMDLOG"; then echo "the failed record was logged as written" >&2; return 1; fi
147+
grep -qxF "STAMP 62" "$FAKE_CMDLOG"
148+
rm -rf "$WORK"
149+
}
150+
136151
@test "CRDs the release did not install are left alone" {
137152
prep
138153
edit_crds '.items |= map(.metadata.labels = {})'

‎hack/testdata/migration-61-snapshot-crds/kubectl‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# FAKE_STATE directory holding crds.json and objects.json
1313
# FAKE_CRD_FAIL non-empty => reading a CRD exits 1 with this stderr
1414
# FAKE_DELETE_FAIL non-empty => deleting a CRD exits 1 with this stderr
15+
# FAKE_RECORD_FAIL non-empty => annotating cozystack-version exits 1 with this stderr
1516
set -u
1617

1718
log() { [ -n "${FAKE_CMDLOG:-}" ] && printf '%s\n' "$*" >> "$FAKE_CMDLOG"; }
@@ -75,6 +76,7 @@ case "$*" in
7576
;;
7677

7778
"annotate configmap "*)
79+
if [ -n "${FAKE_RECORD_FAIL:-}" ]; then printf '%s\n' "$FAKE_RECORD_FAIL" >&2; exit 1; fi
7880
log "RECORD $*"
7981
exit 0
8082
;;

‎packages/system/snapshot-controller/tests/crds_test.yaml‎

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ tests:
2020
path: metadata.annotations["helm.sh/resource-policy"]
2121
value: keep
2222

23-
- it: the group snapshot CRDs store v1beta2
23+
- it: volumegroupsnapshots serves v1beta2 and no longer v1alpha1
2424
template: charts/snapshot-controller/templates/crds.yaml
2525
documentSelector:
2626
path: metadata.name
@@ -30,6 +30,43 @@ tests:
3030
path: spec.versions
3131
content:
3232
name: v1beta2
33+
storage: true
34+
any: true
35+
- notContains:
36+
path: spec.versions
37+
content:
38+
name: v1alpha1
39+
any: true
40+
41+
- it: volumegroupsnapshotcontents serves v1beta2 and no longer v1alpha1
42+
template: charts/snapshot-controller/templates/crds.yaml
43+
documentSelector:
44+
path: metadata.name
45+
value: volumegroupsnapshotcontents.groupsnapshot.storage.k8s.io
46+
asserts:
47+
- contains:
48+
path: spec.versions
49+
content:
50+
name: v1beta2
51+
storage: true
52+
any: true
53+
- notContains:
54+
path: spec.versions
55+
content:
56+
name: v1alpha1
57+
any: true
58+
59+
- it: volumegroupsnapshotclasses serves v1beta2 and no longer v1alpha1
60+
template: charts/snapshot-controller/templates/crds.yaml
61+
documentSelector:
62+
path: metadata.name
63+
value: volumegroupsnapshotclasses.groupsnapshot.storage.k8s.io
64+
asserts:
65+
- contains:
66+
path: spec.versions
67+
content:
68+
name: v1beta2
69+
storage: true
3370
any: true
3471
- notContains:
3572
path: spec.versions

0 commit comments

Comments
 (0)