Skip to content

Commit 637098f

Browse files
committed
test(kafka): anchor the release selector the hook suites assert on
Both suites matched "strimzi.io/cluster=kafka-test" as a bare substring, and that is a prefix of the sibling release kafka-test2 and of kafka-test-topics. Rendering the hook with either selector left both suites green, so neither pinned the scoping they exist to pin. Anchor on the leading "-l " and on the trailing delimiter; both variants now red in both suites, and the six earlier hook mutations still red exactly where they did. Drop the notMatchRegex on a leading slash. It cannot fail on its own: the anchored image pattern above rejects a leading slash first, and an empty _cluster.images-registry renders no slash to begin with. Its rationale moves into that pattern's comment. Record why activeDeadlineSeconds and the 180s wait have to move together. A deadline that fires mid-wait kills the Job, and with backoffLimit: 0 the hook then returns non-zero, which is the wedged uninstall the deliberate exit 0 on the timeout branch exists to avoid. Assisted-by: LLM Signed-off-by: IvanHunters <[email protected]>
1 parent 415aa82 commit 637098f

3 files changed

Lines changed: 20 additions & 9 deletions

File tree

‎hack/kafka-pre-delete-hook.bats‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,12 @@ KEOF
100100
cat "$tmp/out" "$tmp/err"
101101
false
102102
fi
103-
if ! grep -q "strimzi.io/cluster=kafka-test" "$tmp/calls"; then
103+
# Anchored on both sides. Bare "strimzi.io/cluster=kafka-test" is a prefix of
104+
# the sibling release kafka-test2 and of kafka-test-topics, so a selector
105+
# widened to either stays green against it: verified by rendering the hook
106+
# with {{ .Release.Name }}2 and watching this test pass. The leading "-l " and
107+
# the trailing space are what make it name this release and no other.
108+
if ! grep -q -- "-l strimzi.io/cluster=kafka-test " "$tmp/calls"; then
104109
echo "FAIL: the delete was not scoped to this release"
105110
cat "$tmp/calls"
106111
false

‎packages/apps/kafka/templates/hooks/delete.yaml‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ metadata:
1717
"helm.sh/hook-delete-policy": before-hook-creation
1818
spec:
1919
ttlSecondsAfterFinished: 3600
20+
# 270 + terminationGracePeriodSeconds 10 stays under helm-controller's 300s
21+
# default, and leaves 90s over the 180s wait below for scheduling and the
22+
# image pull. That headroom is the part to keep in mind when either number is
23+
# tuned: a deadline that fires mid-wait kills the Job, and with
24+
# backoffLimit: 0 the hook returns non-zero, which is the wedged uninstall the
25+
# deliberate exit 0 on the timeout branch exists to avoid. Raise this and the
26+
# wait together, or not at all.
2027
activeDeadlineSeconds: 270
2128
backoffLimit: 0
2229
template:

‎packages/apps/kafka/tests/delete_test.yaml‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,12 @@ tests:
4343
path: spec.ttlSecondsAfterFinished
4444
value: 3600
4545
documentIndex: 0
46+
# Both quotes are part of the pattern. Unanchored, this matches a selector
47+
# widened to the sibling release kafka-test2 or to kafka-test-topics, so
48+
# it would pin nothing about scoping.
4649
- matchRegex:
4750
path: spec.template.spec.containers[0].command[2]
48-
pattern: "strimzi\\.io/cluster=kafka-test"
51+
pattern: "-l 'strimzi\\.io/cluster=kafka-test'"
4952
documentIndex: 0
5053
- matchRegex:
5154
path: spec.template.spec.containers[0].command[2]
@@ -56,17 +59,13 @@ tests:
5659
# tests/, so a literal of either turns the next bump red for no defect.
5760
# What matters is that the ref stays pinned by digest at all. Same shape
5861
# as harbor's cleanup_hook_test.yaml and mariadb's
59-
# cleanup_pvc_hook_test.yaml.
62+
# cleanup_pvc_hook_test.yaml. The leading ^ also covers the empty
63+
# images-registry case, where a bare leading slash would be an unpullable
64+
# ref that only surfaces at uninstall time.
6065
- matchRegex:
6166
path: spec.template.spec.containers[0].image
6267
pattern: ^clastix/kubectl:v[0-9]+\.[0-9]+(\.[0-9]+)?@sha256:[0-9a-f]{64}$
6368
documentIndex: 0
64-
# An empty images-registry must not leave a bare leading slash, which is
65-
# an unpullable ref that only shows up at uninstall time.
66-
- notMatchRegex:
67-
path: spec.template.spec.containers[0].image
68-
pattern: ^/
69-
documentIndex: 0
7069
- isKind:
7170
of: ServiceAccount
7271
documentIndex: 1

0 commit comments

Comments
 (0)