From a2267b6110bd2ad5f8cf32f4c9bd6a8d6e6e6af5 Mon Sep 17 00:00:00 2001 From: Julien Bouquillon Date: Mon, 28 Aug 2023 17:54:16 +0200 Subject: [PATCH] feat: allow simple pg_basebackup --- charts/cnpg-cluster/templates/cluster.cnpg.yaml | 3 +++ .../__snapshot__/cnpg-cluster_test.yaml.snap | 13 +++++++++++++ charts/cnpg-cluster/tests/cnpg-cluster_test.yaml | 10 ++++++++++ .../cnpg-cluster/tests/values/pg_basebackup.yaml | 15 +++++++++++++++ charts/cnpg-cluster/values.yaml | 5 +++++ 5 files changed, 46 insertions(+) create mode 100644 charts/cnpg-cluster/tests/values/pg_basebackup.yaml diff --git a/charts/cnpg-cluster/templates/cluster.cnpg.yaml b/charts/cnpg-cluster/templates/cluster.cnpg.yaml index a1e84d9..f35b609 100644 --- a/charts/cnpg-cluster/templates/cluster.cnpg.yaml +++ b/charts/cnpg-cluster/templates/cluster.cnpg.yaml @@ -98,6 +98,9 @@ spec: {{- else if (and .Values.replica.enabled .Values.replica.source) }} pg_basebackup: source: {{ .Values.replica.source }} + {{- else if (and .Values.pg_basebackup.enabled .Values.pg_basebackup.source) }} + pg_basebackup: + source: {{ .Values.pg_basebackup.source }} {{- else }} initdb: database: {{ .Values.dbName }} diff --git a/charts/cnpg-cluster/tests/__snapshot__/cnpg-cluster_test.yaml.snap b/charts/cnpg-cluster/tests/__snapshot__/cnpg-cluster_test.yaml.snap index eb6d24c..2883a49 100644 --- a/charts/cnpg-cluster/tests/__snapshot__/cnpg-cluster_test.yaml.snap +++ b/charts/cnpg-cluster/tests/__snapshot__/cnpg-cluster_test.yaml.snap @@ -118,6 +118,19 @@ cluster with enabled backup and recovery: cluster: name: RELEASE-NAME-cnpg-cluster schedule: 1 2 3 * * 0 +cluster with pg_basebackup: + 1: | + - connectionParameters: + dbname: app + host: some-host-to-replicate-from + user: postgres + name: source-cluster + password: + key: password + name: source-secret-for-source-replication + 2: | + pg_basebackup: + source: source-cluster cluster with recovery enabled: 1: | bootstrap: diff --git a/charts/cnpg-cluster/tests/cnpg-cluster_test.yaml b/charts/cnpg-cluster/tests/cnpg-cluster_test.yaml index a2a38ab..2b2ef46 100644 --- a/charts/cnpg-cluster/tests/cnpg-cluster_test.yaml +++ b/charts/cnpg-cluster/tests/cnpg-cluster_test.yaml @@ -103,3 +103,13 @@ tests: - template: cluster.cnpg.yaml matchSnapshot: path: spec.replica + - it: cluster with pg_basebackup + values: + - ./values/pg_basebackup.yaml + asserts: + - template: cluster.cnpg.yaml + matchSnapshot: + path: spec.externalClusters + - template: cluster.cnpg.yaml + matchSnapshot: + path: spec.bootstrap diff --git a/charts/cnpg-cluster/tests/values/pg_basebackup.yaml b/charts/cnpg-cluster/tests/values/pg_basebackup.yaml new file mode 100644 index 0000000..c53ef99 --- /dev/null +++ b/charts/cnpg-cluster/tests/values/pg_basebackup.yaml @@ -0,0 +1,15 @@ +imageName: ghcr.io/cloudnative-pg/postgis:14 + +pg_basebackup: + enabled: true + source: source-cluster + +externalClusters: + - name: source-cluster + connectionParameters: + host: some-host-to-replicate-from + user: postgres + dbname: app + password: + name: source-secret-for-source-replication + key: password diff --git a/charts/cnpg-cluster/values.yaml b/charts/cnpg-cluster/values.yaml index 13c75d6..f448988 100644 --- a/charts/cnpg-cluster/values.yaml +++ b/charts/cnpg-cluster/values.yaml @@ -185,3 +185,8 @@ postInitApplicationSQLRefs: # secretRefs: # - name: post-init-sql-secret # key: secret.sql + +# +pg_basebackup: + enabled: false + source: