Skip to content

Commit 3d1b0db

Browse files
committed
Updated KUTTL E2Es for POSIX standard shells
Overall reference - https://www.gnu.org/software/bash/manual/html_node/Major-Differences-From-The-Bourne-Shell.html Some specific items include: Double equals ('==') not supported by all POSIX shells. - https://www.shellcheck.net/wiki/SC3014 printf %q not supported by all POSIX shells. - https://ss64.com/bash/printf.html - https://www.shellcheck.net/wiki/SC3050 arithmetic for loops are undefined - https://www.shellcheck.net/wiki/SC3005 regex matching (=~) is undefined - https://www.shellcheck.net/wiki/SC3015 cannot match globs in [..] - https://www.shellcheck.net/wiki/SC2081 cannot use logical operators in [..] - https://www.shellcheck.net/wiki/SC2107 Issue: PGO-716
1 parent ec2b42d commit 3d1b0db

35 files changed

+295
-178
lines changed

testing/kuttl/e2e/backup/01--check-pod-command.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ commands:
66
- script: |
77
# Retry getting a successful pod from the most recent backup job.
88
# If that pod doesn't have the expected command, sleep and retry
9-
for i in {1..10}; do
9+
i=1; while [ $i -le 10 ]; do
1010
BACKUP_COMMAND=$(
1111
kubectl get pod --namespace "${NAMESPACE}" \
1212
--output jsonpath="{.items[*].spec.containers[*].env[?(@.name=='COMMAND_OPTS')].value}" \
@@ -19,10 +19,11 @@ commands:
1919
2020
echo "BACKUP_COMMAND found ${BACKUP_COMMAND}"
2121
22-
if [[ -n $BACKUP_COMMAND && "$BACKUP_COMMAND" == "--stanza=db --repo=1" ]]; then
22+
if [ -n "$BACKUP_COMMAND" ] && [ "$BACKUP_COMMAND" = "--stanza=db --repo=1" ]; then
2323
exit 0
2424
fi
2525
sleep 4
26+
i=$(( i + 1 ))
2627
done
2728
2829
exit 1

testing/kuttl/e2e/backup/02--backup-with-flags.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ commands:
66
77
echo "RESULT from taking backup: ${RESULT}"
88
9-
if [[ -n $RESULT && "$RESULT" == "postgresclusters/backup-cluster backup initiated" ]]; then
9+
if [ -n "$RESULT" ] && [ "$RESULT" = "postgresclusters/backup-cluster backup initiated" ]; then
1010
exit 0
1111
fi
1212

testing/kuttl/e2e/backup/03--check-pod-command-with-flags.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ commands:
66
- script: |
77
# Retry getting a successful pod from the most recent backup job.
88
# If that pod doesn't have the expected command, sleep and retry
9-
for i in {1..10}; do
9+
i=1; while [ $i -le 10 ]; do
1010
BACKUP_COMMAND=$(
1111
kubectl get pod --namespace "${NAMESPACE}" \
1212
--output jsonpath="{.items[*].spec.containers[*].env[?(@.name=='COMMAND_OPTS')].value}" \
@@ -19,10 +19,11 @@ commands:
1919
2020
echo "BACKUP_COMMAND found ${BACKUP_COMMAND}"
2121
22-
if [[ -n $BACKUP_COMMAND && "$BACKUP_COMMAND" == "--stanza=db --repo=1 --type=full" ]]; then
22+
if [ -n "$BACKUP_COMMAND" ] && [ "$BACKUP_COMMAND" = "--stanza=db --repo=1 --type=full" ]; then
2323
exit 0
2424
fi
2525
sleep 4
26+
i=$(( i + 1 ))
2627
done
2728
2829
exit 1

testing/kuttl/e2e/backup/04--backup-with-longer-option.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ commands:
66
77
echo "RESULT from taking backup: ${RESULT}"
88
9-
if [[ -n $RESULT && "$RESULT" == "postgresclusters/backup-cluster backup initiated" ]]; then
9+
if [ -n "$RESULT" ] && [ "$RESULT" = "postgresclusters/backup-cluster backup initiated" ]; then
1010
exit 0
1111
fi
1212

testing/kuttl/e2e/backup/05--check-pod-command-with-longer-options.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ commands:
66
- script: |
77
# Retry getting a successful pod from the most recent backup job.
88
# If that pod doesn't have the expected command, sleep and retry
9-
for i in {1..10}; do
9+
i=1; while [ $i -le 10 ]; do
1010
BACKUP_COMMAND=$(
1111
kubectl get pod --namespace "${NAMESPACE}" \
1212
--output jsonpath="{.items[*].spec.containers[*].env[?(@.name=='COMMAND_OPTS')].value}" \
@@ -19,10 +19,11 @@ commands:
1919
2020
echo "BACKUP_COMMAND found ${BACKUP_COMMAND}"
2121
22-
if [[ -n $BACKUP_COMMAND && "$BACKUP_COMMAND" == "--stanza=db --repo=1 --type=full --start-fast=y" ]]; then
22+
if [ -n "$BACKUP_COMMAND" ] && [ "$BACKUP_COMMAND" = "--stanza=db --repo=1 --type=full --start-fast=y" ]; then
2323
exit 0
2424
fi
2525
sleep 4
26+
i=$(( i + 1 ))
2627
done
2728
2829
exit 1

testing/kuttl/e2e/backup/06--backup-with-multiple-flags.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ commands:
66
77
echo "RESULT from taking backup: ${RESULT}"
88
9-
if [[ -n $RESULT && "$RESULT" == "postgresclusters/backup-cluster backup initiated" ]]; then
9+
if [ -n "$RESULT" ] && [ "$RESULT" = "postgresclusters/backup-cluster backup initiated" ]; then
1010
exit 0
1111
fi
1212

testing/kuttl/e2e/backup/07--check-pod-command-with-multiple-flags.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ commands:
66
- script: |
77
# Retry getting a successful pod from the most recent backup job.
88
# If that pod doesn't have the expected command, sleep and retry
9-
for i in {1..10}; do
9+
i=1; while [ $i -le 10 ]; do
1010
BACKUP_COMMAND=$(
1111
kubectl get pod --namespace "${NAMESPACE}" \
1212
--output jsonpath="{.items[*].spec.containers[*].env[?(@.name=='COMMAND_OPTS')].value}" \
@@ -19,10 +19,11 @@ commands:
1919
2020
echo "BACKUP_COMMAND found ${BACKUP_COMMAND}"
2121
22-
if [[ -n $BACKUP_COMMAND && "$BACKUP_COMMAND" == "--stanza=db --repo=1 --type=full --start-fast=y" ]]; then
22+
if [ -n "$BACKUP_COMMAND" ] && [ "$BACKUP_COMMAND" = "--stanza=db --repo=1 --type=full --start-fast=y" ]; then
2323
exit 0
2424
fi
2525
sleep 4
26+
i=$(( i + 1 ))
2627
done
2728
2829
exit 1

testing/kuttl/e2e/backup/08--backup-with-just-trigger.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: kuttl.dev/v1beta1
22
kind: TestStep
33
commands:
4-
- script: |
4+
- script: |
55
pgbackrest_backup_annotation() {
66
kubectl get --namespace "${NAMESPACE}" postgrescluster/backup-cluster \
77
--output 'go-template={{ index .metadata.annotations "postgres-operator.crunchydata.com/pgbackrest-backup" }}'
@@ -14,13 +14,13 @@ commands:
1414
CURRENT=$(pgbackrest_backup_annotation)
1515
1616
if [ "${CURRENT}" = "${PRIOR}" ]; then
17-
printf 'Expected annotation to change, got %q\n' "${CURRENT}"
17+
printf 'Expected annotation to change, got %s\n' "${CURRENT}"
1818
exit 1
1919
fi
2020
2121
echo "RESULT from taking backup: ${RESULT}"
2222
23-
if [[ -n $RESULT && "$RESULT" == "postgresclusters/backup-cluster backup initiated" ]]; then
23+
if [ -n "$RESULT" ] && [ "$RESULT" = "postgresclusters/backup-cluster backup initiated" ]; then
2424
exit 0
2525
fi
2626

testing/kuttl/e2e/backup/11--backup-with-new-flag.yaml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,17 @@ commands:
1212
exit 1
1313
fi
1414
15-
if [[ "${RESULT,,}" != *conflict* || "${RESULT}" != *repoName* ]]; then
16-
printf 'Expected conflict on repoName, got %q\n' "${RESULT}"
17-
exit 1
15+
# get lowercase for result
16+
lower=$(echo "$RESULT" | tr '[:upper:]' '[:lower:]')
17+
18+
# check for the substring using POSIX compliant parameter-expansion.
19+
# If the variable contains the substring after the '%', it does not return
20+
# the entire string content, leading to a mismatch. If both substrings are found,
21+
# the test passes.
22+
# - https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html
23+
if [ "${lower}" != "${lower%"conflict"*}" ] && [ "${RESULT}" != "${RESULT%"repoName"*}" ]; then
24+
exit 0
1825
fi
26+
27+
printf 'Expected conflict on repoName, got %s\n' "${RESULT}"
28+
exit 1

testing/kuttl/e2e/backup/12--backup-with-force-conflicts.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ commands:
1616
CURRENT=$(pgbackrest_backup_annotation)
1717
1818
if [ "${CURRENT}" = "${PRIOR}" ]; then
19-
printf 'Expected annotation to change, got %q' "${CURRENT}"
19+
printf 'Expected annotation to change, got %s' "${CURRENT}"
2020
exit 1
2121
fi
2222
2323
echo "RESULT from taking backup: ${RESULT}"
2424
25-
if [[ -n $RESULT && "$RESULT" == "postgresclusters/backup-cluster backup initiated" ]]; then
25+
if [ -n "$RESULT" ] && [ "$RESULT" = "postgresclusters/backup-cluster backup initiated" ]; then
2626
exit 0
2727
fi
2828

0 commit comments

Comments
 (0)