Skip to content

Commit 1891652

Browse files
committed
test(e2e): fail the isp-hosted no-Cilium check on any cilium.io CRD
The check looked for one CRD by name, so a cluster carrying only part of Cilium's CRDs passed as a cluster without Cilium. It also needs a CRD list it could actually read: piping a failed list into the count read as zero CRDs and passed. Assisted-by: LLM Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent cd28e9d commit 1891652

2 files changed

Lines changed: 57 additions & 2 deletions

File tree

‎hack/e2e-install-cozystack-hosted.bats‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,15 @@
6868
# The variant's promise is that nothing in it needs Cilium or a
6969
# Cozystack-provided StorageClass. A green install proves that only if those
7070
# were really absent while it converged.
71-
if kubectl get crd ciliumnetworkpolicies.cilium.io >/dev/null 2>&1; then
72-
echo "Cilium CRDs are installed; the lane no longer tests a cluster without them" >&2
71+
# Any CRD in the group counts, not only the policy kinds. The premise is a
72+
# cluster with no Cilium at all, and a partial set breaks it even where the
73+
# tenant guard, which needs both policy kinds, would still skip its policies.
74+
# Read before counting, so a failed list fails the test instead of counting
75+
# as zero.
76+
crd_groups="$(kubectl get crd -o jsonpath='{range .items[*]}{.spec.group}{"\n"}{end}')"
77+
cilium_crds="$(printf '%s\n' "$crd_groups" | grep -cx 'cilium\.io' || true)"
78+
if [ "$cilium_crds" -ne 0 ]; then
79+
echo "$cilium_crds cilium.io CRDs are installed; the lane no longer tests a cluster without them" >&2
7380
exit 1
7481
fi
7582
for sc in replicated local; do

‎hack/isp-hosted-lane_test.bats‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,51 @@ TESTING_MAKEFILE="$REPO_ROOT/packages/core/testing/Makefile"
6767
grep -Eq '^[[:space:]]+KIND_NODE_IMAGE: "?kindest/node:v[0-9.]+@sha256:[0-9a-f]{64}"?$' "$WORKFLOW"
6868
grep -Fq 'sha256sum --check' "$WORKFLOW"
6969
}
70+
71+
# Runs the install suite's no-Cilium check against a stubbed kubectl. The copy
72+
# drops the e2e- prefix so hack/cozytest.sh arms no cluster captures, which
73+
# would otherwise run the stub as if it were a cluster.
74+
@test "the suite's no-Cilium check fails on any cilium.io CRD, not only CiliumNetworkPolicy" {
75+
tmp="$(mktemp -d)"
76+
mkdir -p "$tmp/bin"
77+
cp "$INSTALL" "$tmp/hosted.bats"
78+
printf '%s\n' \
79+
'#!/bin/sh' \
80+
'[ "$1 $2" = "get storageclass" ] && exit 1' \
81+
'[ "$1 $2" = "get crd" ] || exit 2' \
82+
'shift 2' \
83+
'[ -n "$FAKE_LIST_FAILS" ] && exit 1' \
84+
'case "$*" in' \
85+
' "-o name") for n in $FAKE_CRDS; do echo "customresourcedefinition.apiextensions.k8s.io/$n"; done ;;' \
86+
' -o\ jsonpath=*) for n in $FAKE_CRDS; do echo "${n#*.}"; done ;;' \
87+
' -*) exit 2 ;;' \
88+
' *) for n in $FAKE_CRDS; do [ "$n" = "$1" ] && exit 0; done; exit 1 ;;' \
89+
'esac' > "$tmp/bin/kubectl"
90+
chmod +x "$tmp/bin/kubectl"
91+
92+
rc=0
93+
PATH="$tmp/bin:$PATH" FAKE_CRDS="packages.cozystack.io ciliumendpoints.cilium.io" COZY_REPORT_DIR="$tmp/report" COZYTEST_TRACE=0 \
94+
"$REPO_ROOT/hack/cozytest.sh" "$tmp/hosted.bats" "The cluster carries none" > "$tmp/partial.log" 2>&1 || rc=$?
95+
if [ "$rc" -eq 0 ]; then
96+
echo "the check passed with ciliumendpoints.cilium.io installed" >&2
97+
exit 1
98+
fi
99+
100+
rc=0
101+
PATH="$tmp/bin:$PATH" FAKE_CRDS="" FAKE_LIST_FAILS=1 COZY_REPORT_DIR="$tmp/report" COZYTEST_TRACE=0 \
102+
"$REPO_ROOT/hack/cozytest.sh" "$tmp/hosted.bats" "The cluster carries none" > "$tmp/unreadable.log" 2>&1 || rc=$?
103+
if [ "$rc" -eq 0 ]; then
104+
echo "the check passed although the CRD list could not be read" >&2
105+
exit 1
106+
fi
107+
108+
rc=0
109+
PATH="$tmp/bin:$PATH" FAKE_CRDS="packages.cozystack.io" COZY_REPORT_DIR="$tmp/report" COZYTEST_TRACE=0 \
110+
"$REPO_ROOT/hack/cozytest.sh" "$tmp/hosted.bats" "The cluster carries none" > "$tmp/clean.log" 2>&1 || rc=$?
111+
if [ "$rc" -ne 0 ] || ! grep -q "Test OK" "$tmp/clean.log"; then
112+
echo "the check did not pass on a cluster with no cilium.io CRD:" >&2
113+
cat "$tmp/clean.log" >&2
114+
exit 1
115+
fi
116+
rm -rf "$tmp"
117+
}

0 commit comments

Comments
 (0)