44#
55# Expected data lives in 31_configmap_*.yaml files alongside this assert.
66# envsubst expands only the listed shell variables ($NAMESPACE etc.),
7- # leaving Hadoop ${env.FOO} references untouched. Both sides are
8- # normalised through yq so formatting differences don't cause false
9- # failures.
7+ # leaving Hadoop ${env.FOO} references untouched.
8+ #
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+ #
17+ # kuttl runs script commands with sh, not bash, so process substitution
18+ # is unavailable. Temp files namespaced under $NAMESPACE are used for
19+ # diff output to avoid collisions when tests run concurrently.
1020apiVersion: kuttl.dev/v1beta1
1121kind: TestAssert
1222timeout: 600
@@ -15,13 +25,10 @@ commands:
1525 # ConfigMap data snapshot: hdfs-namenode-default
1626 #
1727 - script: |
18- expected=$( envsubst '$NAMESPACE' < 31_configmap_hdfs-namenode-default.yaml | yq -o=json)
19- actual=$( kubectl -n $NAMESPACE get cm hdfs-namenode-default -o yaml | yq -o=json '.data | del(.["vector.toml"])')
20- if [ "$ expected" != "$ actual" ] ; then
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
2131 echo "ERROR: ConfigMap hdfs-namenode-default data drifted from snapshot."
22- echo "$expected" > /tmp/expected.json
23- echo "$actual" > /tmp/actual.json
24- diff /tmp/expected.json /tmp/actual.json
2532 exit 1
2633 fi
2734 #
@@ -33,25 +40,19 @@ commands:
3340{% else %}
3441 export DATANODE_DATA_DIR='[DISK]/stackable/data/data/datanode'
3542{% endif %}
36- expected=$( envsubst '$NAMESPACE $DATANODE_DATA_DIR' < 31_configmap_hdfs-datanode-default.yaml | yq -o=json)
37- actual=$( kubectl -n $NAMESPACE get cm hdfs-datanode-default -o yaml | yq -o=json '.data | del(.["vector.toml"])')
38- if [ "$ expected" != "$ actual" ] ; then
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
3946 echo "ERROR: ConfigMap hdfs-datanode-default data drifted from snapshot."
40- echo "$expected" > /tmp/expected.json
41- echo "$actual" > /tmp/actual.json
42- diff /tmp/expected.json /tmp/actual.json
4347 exit 1
4448 fi
4549 #
4650 # ConfigMap data snapshot: hdfs-journalnode-default
4751 #
4852 - script: |
49- expected=$( envsubst '$NAMESPACE' < 31_configmap_hdfs-journalnode-default.yaml | yq -o=json)
50- actual=$( kubectl -n $NAMESPACE get cm hdfs-journalnode-default -o yaml | yq -o=json '.data | del(.["vector.toml"])')
51- if [ "$ expected" != "$ actual" ] ; then
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
5256 echo "ERROR: ConfigMap hdfs-journalnode-default data drifted from snapshot."
53- echo "$expected" > /tmp/expected.json
54- echo "$actual" > /tmp/actual.json
55- diff /tmp/expected.json /tmp/actual.json
5657 exit 1
5758 fi
0 commit comments