diff --git a/tests/templates/kuttl/logging/05-assert.yaml b/tests/templates/kuttl/logging/05-assert.yaml index b7a33ca3..985a0c44 100644 --- a/tests/templates/kuttl/logging/05-assert.yaml +++ b/tests/templates/kuttl/logging/05-assert.yaml @@ -7,4 +7,4 @@ commands: python /tmp/test_log_aggregation.py -n $NAMESPACE - script: >- kubectl exec --namespace=$NAMESPACE opa-test-runner-0 -- - sh /tmp/test_log_aggregation.sh + /tmp/test_log_aggregation.sh diff --git a/tests/templates/kuttl/logging/test_log_aggregation.sh b/tests/templates/kuttl/logging/test_log_aggregation.sh index fab2faca..218bf8eb 100755 --- a/tests/templates/kuttl/logging/test_log_aggregation.sh +++ b/tests/templates/kuttl/logging/test_log_aggregation.sh @@ -1,6 +1,14 @@ #!/usr/bin/env bash -DECISION_LOGS=$(kubectl logs service/test-opa-server -c opa | grep "decision_id"); +# we should distinguish between cases where the variable is not set +# if the service or container is not found (which we don't want), and where +# grep does not find anything (which is what we *do* want). + +set -Eeuo pipefail + +# do not mask kubectl errors, but the right-hand group must always be true +# so the test does not fail on the grep +DECISION_LOGS=$(kubectl logs service/test-opa-server -c opa | { grep "decision_id" || true; }) if [ -n "$DECISION_LOGS" ]; then