Skip to content

Commit f497724

Browse files
committed
Refactor looping tests
Instead of setting an amount of time that these loops are allowed to run, we can use an infinite loop that will fail when Kuttl hits its timeout. Issue [sc-18801]
1 parent c260fde commit f497724

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

testing/kuttl/e2e/root-cert-ownership/01--check-owners.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@ commands:
55
# Get a list of the current owners of the root ca cert secret and verify that
66
# both owners are listed.
77
- script: |
8-
for i in {1..5}; do
8+
contains() { bash -ceu '[[ "$1" == *"$2"* ]]' - "$@"; }
9+
while true; do
910
sleep 1 # this sleep allows time for the owner reference list to be updated
1011
CURRENT_OWNERS=$(kubectl --namespace="${NAMESPACE}" get secret \
1112
pgo-root-cacert -o jsonpath='{.metadata.ownerReferences[*].name}')
1213
# If owner1 and owner2 are both listed, exit successfully
13-
contains() { bash -ceu '[[ "$1" == *"$2"* ]]' - "$@"; }
1414
if contains "${CURRENT_OWNERS}" "owner1" && contains "${CURRENT_OWNERS}" "owner2"; then
1515
exit 0
1616
fi
1717
done
18-
# proper ownership references were not found, so the test fails
19-
exit 1

testing/kuttl/e2e/root-cert-ownership/03--check-owners.yaml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@ commands:
55
# Get a list of the current owners of the root ca cert secret and verify that
66
# owner1 is no longer listed and owner2 is found.
77
- script: |
8-
for i in {1..5}; do
8+
contains() { bash -ceu '[[ "$1" == *"$2"* ]]' - "$@"; }
9+
while true; do
910
sleep 1 # this sleep allows time for the owner reference list to be updated
1011
CURRENT_OWNERS=$(kubectl --namespace="${NAMESPACE}" get secret \
1112
pgo-root-cacert -o jsonpath='{.metadata.ownerReferences[*].name}')
1213
# If owner1 is removed and owner2 is still listed, exit successfully
13-
contains() { bash -ceu '[[ "$1" == *"$2"* ]]' - "$@"; }
14-
if ! contains "${CURRENT_OWNERS}" "owner1" && contains "${CURRENT_OWNERS}" "owner2"; then
14+
if !(contains "${CURRENT_OWNERS}" "owner1") && contains "${CURRENT_OWNERS}" "owner2"; then
1515
exit 0
1616
fi
1717
done
18-
# proper ownership references were not found, so the test fails
19-
exit 1

testing/kuttl/e2e/root-cert-ownership/05--check-secret.yaml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ commands:
88
# secret should be deleted.
99
- script: |
1010
NUM_CLUSTERS=$(kubectl --namespace="${NAMESPACE}" get postgrescluster --output name | wc -l)
11+
echo "Found ${NUM_CLUSTERS} clusters"
1112
if [ "$NUM_CLUSTERS" != 0 ]; then
12-
for i in {1..5}; do
13-
sleep 1 # This sleep allows time for the owner reference list to be updated
13+
# Continue checking until Kuttl times out
14+
# If at least one owner is never removed the test fails
15+
while true; do
16+
sleep 5 # This sleep allows time for the owner reference list to be updated
1417
CURRENT_OWNERS=$(kubectl --namespace="${NAMESPACE}" get secret \
1518
pgo-root-cacert -o jsonpath='{.metadata.ownerReferences[*].name}')
1619
# If neither owner is listed, exit successfully
@@ -19,17 +22,15 @@ commands:
1922
exit 0
2023
fi
2124
done
22-
# At least one owner was never removed, so the test fails
23-
exit 1
2425
else
25-
for i in {1..5}; do
26-
sleep 1 # this sleep allows time for garbage collector to delete the secret
26+
# Continue checking until Kuttl times out
27+
# If the secret is never removed, the test fails
28+
while true; do
29+
sleep 5 # this sleep allows time for garbage collector to delete the secret
2730
ROOT_SECRET=$(kubectl --namespace="${NAMESPACE}" get --ignore-not-found \
2831
secret pgo-root-cacert --output name | wc -l)
2932
if [ "$ROOT_SECRET" = 0 ]; then
3033
exit 0
3134
fi
3235
done
33-
# The root secret was never removed, so the test fails
34-
exit 1
3536
fi

0 commit comments

Comments
 (0)