From 4d82cb4c2225d67f020493847928234da8840f36 Mon Sep 17 00:00:00 2001 From: Maxi Wittich Date: Mon, 26 Aug 2024 20:01:49 +0200 Subject: [PATCH 1/4] Adding tests for file_header and footer --- .../templates/kuttl/smoke/30-install-superset.yaml.j2 | 11 +++++++++++ tests/templates/kuttl/smoke/31-assert.yaml | 11 +++++++++++ 2 files changed, 22 insertions(+) create mode 100644 tests/templates/kuttl/smoke/31-assert.yaml diff --git a/tests/templates/kuttl/smoke/30-install-superset.yaml.j2 b/tests/templates/kuttl/smoke/30-install-superset.yaml.j2 index 7739c151..f2db46f8 100644 --- a/tests/templates/kuttl/smoke/30-install-superset.yaml.j2 +++ b/tests/templates/kuttl/smoke/30-install-superset.yaml.j2 @@ -36,6 +36,17 @@ spec: config: logging: enableVectorAgent: {{ lookup('env', 'VECTOR_AGGREGATOR') | length > 0 }} + configOverrides: + superset_config.py: + EXPERIMENTAL_FILE_HEADER: | + COMMON_HEADER_VAR = "role-value" + ROLE_HEADER_VAR = "role-value" + EXPERIMENTAL_FILE_FOOTER: | + ROLE_FOOTER_VAR = "role-value" roleGroups: default: replicas: 1 + configOverrides: + superset_config.py: + EXPERIMENTAL_FILE_HEADER: | + COMMON_HEADER_VAR = "group-value" diff --git a/tests/templates/kuttl/smoke/31-assert.yaml b/tests/templates/kuttl/smoke/31-assert.yaml new file mode 100644 index 00000000..d1063850 --- /dev/null +++ b/tests/templates/kuttl/smoke/31-assert.yaml @@ -0,0 +1,11 @@ +--- +apiVersion: kuttl.dev/v1beta1 +kind: TestAssert +timeout: 600 +commands: + # + # Test envOverrides + # + - script: | + kubectl -n $NAMESPACE get cm superset-node-default -o yaml | yq -e '.data."superset_config.py"' | grep "COMMON_HEADER_VAR = "group-value"" + kubectl -n $NAMESPACE get cm superset-node-default -o yaml | yq -e '.data."superset_config.py"' | grep "ROLE_FOOTER_VAR = "role-value"" From 0d25aeb87b9396f0484d606266cb2cb2a3d5c335 Mon Sep 17 00:00:00 2001 From: Maxi Wittich Date: Tue, 27 Aug 2024 14:03:29 +0200 Subject: [PATCH 2/4] Adding test step to check if var ROLE_HEADER_VAR is gone --- tests/templates/kuttl/smoke/31-assert.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/templates/kuttl/smoke/31-assert.yaml b/tests/templates/kuttl/smoke/31-assert.yaml index 5e70aaac..c64bbcd4 100644 --- a/tests/templates/kuttl/smoke/31-assert.yaml +++ b/tests/templates/kuttl/smoke/31-assert.yaml @@ -9,6 +9,7 @@ commands: - script: | kubectl -n $NAMESPACE get cm superset-node-default -o yaml | yq -e '.data."superset_config.py"' | grep "COMMON_HEADER_VAR = "group-value"" kubectl -n $NAMESPACE get cm superset-node-default -o yaml | yq -e '.data."superset_config.py"' | grep "ROLE_FOOTER_VAR = "role-value"" + if [ -z "$(kubectl -n $NAMESPACE get cm superset-node-default -o yaml | yq -e '.data."superset_config.py"' | grep "ROLE_HEADER_VAR = \"role-value\"")" ]; then (echo "Success, ROLE_HEADER_VAR not present") else { echo "Failure, ROLE_HEADER_VAR present"; exit 1; } fi kubectl -n $NAMESPACE get sts superset-node-default -o yaml | yq -e '.spec.template.spec.containers[] | select (.name == "superset") | .env[] | select (.name == "COMMON_VAR" and .value == "group-value")' kubectl -n $NAMESPACE get sts superset-node-default -o yaml | yq -e '.spec.template.spec.containers[] | select (.name == "superset") | .env[] | select (.name == "GROUP_VAR" and .value == "group-value")' kubectl -n $NAMESPACE get sts superset-node-default -o yaml | yq -e '.spec.template.spec.containers[] | select (.name == "superset") | .env[] | select (.name == "ROLE_VAR" and .value == "role-value")' From ca1e7263e2875ce3f044a71443fa4c1befacf06e Mon Sep 17 00:00:00 2001 From: Maxi Wittich Date: Wed, 28 Aug 2024 19:37:28 +0200 Subject: [PATCH 3/4] Reworking tests for more readability and better codes style --- tests/templates/kuttl/smoke/31-assert.yaml | 33 ++++++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/tests/templates/kuttl/smoke/31-assert.yaml b/tests/templates/kuttl/smoke/31-assert.yaml index c64bbcd4..607599ce 100644 --- a/tests/templates/kuttl/smoke/31-assert.yaml +++ b/tests/templates/kuttl/smoke/31-assert.yaml @@ -7,9 +7,30 @@ commands: # Test envOverrides # - script: | - kubectl -n $NAMESPACE get cm superset-node-default -o yaml | yq -e '.data."superset_config.py"' | grep "COMMON_HEADER_VAR = "group-value"" - kubectl -n $NAMESPACE get cm superset-node-default -o yaml | yq -e '.data."superset_config.py"' | grep "ROLE_FOOTER_VAR = "role-value"" - if [ -z "$(kubectl -n $NAMESPACE get cm superset-node-default -o yaml | yq -e '.data."superset_config.py"' | grep "ROLE_HEADER_VAR = \"role-value\"")" ]; then (echo "Success, ROLE_HEADER_VAR not present") else { echo "Failure, ROLE_HEADER_VAR present"; exit 1; } fi - kubectl -n $NAMESPACE get sts superset-node-default -o yaml | yq -e '.spec.template.spec.containers[] | select (.name == "superset") | .env[] | select (.name == "COMMON_VAR" and .value == "group-value")' - kubectl -n $NAMESPACE get sts superset-node-default -o yaml | yq -e '.spec.template.spec.containers[] | select (.name == "superset") | .env[] | select (.name == "GROUP_VAR" and .value == "group-value")' - kubectl -n $NAMESPACE get sts superset-node-default -o yaml | yq -e '.spec.template.spec.containers[] | select (.name == "superset") | .env[] | select (.name == "ROLE_VAR" and .value == "role-value")' + #!/usr/bin/env bash + set -euo pipefail + + # Config Test Data + SUPERSET_CONFIG=$( + kubectl -n "$NAMESPACE" get cm superset-node-default -o yaml \ + | yq -e '.data["superset_config.py"]' + ) + + # Config Test Assertions + echo "$SUPERSET_CONFIG" | grep 'COMMON_HEADER_VAR = "group-value"' + echo "$SUPERSET_CONFIG" | grep 'ROLE_FOOTER_VAR = "role-value"' + echo "$SUPERSET_CONFIG" | grep -v 'ROLE_HEADER_VAR = "role-value"' + + # STS Spec Test Data + SUPERSET_NODE_DEFAULT_STS=$(kubectl -n "$NAMESPACE" get sts superset-node-default -o yaml) + YQ_FILTER=' + .spec.template.spec.containers[] + | select(.name == "superset") + | .env[] + | select(.name == strenv(KEY) and .value == strenv(VALUE)) + ' + + # STS Spec Test Assertions + echo "$SUPERSET_NODE_DEFAULT_STS" | KEY="COMMON_VAR" VALUE="group-value" yq -e "$YQ_FILTER" + echo "$SUPERSET_NODE_DEFAULT_STS" | KEY="GROUP_VAR" VALUE="group-value" yq -e "$YQ_FILTER" + echo "$SUPERSET_NODE_DEFAULT_STS" | KEY="ROLE_VAR" VALUE="role-value" yq -e "$YQ_FILTER" \ No newline at end of file From 253f467b4d05426e1450ead4634e4bf32a6f5985 Mon Sep 17 00:00:00 2001 From: Maxi Wittich Date: Wed, 28 Aug 2024 19:39:13 +0200 Subject: [PATCH 4/4] Adding new line --- tests/templates/kuttl/smoke/31-assert.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/templates/kuttl/smoke/31-assert.yaml b/tests/templates/kuttl/smoke/31-assert.yaml index 607599ce..aa98ee25 100644 --- a/tests/templates/kuttl/smoke/31-assert.yaml +++ b/tests/templates/kuttl/smoke/31-assert.yaml @@ -33,4 +33,4 @@ commands: # STS Spec Test Assertions echo "$SUPERSET_NODE_DEFAULT_STS" | KEY="COMMON_VAR" VALUE="group-value" yq -e "$YQ_FILTER" echo "$SUPERSET_NODE_DEFAULT_STS" | KEY="GROUP_VAR" VALUE="group-value" yq -e "$YQ_FILTER" - echo "$SUPERSET_NODE_DEFAULT_STS" | KEY="ROLE_VAR" VALUE="role-value" yq -e "$YQ_FILTER" \ No newline at end of file + echo "$SUPERSET_NODE_DEFAULT_STS" | KEY="ROLE_VAR" VALUE="role-value" yq -e "$YQ_FILTER"