From 3d7ca1f839309689d9f6b6e15f937bd02b879863 Mon Sep 17 00:00:00 2001 From: Viacheslav Sarzhan Date: Fri, 20 Dec 2024 00:08:29 +0200 Subject: [PATCH 1/2] CLOUD-727 bump golang.org/x/net to 0.33.0 (#990) --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index e5cc9c994..b06a17905 100644 --- a/go.mod +++ b/go.mod @@ -111,7 +111,7 @@ require ( go.opentelemetry.io/proto/otlp v1.4.0 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect - golang.org/x/net v0.32.0 // indirect + golang.org/x/net v0.33.0 // indirect golang.org/x/oauth2 v0.24.0 // indirect golang.org/x/sync v0.10.0 // indirect golang.org/x/sys v0.28.0 // indirect diff --git a/go.sum b/go.sum index d8f4f1d46..cc989da59 100644 --- a/go.sum +++ b/go.sum @@ -293,8 +293,8 @@ golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI= -golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs= +golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I= +golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.24.0 h1:KTBBxWqUa0ykRPLtV69rRto9TLXcqYkeswu48x/gvNE= golang.org/x/oauth2 v0.24.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= From 2dddc34e7ee06ed83537fb0403e5b9bbeb65be05 Mon Sep 17 00:00:00 2001 From: Inel Pandzic Date: Fri, 20 Dec 2024 14:04:35 +0100 Subject: [PATCH 2/2] K8SPG-634: Auto schema creation (#966) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add AutoCreateUserSchema field. * Generate CRDs. * Fix nil pointer. * Update cr.yaml. * Fix CR * Update users e2e test. * Enable autoCreateUserSchema by default. * Enable AutoCreateUserSchema properly. * Fix tests. * Test updated. * Fix panic * Update upgrade-consistency test. --------- Co-authored-by: Viacheslav Sarzhan Co-authored-by: Ege Güneş --- .../pgv2.percona.com_perconapgclusters.yaml | 5 + .../pgv2.percona.com_perconapgclusters.yaml | 5 + deploy/bundle.yaml | 5 + deploy/cr.yaml | 2 + deploy/crd.yaml | 5 + deploy/cw-bundle.yaml | 5 + .../tests/upgrade-consistency/01-assert.yaml | 2 +- .../01-create-cluster.yaml | 2 +- .../tests/upgrade-consistency/02-assert.yaml | 2 +- .../upgrade-consistency/02-patch-cluster.yaml | 2 +- .../tests/upgrade-consistency/03-assert.yaml | 2 +- .../upgrade-consistency/03-patch-cluster.yaml | 2 +- .../tests/upgrade-consistency/04-assert.yaml | 135 ------------------ .../upgrade-consistency/04-patch-cluster.yaml | 16 --- .../tests/upgrade-consistency/05-assert.yaml | 135 ------------------ .../upgrade-consistency/05-patch-cluster.yaml | 16 --- e2e-tests/tests/users/07-add-custom-user.yaml | 2 +- .../users/08-write-data-to-custom-db.yaml | 5 +- .../users/09-read-from-primary-custom-db.yaml | 3 +- .../users/11-write-data-to-custom-db.yaml | 3 +- .../users/12-read-from-primary-custom-db.yaml | 3 +- .../testdata/sidecar-resources-cr.yaml | 2 +- .../v2/perconapgcluster_types.go | 15 ++ .../v2/zz_generated.deepcopy.go | 5 + 24 files changed, 64 insertions(+), 315 deletions(-) delete mode 100644 e2e-tests/tests/upgrade-consistency/04-assert.yaml delete mode 100644 e2e-tests/tests/upgrade-consistency/04-patch-cluster.yaml delete mode 100644 e2e-tests/tests/upgrade-consistency/05-assert.yaml delete mode 100644 e2e-tests/tests/upgrade-consistency/05-patch-cluster.yaml diff --git a/build/crd/percona/generated/pgv2.percona.com_perconapgclusters.yaml b/build/crd/percona/generated/pgv2.percona.com_perconapgclusters.yaml index 6c43c214c..11bce9ab5 100644 --- a/build/crd/percona/generated/pgv2.percona.com_perconapgclusters.yaml +++ b/build/crd/percona/generated/pgv2.percona.com_perconapgclusters.yaml @@ -56,6 +56,11 @@ spec: type: object spec: properties: + autoCreateUserSchema: + description: |- + Whether or not the cluster has schemas automatically created for the user + defined in `spec.users` for all of the databases listed for that user. + type: boolean backups: description: PostgreSQL backup configuration properties: diff --git a/config/crd/bases/pgv2.percona.com_perconapgclusters.yaml b/config/crd/bases/pgv2.percona.com_perconapgclusters.yaml index ccc25ad0a..fa47a47bf 100644 --- a/config/crd/bases/pgv2.percona.com_perconapgclusters.yaml +++ b/config/crd/bases/pgv2.percona.com_perconapgclusters.yaml @@ -462,6 +462,11 @@ spec: type: object spec: properties: + autoCreateUserSchema: + description: |- + Whether or not the cluster has schemas automatically created for the user + defined in `spec.users` for all of the databases listed for that user. + type: boolean backups: description: PostgreSQL backup configuration properties: diff --git a/deploy/bundle.yaml b/deploy/bundle.yaml index ba8aee72b..6014ef4ee 100644 --- a/deploy/bundle.yaml +++ b/deploy/bundle.yaml @@ -755,6 +755,11 @@ spec: type: object spec: properties: + autoCreateUserSchema: + description: |- + Whether or not the cluster has schemas automatically created for the user + defined in `spec.users` for all of the databases listed for that user. + type: boolean backups: description: PostgreSQL backup configuration properties: diff --git a/deploy/cr.yaml b/deploy/cr.yaml index b96283517..0be73896e 100644 --- a/deploy/cr.yaml +++ b/deploy/cr.yaml @@ -28,6 +28,8 @@ spec: # openshift: true +# autoCreateUserSchema: true + # users: # - name: rhino # databases: diff --git a/deploy/crd.yaml b/deploy/crd.yaml index f891f67fd..ec11863d5 100644 --- a/deploy/crd.yaml +++ b/deploy/crd.yaml @@ -755,6 +755,11 @@ spec: type: object spec: properties: + autoCreateUserSchema: + description: |- + Whether or not the cluster has schemas automatically created for the user + defined in `spec.users` for all of the databases listed for that user. + type: boolean backups: description: PostgreSQL backup configuration properties: diff --git a/deploy/cw-bundle.yaml b/deploy/cw-bundle.yaml index 91b167246..8b237e5f2 100644 --- a/deploy/cw-bundle.yaml +++ b/deploy/cw-bundle.yaml @@ -755,6 +755,11 @@ spec: type: object spec: properties: + autoCreateUserSchema: + description: |- + Whether or not the cluster has schemas automatically created for the user + defined in `spec.users` for all of the databases listed for that user. + type: boolean backups: description: PostgreSQL backup configuration properties: diff --git a/e2e-tests/tests/upgrade-consistency/01-assert.yaml b/e2e-tests/tests/upgrade-consistency/01-assert.yaml index 26dcf4571..c7978a131 100644 --- a/e2e-tests/tests/upgrade-consistency/01-assert.yaml +++ b/e2e-tests/tests/upgrade-consistency/01-assert.yaml @@ -122,7 +122,7 @@ kind: PerconaPGCluster metadata: name: upgrade-consistency spec: - crVersion: 2.1.0 + crVersion: 2.4.0 status: pgbouncer: ready: 3 diff --git a/e2e-tests/tests/upgrade-consistency/01-create-cluster.yaml b/e2e-tests/tests/upgrade-consistency/01-create-cluster.yaml index 6bffc104b..cfb4cf562 100644 --- a/e2e-tests/tests/upgrade-consistency/01-create-cluster.yaml +++ b/e2e-tests/tests/upgrade-consistency/01-create-cluster.yaml @@ -10,5 +10,5 @@ commands: get_cr \ | yq eval ' - .spec.crVersion="2.1.0"' - \ + .spec.crVersion="2.4.0"' - \ | kubectl -n "${NAMESPACE}" apply -f - diff --git a/e2e-tests/tests/upgrade-consistency/02-assert.yaml b/e2e-tests/tests/upgrade-consistency/02-assert.yaml index 3b9845d84..9b1857157 100644 --- a/e2e-tests/tests/upgrade-consistency/02-assert.yaml +++ b/e2e-tests/tests/upgrade-consistency/02-assert.yaml @@ -120,7 +120,7 @@ kind: PerconaPGCluster metadata: name: upgrade-consistency spec: - crVersion: 2.2.0 + crVersion: 2.5.0 status: pgbouncer: ready: 3 diff --git a/e2e-tests/tests/upgrade-consistency/02-patch-cluster.yaml b/e2e-tests/tests/upgrade-consistency/02-patch-cluster.yaml index e63465fb2..a5f90f450 100644 --- a/e2e-tests/tests/upgrade-consistency/02-patch-cluster.yaml +++ b/e2e-tests/tests/upgrade-consistency/02-patch-cluster.yaml @@ -10,7 +10,7 @@ commands: get_cr \ | yq eval ' - .spec.crVersion="2.2.0"' - \ + .spec.crVersion="2.5.0"' - \ | kubectl -n "${NAMESPACE}" apply -f - sleep 10 diff --git a/e2e-tests/tests/upgrade-consistency/03-assert.yaml b/e2e-tests/tests/upgrade-consistency/03-assert.yaml index 0216e2395..9bfd8e1c9 100644 --- a/e2e-tests/tests/upgrade-consistency/03-assert.yaml +++ b/e2e-tests/tests/upgrade-consistency/03-assert.yaml @@ -120,7 +120,7 @@ kind: PerconaPGCluster metadata: name: upgrade-consistency spec: - crVersion: 2.3.0 + crVersion: 2.6.0 status: pgbouncer: ready: 3 diff --git a/e2e-tests/tests/upgrade-consistency/03-patch-cluster.yaml b/e2e-tests/tests/upgrade-consistency/03-patch-cluster.yaml index ec35b72a9..3c2c0cb7b 100644 --- a/e2e-tests/tests/upgrade-consistency/03-patch-cluster.yaml +++ b/e2e-tests/tests/upgrade-consistency/03-patch-cluster.yaml @@ -10,7 +10,7 @@ commands: get_cr \ | yq eval ' - .spec.crVersion="2.3.0"' - \ + .spec.crVersion="2.6.0"' - \ | kubectl -n "${NAMESPACE}" apply -f - sleep 10 diff --git a/e2e-tests/tests/upgrade-consistency/04-assert.yaml b/e2e-tests/tests/upgrade-consistency/04-assert.yaml deleted file mode 100644 index 9d5c3124f..000000000 --- a/e2e-tests/tests/upgrade-consistency/04-assert.yaml +++ /dev/null @@ -1,135 +0,0 @@ -apiVersion: kuttl.dev/v1beta1 -kind: TestAssert -timeout: 240 ---- -kind: StatefulSet -apiVersion: apps/v1 -metadata: - name: upgrade-consistency-repo-host - labels: - postgres-operator.crunchydata.com/cluster: upgrade-consistency - postgres-operator.crunchydata.com/data: pgbackrest - postgres-operator.crunchydata.com/pgbackrest: '' - postgres-operator.crunchydata.com/pgbackrest-dedicated: '' - ownerReferences: - - apiVersion: postgres-operator.crunchydata.com/v1beta1 - kind: PostgresCluster - name: upgrade-consistency - controller: true - blockOwnerDeletion: true -status: - observedGeneration: 4 - replicas: 1 - readyReplicas: 1 - updatedReplicas: 1 - collisionCount: 0 ---- -kind: StatefulSet -apiVersion: apps/v1 -metadata: - labels: - postgres-operator.crunchydata.com/cluster: upgrade-consistency - postgres-operator.crunchydata.com/data: postgres - postgres-operator.crunchydata.com/instance-set: instance1 - ownerReferences: - - apiVersion: postgres-operator.crunchydata.com/v1beta1 - kind: PostgresCluster - name: upgrade-consistency - controller: true - blockOwnerDeletion: true -status: - observedGeneration: 4 - replicas: 1 - readyReplicas: 1 - updatedReplicas: 1 - collisionCount: 0 ---- -kind: Deployment -apiVersion: apps/v1 -metadata: - name: upgrade-consistency-pgbouncer - labels: - postgres-operator.crunchydata.com/cluster: upgrade-consistency - postgres-operator.crunchydata.com/role: pgbouncer - annotations: - deployment.kubernetes.io/revision: '4' - ownerReferences: - - apiVersion: postgres-operator.crunchydata.com/v1beta1 - kind: PostgresCluster - name: upgrade-consistency - controller: true - blockOwnerDeletion: true -status: - observedGeneration: 4 - replicas: 3 - updatedReplicas: 3 - readyReplicas: 3 ---- -kind: Job -apiVersion: batch/v1 -metadata: - labels: - postgres-operator.crunchydata.com/cluster: upgrade-consistency - postgres-operator.crunchydata.com/pgbackrest: '' - postgres-operator.crunchydata.com/pgbackrest-backup: replica-create - postgres-operator.crunchydata.com/pgbackrest-repo: repo1 - ownerReferences: - - apiVersion: pgv2.percona.com/v2 - kind: PerconaPGBackup - controller: true - blockOwnerDeletion: true -status: - succeeded: 1 ---- -apiVersion: postgres-operator.crunchydata.com/v1beta1 -kind: PostgresCluster -metadata: - name: upgrade-consistency - ownerReferences: - - apiVersion: pgv2.percona.com/v2 - kind: PerconaPGCluster - name: upgrade-consistency - controller: true - blockOwnerDeletion: true - finalizers: - - postgres-operator.crunchydata.com/finalizer -status: - instances: - - name: instance1 - readyReplicas: 3 - replicas: 3 - updatedReplicas: 3 - observedGeneration: 4 - pgbackrest: - repoHost: - apiVersion: apps/v1 - kind: StatefulSet - ready: true - repos: - - bound: true - name: repo1 - replicaCreateBackupComplete: true - stanzaCreated: true - proxy: - pgBouncer: - readyReplicas: 3 - replicas: 3 ---- -apiVersion: pgv2.percona.com/v2 -kind: PerconaPGCluster -metadata: - name: upgrade-consistency -spec: - crVersion: 2.4.0 -status: - pgbouncer: - ready: 3 - size: 3 - postgres: - instances: - - name: instance1 - ready: 3 - size: 3 - ready: 3 - size: 3 - state: ready diff --git a/e2e-tests/tests/upgrade-consistency/04-patch-cluster.yaml b/e2e-tests/tests/upgrade-consistency/04-patch-cluster.yaml deleted file mode 100644 index 16de5cdd9..000000000 --- a/e2e-tests/tests/upgrade-consistency/04-patch-cluster.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: kuttl.dev/v1beta1 -kind: TestStep -timeout: 30 -commands: - - script: |- - set -o errexit - set -o xtrace - - source ../../functions - - get_cr \ - | yq eval ' - .spec.crVersion="2.4.0"' - \ - | kubectl -n "${NAMESPACE}" apply -f - - - sleep 10 diff --git a/e2e-tests/tests/upgrade-consistency/05-assert.yaml b/e2e-tests/tests/upgrade-consistency/05-assert.yaml deleted file mode 100644 index 4a8aef6e2..000000000 --- a/e2e-tests/tests/upgrade-consistency/05-assert.yaml +++ /dev/null @@ -1,135 +0,0 @@ -apiVersion: kuttl.dev/v1beta1 -kind: TestAssert -timeout: 240 ---- -kind: StatefulSet -apiVersion: apps/v1 -metadata: - name: upgrade-consistency-repo-host - labels: - postgres-operator.crunchydata.com/cluster: upgrade-consistency - postgres-operator.crunchydata.com/data: pgbackrest - postgres-operator.crunchydata.com/pgbackrest: '' - postgres-operator.crunchydata.com/pgbackrest-dedicated: '' - ownerReferences: - - apiVersion: postgres-operator.crunchydata.com/v1beta1 - kind: PostgresCluster - name: upgrade-consistency - controller: true - blockOwnerDeletion: true -status: - observedGeneration: 5 - replicas: 1 - readyReplicas: 1 - updatedReplicas: 1 - collisionCount: 0 ---- -kind: StatefulSet -apiVersion: apps/v1 -metadata: - labels: - postgres-operator.crunchydata.com/cluster: upgrade-consistency - postgres-operator.crunchydata.com/data: postgres - postgres-operator.crunchydata.com/instance-set: instance1 - ownerReferences: - - apiVersion: postgres-operator.crunchydata.com/v1beta1 - kind: PostgresCluster - name: upgrade-consistency - controller: true - blockOwnerDeletion: true -status: - observedGeneration: 5 - replicas: 1 - readyReplicas: 1 - updatedReplicas: 1 - collisionCount: 0 ---- -kind: Deployment -apiVersion: apps/v1 -metadata: - name: upgrade-consistency-pgbouncer - labels: - postgres-operator.crunchydata.com/cluster: upgrade-consistency - postgres-operator.crunchydata.com/role: pgbouncer - annotations: - deployment.kubernetes.io/revision: '5' - ownerReferences: - - apiVersion: postgres-operator.crunchydata.com/v1beta1 - kind: PostgresCluster - name: upgrade-consistency - controller: true - blockOwnerDeletion: true -status: - observedGeneration: 5 - replicas: 3 - updatedReplicas: 3 - readyReplicas: 3 ---- -kind: Job -apiVersion: batch/v1 -metadata: - labels: - postgres-operator.crunchydata.com/cluster: upgrade-consistency - postgres-operator.crunchydata.com/pgbackrest: '' - postgres-operator.crunchydata.com/pgbackrest-backup: replica-create - postgres-operator.crunchydata.com/pgbackrest-repo: repo1 - ownerReferences: - - apiVersion: pgv2.percona.com/v2 - kind: PerconaPGBackup - controller: true - blockOwnerDeletion: true -status: - succeeded: 1 ---- -apiVersion: postgres-operator.crunchydata.com/v1beta1 -kind: PostgresCluster -metadata: - name: upgrade-consistency - ownerReferences: - - apiVersion: pgv2.percona.com/v2 - kind: PerconaPGCluster - name: upgrade-consistency - controller: true - blockOwnerDeletion: true - finalizers: - - postgres-operator.crunchydata.com/finalizer -status: - instances: - - name: instance1 - readyReplicas: 3 - replicas: 3 - updatedReplicas: 3 - observedGeneration: 5 - pgbackrest: - repoHost: - apiVersion: apps/v1 - kind: StatefulSet - ready: true - repos: - - bound: true - name: repo1 - replicaCreateBackupComplete: true - stanzaCreated: true - proxy: - pgBouncer: - readyReplicas: 3 - replicas: 3 ---- -apiVersion: pgv2.percona.com/v2 -kind: PerconaPGCluster -metadata: - name: upgrade-consistency -spec: - crVersion: 2.5.0 -status: - pgbouncer: - ready: 3 - size: 3 - postgres: - instances: - - name: instance1 - ready: 3 - size: 3 - ready: 3 - size: 3 - state: ready diff --git a/e2e-tests/tests/upgrade-consistency/05-patch-cluster.yaml b/e2e-tests/tests/upgrade-consistency/05-patch-cluster.yaml deleted file mode 100644 index a5f90f450..000000000 --- a/e2e-tests/tests/upgrade-consistency/05-patch-cluster.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: kuttl.dev/v1beta1 -kind: TestStep -timeout: 30 -commands: - - script: |- - set -o errexit - set -o xtrace - - source ../../functions - - get_cr \ - | yq eval ' - .spec.crVersion="2.5.0"' - \ - | kubectl -n "${NAMESPACE}" apply -f - - - sleep 10 diff --git a/e2e-tests/tests/users/07-add-custom-user.yaml b/e2e-tests/tests/users/07-add-custom-user.yaml index a621d50c3..6bbfc2081 100644 --- a/e2e-tests/tests/users/07-add-custom-user.yaml +++ b/e2e-tests/tests/users/07-add-custom-user.yaml @@ -8,5 +8,5 @@ commands: source ../../functions - kubectl -n ${NAMESPACE} patch perconapgcluster/${test_name} --type=json -p '[{"op":"add", "path":"/spec/users","value":[{"name":"rhino","databases":["zoo"],"password":{"type":"ASCII"},"secretName":"rhino-credentials"}]}]' + kubectl -n ${NAMESPACE} patch perconapgcluster/${test_name} --type=json -p '[{"op":"add", "path":"/spec/autoCreateUserSchema","value":true},{"op":"add", "path":"/spec/users","value":[{"name":"rhino","databases":["zoo"],"password":{"type":"ASCII"},"secretName":"rhino-credentials"}]}]' sleep 10 diff --git a/e2e-tests/tests/users/08-write-data-to-custom-db.yaml b/e2e-tests/tests/users/08-write-data-to-custom-db.yaml index 3c4af7e2b..f240b8637 100644 --- a/e2e-tests/tests/users/08-write-data-to-custom-db.yaml +++ b/e2e-tests/tests/users/08-write-data-to-custom-db.yaml @@ -10,13 +10,14 @@ commands: password=$(get_psql_user_pass rhino-credentials) user='rhino' db_name='zoo' + schema='rhino' hostname=$(get_pgbouncer_host rhino-credentials) run_psql \ - 'CREATE SCHEMA app CREATE TABLE IF NOT EXISTS customApp (id int PRIMARY KEY);' \ + 'CREATE TABLE IF NOT EXISTS customApp (id int PRIMARY KEY);' \ "-h $hostname -U $user -d $db_name" "$password" run_psql \ - 'INSERT INTO app.customApp (id) VALUES (100500)' \ + "INSERT INTO $schema.customApp (id) VALUES (100500)" \ "-h $hostname -U $user -d $db_name" "$password" diff --git a/e2e-tests/tests/users/09-read-from-primary-custom-db.yaml b/e2e-tests/tests/users/09-read-from-primary-custom-db.yaml index aee4ebd44..9ee89a304 100644 --- a/e2e-tests/tests/users/09-read-from-primary-custom-db.yaml +++ b/e2e-tests/tests/users/09-read-from-primary-custom-db.yaml @@ -11,8 +11,9 @@ commands: password=$(get_psql_user_pass rhino-credentials) user='rhino' db_name='zoo' + schema='rhino' hostname=$(get_pgbouncer_host rhino-credentials) - data=$(run_psql 'SELECT * from app.customApp;' "-h $hostname -U $user -d $db_name" "$password") + data=$(run_psql "SELECT * from $schema.customApp;" "-h $hostname -U $user -d $db_name" "$password") kubectl create configmap -n "${NAMESPACE}" 09-read-from-primary-custom-db --from-literal=data="${data}" diff --git a/e2e-tests/tests/users/11-write-data-to-custom-db.yaml b/e2e-tests/tests/users/11-write-data-to-custom-db.yaml index 734259c62..768d3061c 100644 --- a/e2e-tests/tests/users/11-write-data-to-custom-db.yaml +++ b/e2e-tests/tests/users/11-write-data-to-custom-db.yaml @@ -10,8 +10,9 @@ commands: password=$(get_psql_user_pass rhino-credentials) user='rhino' db_name='zoo' + schema='rhino' hostname=$(get_pgbouncer_host rhino-credentials) run_psql \ - 'INSERT INTO app.customApp (id) VALUES (100501)' \ + "INSERT INTO $schema.customApp (id) VALUES (100501)" \ "-h $hostname -U $user -d $db_name" "$password" diff --git a/e2e-tests/tests/users/12-read-from-primary-custom-db.yaml b/e2e-tests/tests/users/12-read-from-primary-custom-db.yaml index e41dc7a0d..bfccdf36c 100644 --- a/e2e-tests/tests/users/12-read-from-primary-custom-db.yaml +++ b/e2e-tests/tests/users/12-read-from-primary-custom-db.yaml @@ -11,7 +11,8 @@ commands: password=$(get_psql_user_pass rhino-credentials) user='rhino' db_name='zoo' + schema='rhino' hostname=$(get_pgbouncer_host rhino-credentials) - data=$(run_psql 'SELECT * from app.customApp;' "-h $hostname -U $user -d $db_name" "$password") + data=$(run_psql "SELECT * from $schema.customApp;" "-h $hostname -U $user -d $db_name" "$password") kubectl create configmap -n "${NAMESPACE}" 12-read-from-primary-custom-db --from-literal=data="${data}" diff --git a/percona/controller/testdata/sidecar-resources-cr.yaml b/percona/controller/testdata/sidecar-resources-cr.yaml index 2a363cb7c..3cf523a66 100644 --- a/percona/controller/testdata/sidecar-resources-cr.yaml +++ b/percona/controller/testdata/sidecar-resources-cr.yaml @@ -4,7 +4,7 @@ kind: PerconaPGCluster metadata: name: cluster1 spec: - crVersion: 2.5.0 + crVersion: 2.6.0 image: perconalab/percona-postgresql-operator:main-ppg16-postgres imagePullPolicy: Always diff --git a/pkg/apis/pgv2.percona.com/v2/perconapgcluster_types.go b/pkg/apis/pgv2.percona.com/v2/perconapgcluster_types.go index b7f063ebf..dddc1aed3 100644 --- a/pkg/apis/pgv2.percona.com/v2/perconapgcluster_types.go +++ b/pkg/apis/pgv2.percona.com/v2/perconapgcluster_types.go @@ -12,6 +12,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "github.com/percona/percona-postgresql-operator/internal/logging" + "github.com/percona/percona-postgresql-operator/internal/naming" pNaming "github.com/percona/percona-postgresql-operator/percona/naming" crunchyv1beta1 "github.com/percona/percona-postgresql-operator/pkg/apis/postgres-operator.crunchydata.com/v1beta1" ) @@ -166,6 +167,11 @@ type PerconaPGClusterSpec struct { // +operator-sdk:csv:customresourcedefinitions:type=spec // +optional Extensions ExtensionsSpec `json:"extensions,omitempty"` + + // Whether or not the cluster has schemas automatically created for the user + // defined in `spec.users` for all of the databases listed for that user. + // +optional + AutoCreateUserSchema *bool `json:"autoCreateUserSchema,omitempty"` } func (cr *PerconaPGCluster) Default() { @@ -218,6 +224,10 @@ func (cr *PerconaPGCluster) Default() { if cr.Spec.Extensions.BuiltIn.PGAudit == nil { cr.Spec.Extensions.BuiltIn.PGAudit = &t } + + if cr.CompareVersion("2.6.0") >= 0 && cr.Spec.AutoCreateUserSchema == nil { + cr.Spec.AutoCreateUserSchema = &t + } } func (cr *PerconaPGCluster) ToCrunchy(ctx context.Context, postgresCluster *crunchyv1beta1.PostgresCluster, scheme *runtime.Scheme) (*crunchyv1beta1.PostgresCluster, error) { @@ -247,6 +257,11 @@ func (cr *PerconaPGCluster) ToCrunchy(ctx context.Context, postgresCluster *crun annotations[pNaming.ToCrunchyAnnotation(k)] = v } } + + if cr.Spec.AutoCreateUserSchema != nil && *cr.Spec.AutoCreateUserSchema { + annotations[naming.AutoCreateUserSchemaAnnotation] = "true" + } + postgresCluster.Annotations = annotations postgresCluster.Labels = cr.Labels if postgresCluster.Labels == nil { diff --git a/pkg/apis/pgv2.percona.com/v2/zz_generated.deepcopy.go b/pkg/apis/pgv2.percona.com/v2/zz_generated.deepcopy.go index 2b4951b9c..fc7366195 100644 --- a/pkg/apis/pgv2.percona.com/v2/zz_generated.deepcopy.go +++ b/pkg/apis/pgv2.percona.com/v2/zz_generated.deepcopy.go @@ -730,6 +730,11 @@ func (in *PerconaPGClusterSpec) DeepCopyInto(out *PerconaPGClusterSpec) { (*in).DeepCopyInto(*out) } in.Extensions.DeepCopyInto(&out.Extensions) + if in.AutoCreateUserSchema != nil { + in, out := &in.AutoCreateUserSchema, &out.AutoCreateUserSchema + *out = new(bool) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PerconaPGClusterSpec.