Skip to content

Commit 2f57481

Browse files
K8SPG-836: Add separate check for ppg13&14 grantPublicSchemaAccess (#1332)
* Do not test grantPublicSchemaAccess for PPG < 15 * Improve skipping code * Add check for the error instead of skipping * Assign PG_VER based on POSTGRES image if not set * Update e2e-tests/vars.sh Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * update vars --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent d8248fe commit 2f57481

File tree

4 files changed

+49
-27
lines changed

4 files changed

+49
-27
lines changed

e2e-tests/tests/users/13-add-custom-user-with-public-schema-access.yaml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ commands:
77
set -o xtrace
88
99
source ../../functions
10-
11-
kubectl -n ${NAMESPACE} patch perconapgcluster/${test_name} --type=json -p '[{"op":"add", "path":"/spec/autoCreateUserSchema","value":true},{"op":"add", "path":"/spec/users","value":[{"name":"chico","databases":["spain"],"password":{"type":"ASCII"},"secretName":"chico-credentials", "grantPublicSchemaAccess": true}]}]'
12-
sleep 10
10+
if [[ $PG_VER < 15 ]]; then
11+
# grantPublicSchemaAccess is not supported before PPG15. Checking that applying patch fails."
12+
set +o errexit
13+
patch_output=$(kubectl -n ${NAMESPACE} patch perconapgcluster/${test_name} --type=json -p '[{"op":"add", "path":"/spec/autoCreateUserSchema","value":true},{"op":"add", "path":"/spec/users","value":[{"name":"chico","databases":["spain"],"password":{"type":"ASCII"},"secretName":"chico-credentials", "grantPublicSchemaAccess": true}]}]' 2>&1)
14+
set -o errexit
15+
if [[ $patch_output != 'The PerconaPGCluster "users" is invalid: spec: Invalid value: "object": PostgresVersion must be >= 15 if grantPublicSchemaAccess exists and is true' ]]; then
16+
echo "grantPublicSchemaAccess is not supported before PPG15. Current PG_VER = $PG_VER but the patch was applied"
17+
exit 1
18+
fi
19+
else
20+
kubectl -n ${NAMESPACE} patch perconapgcluster/${test_name} --type=json -p '[{"op":"add", "path":"/spec/autoCreateUserSchema","value":true},{"op":"add", "path":"/spec/users","value":[{"name":"chico","databases":["spain"],"password":{"type":"ASCII"},"secretName":"chico-credentials", "grantPublicSchemaAccess": true}]}]'
21+
sleep 10
22+
fi

e2e-tests/tests/users/14-write-data-to-custom-db.yaml

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,19 @@ commands:
77
88
source ../../functions
99
10-
password=$(get_psql_user_pass chico-credentials)
11-
user='chico'
12-
db_name='spain'
13-
schema='public'
14-
hostname=$(get_pgbouncer_host chico-credentials)
10+
if [[ $PG_VER < 15 ]]; then
11+
echo "grantPublicSchemaAccess is not supported before PPG15. Current PG_VER = $PG_VER. Skipping check"
12+
else
13+
password=$(get_psql_user_pass chico-credentials)
14+
user='chico'
15+
db_name='spain'
16+
schema='public'
17+
hostname=$(get_pgbouncer_host chico-credentials)
1518
16-
run_psql \
17-
'SET search_path TO public;CREATE TABLE IF NOT EXISTS customApp (id int PRIMARY KEY);' \
18-
"-h $hostname -U $user -d $db_name" "$password"
19-
run_psql \
20-
"INSERT INTO $schema.customApp (id) VALUES (100500)" \
21-
"-h $hostname -U $user -d $db_name" "$password"
22-
19+
run_psql \
20+
'SET search_path TO public;CREATE TABLE IF NOT EXISTS customApp (id int PRIMARY KEY);' \
21+
"-h $hostname -U $user -d $db_name" "$password"
22+
run_psql \
23+
"INSERT INTO $schema.customApp (id) VALUES (100500)" \
24+
"-h $hostname -U $user -d $db_name" "$password"
25+
fi

e2e-tests/tests/users/15-read-from-primary-custom-db.yaml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ commands:
77
set -o xtrace
88
99
source ../../functions
10+
if [[ $PG_VER < 15 ]]; then
11+
echo "grantPublicSchemaAccess is not supported before PPG15. Current PG_VER = $PG_VER. Creating dummy configmap to pass check"
12+
kubectl create configmap -n "${NAMESPACE}" 10-read-from-primary-custom-db --from-literal=data=' 100500'
13+
else
14+
password=$(get_psql_user_pass chico-credentials)
15+
user='chico'
16+
db_name='spain'
17+
schema='public'
18+
hostname=$(get_pgbouncer_host chico-credentials)
1019
11-
password=$(get_psql_user_pass chico-credentials)
12-
user='chico'
13-
db_name='spain'
14-
schema='public'
15-
hostname=$(get_pgbouncer_host chico-credentials)
20+
data=$(run_psql "SELECT * from $schema.customApp;" "-h $hostname -U $user -d $db_name" "$password")
1621
17-
data=$(run_psql "SELECT * from $schema.customApp;" "-h $hostname -U $user -d $db_name" "$password")
18-
19-
kubectl create configmap -n "${NAMESPACE}" 10-read-from-primary-custom-db --from-literal=data="${data}"
22+
kubectl create configmap -n "${NAMESPACE}" 10-read-from-primary-custom-db --from-literal=data="${data}"
23+
fi

e2e-tests/vars.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ fi
2323

2424
export IMAGE_BASE=${IMAGE_BASE:-"perconalab/percona-postgresql-operator"}
2525
export IMAGE=${IMAGE:-"${IMAGE_BASE}:${VERSION}"}
26-
export PG_VER="${PG_VER:-17}"
26+
if [[ ! $PG_VER && $IMAGE_POSTGRESQL ]]; then
27+
pg_version_value=$(echo "$IMAGE_POSTGRESQL" | sed -E 's/.*:(.*ppg)?([0-9]+).*/\2/')
28+
export PG_VER="${pg_version_value}"
29+
else
30+
export PG_VER="${PG_VER:-17}"
31+
fi
2732
export IMAGE_PGBOUNCER=${IMAGE_PGBOUNCER:-"${IMAGE_BASE}:main-pgbouncer$PG_VER"}
2833
export IMAGE_POSTGRESQL=${IMAGE_POSTGRESQL:-"perconalab/percona-distribution-postgresql:$PG_VER"}
2934
export IMAGE_BACKREST=${IMAGE_BACKREST:-"${IMAGE_BASE}:main-pgbackrest$PG_VER"}
@@ -49,10 +54,10 @@ for var in $(printenv | grep -E '^IMAGE' | awk -F'=' '{print $1}'); do
4954
fi
5055
if [[ $var_value == percona/* || $var_value == perconalab/* ]]; then
5156
new_value="${REGISTRY_NAME_FULL}${var_value}"
52-
export "$var=$new_value"
53-
echo $var=$new_value
57+
export "$var"="$new_value"
58+
echo "$var"="$new_value"
5459
fi
55-
echo $IMAGE
60+
echo "$IMAGE"
5661
done
5762

5863
# shellcheck disable=SC2034

0 commit comments

Comments
 (0)