From 563bde72c1dc71ffe9ab403561b87b5b49110402 Mon Sep 17 00:00:00 2001 From: Andrew Kenworthy Date: Tue, 23 Sep 2025 09:05:58 +0200 Subject: [PATCH] do not mask kubectl errors but do not crash on grep --- tests/templates/kuttl/logging/05-assert.yaml | 2 +- tests/templates/kuttl/logging/test_log_aggregation.sh | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) 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