From 8a7f540e51a6cfba98afaa667f8f8c02c0dc9e62 Mon Sep 17 00:00:00 2001 From: Kjeld Schouten Date: Sat, 1 Feb 2025 22:25:13 +0100 Subject: [PATCH] feat(common): allow for CNPG UID/GID (#31499) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Description** ⚒️ Fixes #27350 **⚙️ Type of change** - [x] ⚙️ Feature/App addition - [ ] 🪛 Bugfix - [ ] ⚠️ Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] 🔃 Refactor of current code **🧪 How Has This Been Tested?** **📃 Notes:** **✔️ Checklist:** - [ ] ⚖️ My code follows the style guidelines of this project - [ ] 👀 I have performed a self-review of my own code - [ ] #️⃣ I have commented my code, particularly in hard-to-understand areas - [ ] 📄 I have made corresponding changes to the documentation - [ ] ⚠️ My changes generate no new warnings - [ ] 🧪 I have added tests to this description that prove my fix is effective or that my feature works - [ ] ⬆️ I increased versions for any altered app according to semantic versioning - [ ] I made sure the title starts with `feat(chart-name):`, `fix(chart-name):` or `chore(chart-name):` **➕ App addition** If this PR is an app addition please make sure you have done the following. - [ ] 🖼️ I have added an icon in the Chart's root directory called `icon.png` --- _Please don't blindly check all the boxes. Read them and only check those that apply. Those checkboxes are there for the reviewer to see what is this all about and the status of this PR with a quick glance._ --------- Co-authored-by: Stavros Kois --- .../cnpg/cluster_recovery_spec_test.yaml | 2 + .../tests/cnpg/cluster_spec_test.yaml | 76 ++++++++++++++++++- .../common/templates/class/cnpg/_cluster.tpl | 3 + 3 files changed, 80 insertions(+), 1 deletion(-) diff --git a/charts/library/common-test/tests/cnpg/cluster_recovery_spec_test.yaml b/charts/library/common-test/tests/cnpg/cluster_recovery_spec_test.yaml index d318a7bd451..4acbce836f5 100644 --- a/charts/library/common-test/tests/cnpg/cluster_recovery_spec_test.yaml +++ b/charts/library/common-test/tests/cnpg/cluster_recovery_spec_test.yaml @@ -40,6 +40,8 @@ tests: imageName: ghcr.io/cloudnative-pg/postgresql:16.3 primaryUpdateStrategy: unsupervised primaryUpdateMethod: switchover + postgresUID: 26 + postgresGID: 26 logLevel: info instances: 2 nodeMaintenanceWindow: diff --git a/charts/library/common-test/tests/cnpg/cluster_spec_test.yaml b/charts/library/common-test/tests/cnpg/cluster_spec_test.yaml index 8c837e251c0..ce0f4dd929b 100644 --- a/charts/library/common-test/tests/cnpg/cluster_spec_test.yaml +++ b/charts/library/common-test/tests/cnpg/cluster_spec_test.yaml @@ -36,6 +36,77 @@ tests: imageName: ghcr.io/cloudnative-pg/postgresql:16.3 primaryUpdateStrategy: unsupervised primaryUpdateMethod: switchover + postgresUID: 26 + postgresGID: 26 + logLevel: info + instances: 2 + nodeMaintenanceWindow: + reusePVC: true + inProgress: false + resources: + limits: + cpu: 4000m + memory: 8Gi + requests: + cpu: 10m + memory: 50Mi + storage: + pvcTemplate: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 100Gi + walStorage: + pvcTemplate: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 100Gi + bootstrap: + initdb: + secret: + name: test-release-name-common-test-cnpg-my-pg-user + database: test-db + owner: test-user + dataChecksums: true + - it: should work with custom UID/GID + set: + postgres16Image: + repository: ghcr.io/cloudnative-pg/postgresql + tag: "16.3" + pullPolicy: IfNotPresent + cnpg: + my-pg: + enabled: true + user: test-user + database: test-db + password: test-password + cluster: + postgresUID: 666 + postgresGID: 666 + asserts: + - documentIndex: &clusterDoc 0 + isKind: + of: Cluster + - documentIndex: *clusterDoc + isAPIVersion: + of: postgresql.cnpg.io/v1 + - documentIndex: *clusterDoc + equal: + path: metadata.name + value: test-release-name-common-test-cnpg-my-pg + - documentIndex: *clusterDoc + equal: + path: spec + value: + enableSuperuserAccess: true + imageName: ghcr.io/cloudnative-pg/postgresql:16.3 + postgresUID: 666 + postgresGID: 666 + primaryUpdateStrategy: unsupervised + primaryUpdateMethod: switchover logLevel: info instances: 2 nodeMaintenanceWindow: @@ -69,7 +140,6 @@ tests: database: test-db owner: test-user dataChecksums: true - - it: should respect changed fallbackDefaults set: postgres15Image: @@ -192,6 +262,8 @@ tests: imageName: some-image primaryUpdateStrategy: supervised primaryUpdateMethod: restart + postgresUID: 26 + postgresGID: 26 logLevel: debug instances: 3 initdb: @@ -239,6 +311,8 @@ tests: imageName: some-image primaryUpdateStrategy: supervised primaryUpdateMethod: restart + postgresUID: 26 + postgresGID: 26 logLevel: debug instances: 3 nodeMaintenanceWindow: diff --git a/charts/library/common/templates/class/cnpg/_cluster.tpl b/charts/library/common/templates/class/cnpg/_cluster.tpl index 63d628547b2..a949fff4cdd 100644 --- a/charts/library/common/templates/class/cnpg/_cluster.tpl +++ b/charts/library/common/templates/class/cnpg/_cluster.tpl @@ -177,6 +177,9 @@ metadata: {{- end }} spec: imageName: {{ $imageName }} + {{/* This ignores `0` on purpose. */}} + postgresUID: {{ $objectData.cluster.postgresUID | default 26 }} + postgresGID: {{ $objectData.cluster.postgresGID | default 26 }} enableSuperuserAccess: {{ $enableSuperUser }} primaryUpdateStrategy: {{ $primaryUpdateStrategy }} primaryUpdateMethod: {{ $primaryUpdateMethod }}