Skip to content

K8SPG-724: fix extension reinstall #1228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions build/postgres-operator/install-extensions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,6 @@ if [[ -n $STORAGE_ENDPOINT ]]; then
args+=(-endpoint "$STORAGE_ENDPOINT")
fi

for key in "${extensions[@]}"; do
if [ -f "${PGDATA_EXTENSIONS}"/"${key}".installed ]; then
echo "Extension ${key} already installed"
continue
fi

echo "Installing extension: ${key}"
/usr/local/bin/extension-installer \
"${args[@]}" \
-key "${key}" \
-install
done

for installed in "${PGDATA_EXTENSIONS}"/*.installed; do
filename=$(basename -- "${installed}")
key=${filename%.*}
Expand All @@ -45,3 +32,16 @@ for installed in "${PGDATA_EXTENSIONS}"/*.installed; do
rm -f "${installed}"
fi
done

for key in "${extensions[@]}"; do
if [ -f "${PGDATA_EXTENSIONS}"/"${key}".installed ]; then
echo "Extension ${key} already installed"
continue
fi

echo "Installing extension: ${key}"
/usr/local/bin/extension-installer \
"${args[@]}" \
-key "${key}" \
-install
done
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ spec:
dynamicConfiguration:
postgresql:
parameters:
shared_preload_libraries: pg_cron
shared_preload_libraries: pg_cron
4 changes: 1 addition & 3 deletions e2e-tests/tests/custom-extensions/06-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ spec:
- name: postgres-startup
- command:
- /usr/local/bin/relocate-extensions.sh
env:
- name: PG_VERSION
resources: {}
volumeMounts:
- mountPath: /pgdata
Expand Down Expand Up @@ -58,7 +56,7 @@ spec:
- /usr/local/bin/init-entrypoint.sh
- name: nss-wrapper-init
status:
observedGeneration: 3
observedGeneration: 2
replicas: 1
updatedReplicas: 1
readyReplicas: 1
Expand Down
14 changes: 14 additions & 0 deletions e2e-tests/tests/custom-extensions/06-update-pg_cron.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: pgv2.percona.com/v2
kind: PerconaPGCluster
metadata:
name: custom-extensions
spec:
extensions:
custom:
- name: pg_cron
version: 1.6.4
patroni:
dynamicConfiguration:
postgresql:
parameters:
shared_preload_libraries: pg_cron
28 changes: 28 additions & 0 deletions e2e-tests/tests/custom-extensions/07-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,36 @@ spec:
- name: postgres-startup
- command:
- /usr/local/bin/relocate-extensions.sh
resources: {}
volumeMounts:
- mountPath: /pgdata
name: postgres-data
- mountPath: /tmp
name: tmp
- command:
- /usr/local/bin/install-extensions.sh
env:
- name: STORAGE_TYPE
value: s3
- name: STORAGE_ENDPOINT
- name: STORAGE_REGION
value: eu-central-1
- name: STORAGE_BUCKET
value: pg-extensions
- name: INSTALL_EXTENSIONS
- name: PG_VERSION
- name: PGDATA_EXTENSIONS
envFrom:
- secretRef:
name: aws-s3-secret
resources: {}
volumeMounts:
- mountPath: /pgdata
name: postgres-data
- name: postgres-data
- name: postgres-data
- mountPath: /tmp
name: tmp
- command:
- /usr/local/bin/init-entrypoint.sh
- name: nss-wrapper-init
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ commands:
set -o xtrace

source ../../functions

wait_cluster_consistency custom-extensions

restart_pg_pods custom-extensions instance1
Expand Down
3 changes: 2 additions & 1 deletion e2e-tests/tests/custom-extensions/08-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ timeout: 30
kind: ConfigMap
apiVersion: v1
metadata:
name: 10-check-extensions
name: 08-check-extensions
data:
data: |2-
pg_cron
pg_stat_monitor
pgaudit
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ commands:

data=$(kubectl -n ${NAMESPACE} exec $(get_client_pod) -- psql -v ON_ERROR_STOP=1 -t -q postgres://postgres:$(get_psql_user_pass custom-extensions-pguser-postgres)@$(get_psql_user_host custom-extensions-pguser-postgres) -c "\c postgres" -c "select name from pg_available_extensions where name in ('pg_cron','pg_stat_monitor','pgaudit') order by name")

kubectl create configmap -n "${NAMESPACE}" 10-check-extensions --from-literal=data="${data}"
kubectl create configmap -n "${NAMESPACE}" 08-check-extensions --from-literal=data="${data}"
87 changes: 78 additions & 9 deletions e2e-tests/tests/custom-extensions/09-assert.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,82 @@
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
timeout: 30
timeout: 300
---
kind: ConfigMap
apiVersion: v1
kind: StatefulSet
apiVersion: apps/v1
metadata:
name: 11-check-extensions
data:
data: |2-
pg_stat_monitor
pgaudit
plpgsql
labels:
postgres-operator.crunchydata.com/cluster: custom-extensions
postgres-operator.crunchydata.com/data: postgres
postgres-operator.crunchydata.com/instance-set: instance1
ownerReferences:
- apiVersion: postgres-operator.crunchydata.com/v1beta1
kind: PostgresCluster
name: custom-extensions
controller: true
blockOwnerDeletion: true
spec:
template:
spec:
initContainers:
- name: postgres-startup
- command:
- /usr/local/bin/relocate-extensions.sh
env:
- name: PG_VERSION
resources: {}
volumeMounts:
- mountPath: /pgdata
name: postgres-data
- mountPath: /tmp
name: tmp
- command:
- /usr/local/bin/install-extensions.sh
env:
- name: STORAGE_TYPE
value: s3
- name: STORAGE_ENDPOINT
- name: STORAGE_REGION
value: eu-central-1
- name: STORAGE_BUCKET
value: pg-extensions
- name: INSTALL_EXTENSIONS
- name: PG_VERSION
- name: PGDATA_EXTENSIONS
envFrom:
- secretRef:
name: aws-s3-secret
resources: {}
volumeMounts:
- mountPath: /pgdata
name: postgres-data
- name: postgres-data
- name: postgres-data
- mountPath: /tmp
name: tmp
- command:
- /usr/local/bin/init-entrypoint.sh
- name: nss-wrapper-init
status:
observedGeneration: 4
replicas: 1
updatedReplicas: 1
readyReplicas: 1
availableReplicas: 1
---
apiVersion: pgv2.percona.com/v2
kind: PerconaPGCluster
metadata:
name: custom-extensions
status:
pgbouncer:
ready: 3
size: 3
postgres:
instances:
- name: instance1
ready: 3
size: 3
ready: 3
size: 3
state: ready
52 changes: 52 additions & 0 deletions e2e-tests/tests/custom-extensions/10-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
timeout: 120
---
kind: StatefulSet
apiVersion: apps/v1
metadata:
labels:
postgres-operator.crunchydata.com/cluster: custom-extensions
postgres-operator.crunchydata.com/data: postgres
postgres-operator.crunchydata.com/instance-set: instance1
ownerReferences:
- apiVersion: postgres-operator.crunchydata.com/v1beta1
kind: PostgresCluster
name: custom-extensions
controller: true
blockOwnerDeletion: true
spec:
template:
spec:
initContainers:
- name: postgres-startup
- command:
- /usr/local/bin/relocate-extensions.sh
- command:
- /usr/local/bin/install-extensions.sh
- command:
- /usr/local/bin/init-entrypoint.sh
- name: nss-wrapper-init
status:
observedGeneration: 4
replicas: 1
updatedReplicas: 1
readyReplicas: 1
availableReplicas: 1
---
apiVersion: pgv2.percona.com/v2
kind: PerconaPGCluster
metadata:
name: custom-extensions
status:
pgbouncer:
ready: 3
size: 3
postgres:
instances:
- name: instance1
ready: 3
size: 3
ready: 3
size: 3
state: ready
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ commands:
set -o xtrace

source ../../functions

wait_cluster_consistency custom-extensions

restart_pg_pods custom-extensions instance1
Expand Down
12 changes: 12 additions & 0 deletions e2e-tests/tests/custom-extensions/11-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
timeout: 30
---
kind: ConfigMap
apiVersion: v1
metadata:
name: 11-check-extensions
data:
data: |2-
pg_stat_monitor
pgaudit
13 changes: 13 additions & 0 deletions e2e-tests/tests/custom-extensions/11-check-extensions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
timeout: 30
commands:
- script: |-
set -o errexit
set -o xtrace

source ../../functions

data=$(kubectl -n ${NAMESPACE} exec $(get_client_pod) -- psql -v ON_ERROR_STOP=1 -t -q postgres://postgres:$(get_psql_user_pass custom-extensions-pguser-postgres)@$(get_psql_user_host custom-extensions-pguser-postgres) -c "\c postgres" -c "select name from pg_available_extensions where name in ('pg_cron','pg_stat_monitor','pgaudit') order by name")

kubectl create configmap -n "${NAMESPACE}" 11-check-extensions --from-literal=data="${data}"
13 changes: 13 additions & 0 deletions e2e-tests/tests/custom-extensions/12-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
timeout: 30
---
kind: ConfigMap
apiVersion: v1
metadata:
name: 12-check-extensions
data:
data: |2-
pg_stat_monitor
pgaudit
plpgsql
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ commands:

data=$(kubectl -n ${NAMESPACE} exec $(get_client_pod) -- psql -v ON_ERROR_STOP=1 -t -q postgres://postgres:$(get_psql_user_pass custom-extensions-pguser-postgres)@$(get_psql_user_host custom-extensions-pguser-postgres) -c "\c postgres" -c "select extname from pg_extension order by extname")

kubectl create configmap -n "${NAMESPACE}" 11-check-extensions --from-literal=data="${data}"
kubectl create configmap -n "${NAMESPACE}" 12-check-extensions --from-literal=data="${data}"
Loading