Skip to content

test: Add tests for file_header and footer #533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions tests/templates/kuttl/smoke/30-install-superset.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,20 @@ 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"
envOverrides:
COMMON_VAR: group-value # overrides role value
GROUP_VAR: group-value # only defined here at group level
30 changes: 27 additions & 3 deletions tests/templates/kuttl/smoke/31-assert.yaml
Copy link
Member

@NickLarsenNZ NickLarsenNZ Aug 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's my suggestion:

  • Use bash and with strict mode (so failures before the last command cause the script to fail).
  • Reduce calls to kubectl for the same resources.
  • Simplify the assertions.
  • Use single quotes for strings which don't need variable expansion.
  • Template the yq filter (unfortunately the go yq works so much differently to the python one which works basically the same as jq... so there are no --arg options).
# - script: |
      #!/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"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the suggestion, it makes sense to me. However, we implemented such stuff here e.g. https://github.com/stackabletech/airflow-operator/pull/490/files and from myself https://github.com/stackabletech/airflow-operator/pull/493/files

As I said I like your suggestion, but fear our tests differ to much from one another and nobody is going to understand it anymore

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see how it has been done, but to me they are unreadable. I think we should go with the readable option (it lessens the burden on reviewers too).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First off: I don't have a strong opinion, but I would tend to agree with @NickLarsenNZ. I see your concerns @Maleware and I have the same ones (mono-repo would be much easier here), but I personally think readability is more important in this case (especially as @NickLarsenNZ already did the work of rewriting the script)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Granted: ca1e726

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,30 @@ commands:
# Test envOverrides
#
- script: |
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"
Loading