Skip to content

Commit 201537d

Browse files
authored
do not mask kubectl errors but do not crash on grep (#764)
1 parent ec2fc7a commit 201537d

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

tests/templates/kuttl/logging/05-assert.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ commands:
77
python /tmp/test_log_aggregation.py -n $NAMESPACE
88
- script: >-
99
kubectl exec --namespace=$NAMESPACE opa-test-runner-0 --
10-
sh /tmp/test_log_aggregation.sh
10+
/tmp/test_log_aggregation.sh

tests/templates/kuttl/logging/test_log_aggregation.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
#!/usr/bin/env bash
22

3-
DECISION_LOGS=$(kubectl logs service/test-opa-server -c opa | grep "decision_id");
3+
# we should distinguish between cases where the variable is not set
4+
# if the service or container is not found (which we don't want), and where
5+
# grep does not find anything (which is what we *do* want).
6+
7+
set -Eeuo pipefail
8+
9+
# do not mask kubectl errors, but the right-hand group must always be true
10+
# so the test does not fail on the grep
11+
DECISION_LOGS=$(kubectl logs service/test-opa-server -c opa | { grep "decision_id" || true; })
412

513
if [ -n "$DECISION_LOGS" ];
614
then

0 commit comments

Comments
 (0)