Skip to content

Commit 08c2450

Browse files
Tests/fix assertions (#786)
* test(smoke): Fix assertions * test(smoke): Fix assertions * chore: Fix the pre-commit configuration
1 parent 5d2f081 commit 08c2450

9 files changed

Lines changed: 2423 additions & 587 deletions

.pre-commit-config.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
---
2-
exclude: ^(Cargo\.nix|crate-hashes\.json|nix/.*)$
2+
# The files tests/templates/kuttl/smoke/31_configmap_.* define the expected ConfigMap contents.
3+
# New lines at the end of these files are intentional and must not be removed by the pre-commit hook
4+
# "end-of-file-fixer".
5+
exclude: ^(Cargo\.nix|crate-hashes\.json|nix/.*|tests/templates/kuttl/smoke/31_configmap_.*)$
36

47
default_language_version:
58
node: system

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

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,45 @@ spec:
405405
name: listener
406406
- mountPath: /stackable/data
407407
name: data
408+
{% if lookup('env', 'VECTOR_AGGREGATOR') %}
409+
- args:
410+
- |
411+
mkdir --parents /stackable/log/_vector-state
412+
# Vector will ignore SIGTERM (as PID != 1) and must be shut down by writing a shutdown trigger file
413+
vector --config /stackable/config/vector.yaml & vector_pid=$!
414+
if [ ! -f "/stackable/log/_vector/shutdown" ]; then
415+
mkdir -p /stackable/log/_vector && inotifywait -qq --event create /stackable/log/_vector; fi
416+
sleep 1
417+
kill $vector_pid
418+
command:
419+
- /bin/bash
420+
- -x
421+
- -euo
422+
- pipefail
423+
- -c
424+
env:
425+
- name: VECTOR_LOG
426+
value: info
427+
- name: VECTOR_AGGREGATOR_ADDRESS
428+
valueFrom:
429+
configMapKeyRef:
430+
key: ADDRESS
431+
name: vector-aggregator-discovery
432+
imagePullPolicy: IfNotPresent
433+
name: vector
434+
resources:
435+
limits:
436+
cpu: 500m
437+
memory: 128Mi
438+
requests:
439+
cpu: 250m
440+
memory: 128Mi
441+
volumeMounts:
442+
- mountPath: /stackable/config
443+
name: hdfs-config
444+
- mountPath: /stackable/log
445+
name: log
446+
{% endif %}
408447
- args:
409448
- |
410449
mkdir -p /stackable/config/zkfc
@@ -457,9 +496,6 @@ spec:
457496
name: zkfc-config
458497
- mountPath: /stackable/mount/log/zkfc
459498
name: zkfc-log-config
460-
{% if lookup('env', 'VECTOR_AGGREGATOR') %}
461-
- name: vector
462-
{% endif %}
463499
enableServiceLinks: false
464500
initContainers:
465501
- args:
@@ -710,7 +746,9 @@ spec:
710746
name: hdfs-namenode-default
711747
name: format-zookeeper-log-config
712748
volumeClaimTemplates:
713-
- metadata:
749+
- apiVersion: v1
750+
kind: PersistentVolumeClaim
751+
metadata:
714752
name: data
715753
spec:
716754
accessModes:
@@ -719,7 +757,10 @@ spec:
719757
requests:
720758
storage: 2Gi
721759
volumeMode: Filesystem
722-
- metadata:
760+
- apiVersion: v1
761+
kind: PersistentVolumeClaim
762+
metadata:
763+
name: data
723764
annotations:
724765
listeners.stackable.tech/listener-class: {{ test_scenario['values']['listener-class'] }}
725766
labels:

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

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,20 @@
66
# envsubst expands only the listed shell variables ($NAMESPACE etc.),
77
# leaving Hadoop ${env.FOO} references untouched.
88
#
9-
# Both sides are converted to JSON via yq, then jq normalises trailing
10-
# newlines in string values (collapsing \n+ to \n) so YAML block scalar
11-
# style (|, |+) differences don't cause false failures.
12-
# vector.toml is excluded because its presence depends on the
13-
# VECTOR_AGGREGATOR env var set by the CI/test runner. The snapshot
14-
# files are plain YAML (not Jinja2 templates), so they cannot
15-
# conditionally include it.
16-
#
179
# kuttl runs script commands with sh, not bash, so process substitution
1810
# is unavailable. Temp files namespaced under $NAMESPACE are used for
1911
# diff output to avoid collisions when tests run concurrently.
2012
apiVersion: kuttl.dev/v1beta1
2113
kind: TestAssert
22-
timeout: 600
14+
timeout: 60
2315
commands:
2416
#
2517
# ConfigMap data snapshot: hdfs-namenode-default
2618
#
2719
- script: |
28-
envsubst '$NAMESPACE' < 31_configmap_hdfs-namenode-default.yaml | yq -o=json | jq 'with_entries(.value |= sub("\n+$"; "\n"))' > /tmp/$NAMESPACE-expected.json
29-
kubectl -n $NAMESPACE get cm hdfs-namenode-default -o yaml | yq -o=json '.data | del(.["vector.toml"])' | jq 'with_entries(.value |= sub("\n+$"; "\n"))' > /tmp/$NAMESPACE-actual.json
30-
if ! diff /tmp/$NAMESPACE-expected.json /tmp/$NAMESPACE-actual.json; then
20+
envsubst '$NAMESPACE' < 31_configmap_hdfs-namenode-default.yaml > /tmp/$NAMESPACE-expected.yaml
21+
kubectl -n $NAMESPACE get cm hdfs-namenode-default -o yaml | yq '.data' > /tmp/$NAMESPACE-actual.yaml
22+
if ! diff /tmp/$NAMESPACE-expected.yaml /tmp/$NAMESPACE-actual.yaml; then
3123
echo "ERROR: ConfigMap hdfs-namenode-default data drifted from snapshot."
3224
exit 1
3325
fi
@@ -40,19 +32,19 @@ commands:
4032
{% else %}
4133
export DATANODE_DATA_DIR='[DISK]/stackable/data/data/datanode'
4234
{% endif %}
43-
envsubst '$NAMESPACE $DATANODE_DATA_DIR' < 31_configmap_hdfs-datanode-default.yaml | yq -o=json | jq 'with_entries(.value |= sub("\n+$"; "\n"))' > /tmp/$NAMESPACE-expected.json
44-
kubectl -n $NAMESPACE get cm hdfs-datanode-default -o yaml | yq -o=json '.data | del(.["vector.toml"])' | jq 'with_entries(.value |= sub("\n+$"; "\n"))' > /tmp/$NAMESPACE-actual.json
45-
if ! diff /tmp/$NAMESPACE-expected.json /tmp/$NAMESPACE-actual.json; then
35+
envsubst '$NAMESPACE $DATANODE_DATA_DIR' < 31_configmap_hdfs-datanode-default.yaml > /tmp/$NAMESPACE-expected.yaml
36+
kubectl -n $NAMESPACE get cm hdfs-datanode-default -o yaml | yq '.data' > /tmp/$NAMESPACE-actual.yaml
37+
if ! diff /tmp/$NAMESPACE-expected.yaml /tmp/$NAMESPACE-actual.yaml; then
4638
echo "ERROR: ConfigMap hdfs-datanode-default data drifted from snapshot."
4739
exit 1
4840
fi
4941
#
5042
# ConfigMap data snapshot: hdfs-journalnode-default
5143
#
5244
- script: |
53-
envsubst '$NAMESPACE' < 31_configmap_hdfs-journalnode-default.yaml | yq -o=json | jq 'with_entries(.value |= sub("\n+$"; "\n"))' > /tmp/$NAMESPACE-expected.json
54-
kubectl -n $NAMESPACE get cm hdfs-journalnode-default -o yaml | yq -o=json '.data | del(.["vector.toml"])' | jq 'with_entries(.value |= sub("\n+$"; "\n"))' > /tmp/$NAMESPACE-actual.json
55-
if ! diff /tmp/$NAMESPACE-expected.json /tmp/$NAMESPACE-actual.json; then
45+
envsubst '$NAMESPACE' < 31_configmap_hdfs-journalnode-default.yaml > /tmp/$NAMESPACE-expected.yaml
46+
kubectl -n $NAMESPACE get cm hdfs-journalnode-default -o yaml | yq '.data' > /tmp/$NAMESPACE-actual.yaml
47+
if ! diff /tmp/$NAMESPACE-expected.yaml /tmp/$NAMESPACE-actual.yaml; then
5648
echo "ERROR: ConfigMap hdfs-journalnode-default data drifted from snapshot."
5749
exit 1
5850
fi

tests/templates/kuttl/smoke/31_configmap_hdfs-datanode-default.yaml

Lines changed: 0 additions & 185 deletions
This file was deleted.

0 commit comments

Comments
 (0)