Skip to content

Commit e40a044

Browse files
committed
fix(tests): add vector templates & fix vars
1 parent fcebf3d commit e40a044

5 files changed

Lines changed: 840 additions & 36 deletions

File tree

tests/templates/kuttl/smoke/30-assert.yaml.j2

Lines changed: 84 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -321,12 +321,14 @@ spec:
321321
name: listener
322322
{% if lookup('env', 'VECTOR_AGGREGATOR') %}
323323
- args:
324-
- |
324+
- |-
325325
mkdir --parents /stackable/log/_vector-state
326326
# Vector will ignore SIGTERM (as PID != 1) and must be shut down by writing a shutdown trigger file
327-
vector --config /stackable/config/vector.yaml & vector_pid=$!
327+
vector & vector_pid=$!
328328
if [ ! -f "/stackable/log/_vector/shutdown" ]; then
329-
mkdir -p /stackable/log/_vector && inotifywait -qq --event create /stackable/log/_vector; fi
329+
mkdir -p /stackable/log/_vector
330+
inotifywait -qq --event create /stackable/log/_vector;
331+
fi
330332
sleep 1
331333
kill $vector_pid
332334
command:
@@ -336,13 +338,31 @@ spec:
336338
- pipefail
337339
- -c
338340
env:
339-
- name: VECTOR_LOG
340-
value: info
341+
- name: CLUSTER_NAME
342+
value: test-hbase
343+
- name: DATA_DIR
344+
value: /stackable/log/_vector-state
345+
- name: LOG_DIR
346+
value: /stackable/log
347+
- name: NAMESPACE
348+
valueFrom:
349+
fieldRef:
350+
fieldPath: metadata.namespace
351+
- name: ROLE_GROUP_NAME
352+
value: default
353+
- name: ROLE_NAME
354+
value: master
341355
- name: VECTOR_AGGREGATOR_ADDRESS
342356
valueFrom:
343357
configMapKeyRef:
344358
key: ADDRESS
345359
name: vector-aggregator-discovery
360+
- name: VECTOR_CONFIG_YAML
361+
value: /stackable/config/vector.yaml
362+
- name: VECTOR_FILE_LOG_LEVEL
363+
value: info
364+
- name: VECTOR_LOG
365+
value: info
346366
imagePullPolicy: IfNotPresent
347367
name: vector
348368
resources:
@@ -353,8 +373,10 @@ spec:
353373
cpu: 250m
354374
memory: 128Mi
355375
volumeMounts:
356-
- mountPath: /stackable/config
376+
- mountPath: /stackable/config/vector.yaml
357377
name: hbase-config
378+
readOnly: true
379+
subPath: vector.yaml
358380
- mountPath: /stackable/log
359381
name: log
360382
{% endif %}
@@ -534,12 +556,14 @@ spec:
534556
name: listener
535557
{% if lookup('env', 'VECTOR_AGGREGATOR') %}
536558
- args:
537-
- |
559+
- |-
538560
mkdir --parents /stackable/log/_vector-state
539561
# Vector will ignore SIGTERM (as PID != 1) and must be shut down by writing a shutdown trigger file
540-
vector --config /stackable/config/vector.yaml & vector_pid=$!
562+
vector & vector_pid=$!
541563
if [ ! -f "/stackable/log/_vector/shutdown" ]; then
542-
mkdir -p /stackable/log/_vector && inotifywait -qq --event create /stackable/log/_vector; fi
564+
mkdir -p /stackable/log/_vector
565+
inotifywait -qq --event create /stackable/log/_vector;
566+
fi
543567
sleep 1
544568
kill $vector_pid
545569
command:
@@ -549,13 +573,31 @@ spec:
549573
- pipefail
550574
- -c
551575
env:
552-
- name: VECTOR_LOG
553-
value: info
576+
- name: CLUSTER_NAME
577+
value: test-hbase
578+
- name: DATA_DIR
579+
value: /stackable/log/_vector-state
580+
- name: LOG_DIR
581+
value: /stackable/log
582+
- name: NAMESPACE
583+
valueFrom:
584+
fieldRef:
585+
fieldPath: metadata.namespace
586+
- name: ROLE_GROUP_NAME
587+
value: default
588+
- name: ROLE_NAME
589+
value: regionserver
554590
- name: VECTOR_AGGREGATOR_ADDRESS
555591
valueFrom:
556592
configMapKeyRef:
557593
key: ADDRESS
558594
name: vector-aggregator-discovery
595+
- name: VECTOR_CONFIG_YAML
596+
value: /stackable/config/vector.yaml
597+
- name: VECTOR_FILE_LOG_LEVEL
598+
value: info
599+
- name: VECTOR_LOG
600+
value: info
559601
imagePullPolicy: IfNotPresent
560602
name: vector
561603
resources:
@@ -566,8 +608,10 @@ spec:
566608
cpu: 250m
567609
memory: 128Mi
568610
volumeMounts:
569-
- mountPath: /stackable/config
611+
- mountPath: /stackable/config/vector.yaml
570612
name: hbase-config
613+
readOnly: true
614+
subPath: vector.yaml
571615
- mountPath: /stackable/log
572616
name: log
573617
{% endif %}
@@ -743,12 +787,14 @@ spec:
743787
name: listener
744788
{% if lookup('env', 'VECTOR_AGGREGATOR') %}
745789
- args:
746-
- |
790+
- |-
747791
mkdir --parents /stackable/log/_vector-state
748792
# Vector will ignore SIGTERM (as PID != 1) and must be shut down by writing a shutdown trigger file
749-
vector --config /stackable/config/vector.yaml & vector_pid=$!
793+
vector & vector_pid=$!
750794
if [ ! -f "/stackable/log/_vector/shutdown" ]; then
751-
mkdir -p /stackable/log/_vector && inotifywait -qq --event create /stackable/log/_vector; fi
795+
mkdir -p /stackable/log/_vector
796+
inotifywait -qq --event create /stackable/log/_vector;
797+
fi
752798
sleep 1
753799
kill $vector_pid
754800
command:
@@ -758,13 +804,31 @@ spec:
758804
- pipefail
759805
- -c
760806
env:
761-
- name: VECTOR_LOG
762-
value: info
807+
- name: CLUSTER_NAME
808+
value: test-hbase
809+
- name: DATA_DIR
810+
value: /stackable/log/_vector-state
811+
- name: LOG_DIR
812+
value: /stackable/log
813+
- name: NAMESPACE
814+
valueFrom:
815+
fieldRef:
816+
fieldPath: metadata.namespace
817+
- name: ROLE_GROUP_NAME
818+
value: default
819+
- name: ROLE_NAME
820+
value: restserver
763821
- name: VECTOR_AGGREGATOR_ADDRESS
764822
valueFrom:
765823
configMapKeyRef:
766824
key: ADDRESS
767825
name: vector-aggregator-discovery
826+
- name: VECTOR_CONFIG_YAML
827+
value: /stackable/config/vector.yaml
828+
- name: VECTOR_FILE_LOG_LEVEL
829+
value: info
830+
- name: VECTOR_LOG
831+
value: info
768832
imagePullPolicy: IfNotPresent
769833
name: vector
770834
resources:
@@ -775,8 +839,10 @@ spec:
775839
cpu: 250m
776840
memory: 128Mi
777841
volumeMounts:
778-
- mountPath: /stackable/config
842+
- mountPath: /stackable/config/vector.yaml
779843
name: hbase-config
844+
readOnly: true
845+
subPath: vector.yaml
780846
- mountPath: /stackable/log
781847
name: log
782848
{% endif %}
Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
---
2+
# Snapshot the full `.data` of each operator-managed rolegroup ConfigMap.
3+
# Any code change that alters a rendered config value will fail these diffs.
4+
#
5+
# How the comparison stays robust:
6+
# * The snapshot files (32_cm-*.yaml) are read straight from disk, so no shell
7+
# `$`-expansion happens: the literal ${NAMESPACE}/${DATA_DIR}/... that the
8+
# operator writes into vector.yaml (Vector resolves them at runtime) survive
9+
# verbatim. Only the two genuinely dynamic values use sentinels:
10+
# - __NAMESPACE__ -> substituted with the random kuttl namespace via sed.
11+
# - __ZNODE__ -> the zk operator mints a fresh znode UUID per install,
12+
# so we normalize the *actual* side instead of guessing
13+
# it (see the sed on the `actual=` pipeline).
14+
# * Both sides are canonicalized to JSON with `yq -o=json`, so block-scalar
15+
# style and trailing-newline differences never cause false positives.
16+
# * On drift we print a `diff -u` so the failing keys are obvious in the logs.
217
apiVersion: kuttl.dev/v1beta1
318
kind: TestAssert
419
timeout: 60
@@ -7,34 +22,55 @@ commands:
722
# ConfigMap data snapshot: test-hbase-master-default
823
#
924
- script: |
10-
export ZNODE_PATH=$(kubectl -n $NAMESPACE get zookeeperznode test-znode -o jsonpath='{.status.znodePath}')
11-
envsubst '$NAMESPACE $ZNODE_PATH' < 32_cm-test-hbase-master-default.yaml > /tmp/$NAMESPACE-expected.yaml
12-
kubectl -n $NAMESPACE get cm test-hbase-master-default -o yaml | yq '.data' > /tmp/$NAMESPACE-actual.yaml
13-
if ! diff /tmp/$NAMESPACE-expected.yaml /tmp/$NAMESPACE-actual.yaml; then
25+
expected=$(sed "s|__NAMESPACE__|$NAMESPACE|g" 32_cm-test-hbase-master-default.yaml | yq -o=json)
26+
actual=$(kubectl -n $NAMESPACE get cm test-hbase-master-default -o yaml \
27+
| yq -o=json '.data' \
28+
| sed -E 's|/znode-[a-f0-9-]+|/znode-__ZNODE__|')
29+
expected_file=$(mktemp) && actual_file=$(mktemp)
30+
printf '%s\n' "$expected" > "$expected_file"
31+
printf '%s\n' "$actual" > "$actual_file"
32+
if ! diff_out=$(diff -u "$expected_file" "$actual_file"); then
1433
echo "ERROR: ConfigMap test-hbase-master-default data drifted from snapshot."
34+
printf '%s\n' "$diff_out"
35+
rm -f "$expected_file" "$actual_file"
1536
exit 1
1637
fi
38+
rm -f "$expected_file" "$actual_file"
1739
1840
#
1941
# ConfigMap data snapshot: test-hbase-regionserver-default
2042
#
2143
- script: |
22-
export ZNODE_PATH=$(kubectl -n $NAMESPACE get zookeeperznode test-znode -o jsonpath='{.status.znodePath}')
23-
envsubst '$NAMESPACE $ZNODE_PATH' < 32_cm-test-hbase-regionserver-default.yaml > /tmp/$NAMESPACE-expected.yaml
24-
kubectl -n $NAMESPACE get cm test-hbase-regionserver-default -o yaml | yq '.data' > /tmp/$NAMESPACE-actual.yaml
25-
if ! diff /tmp/$NAMESPACE-expected.yaml /tmp/$NAMESPACE-actual.yaml; then
44+
expected=$(sed "s|__NAMESPACE__|$NAMESPACE|g" 32_cm-test-hbase-regionserver-default.yaml | yq -o=json)
45+
actual=$(kubectl -n $NAMESPACE get cm test-hbase-regionserver-default -o yaml \
46+
| yq -o=json '.data' \
47+
| sed -E 's|/znode-[a-f0-9-]+|/znode-__ZNODE__|')
48+
expected_file=$(mktemp) && actual_file=$(mktemp)
49+
printf '%s\n' "$expected" > "$expected_file"
50+
printf '%s\n' "$actual" > "$actual_file"
51+
if ! diff_out=$(diff -u "$expected_file" "$actual_file"); then
2652
echo "ERROR: ConfigMap test-hbase-regionserver-default data drifted from snapshot."
53+
printf '%s\n' "$diff_out"
54+
rm -f "$expected_file" "$actual_file"
2755
exit 1
2856
fi
57+
rm -f "$expected_file" "$actual_file"
2958
3059
#
3160
# ConfigMap data snapshot: test-hbase-restserver-default
3261
#
3362
- script: |
34-
export ZNODE_PATH=$(kubectl -n $NAMESPACE get zookeeperznode test-znode -o jsonpath='{.status.znodePath}')
35-
envsubst '$NAMESPACE $ZNODE_PATH' < 32_cm-test-hbase-restserver-default.yaml > /tmp/$NAMESPACE-expected.yaml
36-
kubectl -n $NAMESPACE get cm test-hbase-restserver-default -o yaml | yq '.data' > /tmp/$NAMESPACE-actual.yaml
37-
if ! diff /tmp/$NAMESPACE-expected.yaml /tmp/$NAMESPACE-actual.yaml; then
63+
expected=$(sed "s|__NAMESPACE__|$NAMESPACE|g" 32_cm-test-hbase-restserver-default.yaml | yq -o=json)
64+
actual=$(kubectl -n $NAMESPACE get cm test-hbase-restserver-default -o yaml \
65+
| yq -o=json '.data' \
66+
| sed -E 's|/znode-[a-f0-9-]+|/znode-__ZNODE__|')
67+
expected_file=$(mktemp) && actual_file=$(mktemp)
68+
printf '%s\n' "$expected" > "$expected_file"
69+
printf '%s\n' "$actual" > "$actual_file"
70+
if ! diff_out=$(diff -u "$expected_file" "$actual_file"); then
3871
echo "ERROR: ConfigMap test-hbase-restserver-default data drifted from snapshot."
72+
printf '%s\n' "$diff_out"
73+
rm -f "$expected_file" "$actual_file"
3974
exit 1
4075
fi
76+
rm -f "$expected_file" "$actual_file"

0 commit comments

Comments
 (0)