Skip to content

Commit 31847c4

Browse files
committed
Update root CA certificate ownership kuttl test
Adds better check logic to account for potential race conditions that may be encountered in some environments due to delays in garbage collection and ownership updating. Also fixed a comment and harmonized filenames with existing patterns.
1 parent 2c9a397 commit 31847c4

File tree

5 files changed

+58
-45
lines changed

5 files changed

+58
-45
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
apiVersion: kuttl.dev/v1beta1
3+
kind: TestStep
4+
commands:
5+
# Get a list of the current owners of the root ca cert secret and verify that
6+
# both owners are listed.
7+
- script: |
8+
for i in {1..5}; do
9+
sleep 1 # this sleep allows time for the owner reference list to be updated
10+
CURRENT_OWNERS=$(kubectl --namespace="${NAMESPACE}" get secret \
11+
pgo-root-cacert -o jsonpath='{.metadata.ownerReferences[*].name}')
12+
# If owner1 and owner2 are both listed, exit successfully
13+
if [[ "$CURRENT_OWNERS" == *"owner1"* ]] && [[ "$CURRENT_OWNERS" == *"owner2"* ]]; then
14+
exit 0
15+
fi
16+
done
17+
# proper ownership references were not found, so the test fails
18+
exit 1

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

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
apiVersion: kuttl.dev/v1beta1
3+
kind: TestStep
4+
commands:
5+
# Get a list of the current owners of the root ca cert secret and verify that
6+
# owner1 is no longer listed and owner2 is found.
7+
- script: |
8+
for i in {1..5}; do
9+
sleep 1 # this sleep allows time for the owner reference list to be updated
10+
CURRENT_OWNERS=$(kubectl --namespace="${NAMESPACE}" get secret \
11+
pgo-root-cacert -o jsonpath='{.metadata.ownerReferences[*].name}')
12+
# If owner1 is removed and owner2 is still listed, exit successfully
13+
if [[ "$CURRENT_OWNERS" != *"owner1"* ]] && [[ "$CURRENT_OWNERS" == *"owner2"* ]]; then
14+
exit 0
15+
fi
16+
done
17+
# proper ownership references were not found, so the test fails
18+
exit 1

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

Lines changed: 0 additions & 16 deletions
This file was deleted.

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

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,33 @@
22
apiVersion: kuttl.dev/v1beta1
33
kind: TestStep
44
commands:
5-
# If there are other PostgresClusters in the namespace, ensure that 'owner2'
5+
# If there are other PostgresClusters in the namespace, ensure that 'owner1'
66
# and 'owner2' are not listed.
77
# If there are no other PostgresClusters in the namespace, the 'pgo-root-cacert'
88
# secret should be deleted.
99
- script: |
1010
NUM_CLUSTERS=$(kubectl --namespace="${NAMESPACE}" get postgrescluster --output name | wc -l)
1111
if [[ "$NUM_CLUSTERS" != 0 ]]; then
12-
CURRENT_OWNERS=$(kubectl --namespace="${NAMESPACE}" get secret \
13-
pgo-root-cacert -o jsonpath='{.metadata.ownerReferences[*].name}')
14-
if [[ "$CURRENT_OWNERS" == *"owner1"* ]]; then
15-
exit 1
16-
fi
17-
if [[ "$CURRENT_OWNERS" == *"owner2"* ]]; then
18-
exit 1
19-
fi
12+
for i in {1..5}; do
13+
sleep 1 # This sleep allows time for the owner reference list to be updated
14+
CURRENT_OWNERS=$(kubectl --namespace="${NAMESPACE}" get secret \
15+
pgo-root-cacert -o jsonpath='{.metadata.ownerReferences[*].name}')
16+
# If neither owner is listed, exit successfully
17+
if [[ "$CURRENT_OWNERS" != *"owner1"* ]] || [[ "$CURRENT_OWNERS" != *"owner2"* ]]; then
18+
exit 0
19+
fi
20+
done
21+
# At least one owner was never removed, so the test fails
22+
exit 1
2023
else
21-
ROOT_SECRET=$(kubectl --namespace="${NAMESPACE}" get --ignore-not-found \
22-
secret pgo-root-cacert --output name | wc -l)
23-
if [[ "$ROOT_SECRET" != 0 ]]; then
24-
exit 1
25-
fi
24+
for i in {1..5}; do
25+
sleep 1 # this sleep allows time for garbage collector to delete the secret
26+
ROOT_SECRET=$(kubectl --namespace="${NAMESPACE}" get --ignore-not-found \
27+
secret pgo-root-cacert --output name | wc -l)
28+
if [[ "$ROOT_SECRET" == 0 ]]; then
29+
exit 0
30+
fi
31+
done
32+
# The root secret was never removed, so the test fails
33+
exit 1
2634
fi

0 commit comments

Comments
 (0)