Skip to content

Commit

Permalink
feat(cnpg-cluster): add replication values (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Bouquillon authored Aug 11, 2023
1 parent 4f4c217 commit 3930869
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 1 deletion.
18 changes: 17 additions & 1 deletion charts/cnpg-cluster/templates/cluster.cnpg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ spec:
minSyncReplicas: {{ .Values.minSyncReplicas }}
maxSyncReplicas: {{ .Values.maxSyncReplicas }}
postgresql:
pg_hba:
{{- with .Values.pg_hba }}
{{- toYaml . | nindent 8 }}
{{- end }}
parameters:
{{- with .Values.postgresqlParameters }}
{{- toYaml . | nindent 8 }}
Expand All @@ -77,6 +81,12 @@ spec:
name: {{ .Values.superuserSecretName }}
{{ end}}

{{- if .Values.replica.enabled }}
replica:
enabled: true
source: {{ .Values.replica.source }}
{{- end }}

bootstrap:
{{- if .Values.recovery.enabled }}
recovery:
Expand All @@ -85,6 +95,9 @@ spec:
recoveryTarget:
targetTime: "{{ .Values.recovery.targetTime }}"
{{- end }}
{{- else if (and .Values.replica.enabled .Values.replica.source) }}
pg_basebackup:
source: {{ .Values.replica.source }}
{{- else }}
initdb:
database: {{ .Values.dbName }}
Expand All @@ -108,12 +121,15 @@ spec:
{{ end }}
{{- end }}

{{- if .Values.recovery.enabled }}
externalClusters:
{{- if .Values.recovery.enabled }}
- name: "recovery-cluster"
barmanObjectStore:
{{- toYaml .Values.recovery.barmanObjectStore | nindent 8 }}
{{- end }}
{{- if .Values.externalClusters }}
{{- toYaml .Values.externalClusters | nindent 4 }}
{{- end }}

{{- with .Values.clusterExtraSpec }}
{{- toYaml . | nindent 2 }}
Expand Down
26 changes: 26 additions & 0 deletions charts/cnpg-cluster/tests/__snapshot__/cnpg-cluster_test.yaml.snap
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
cluster with custom pg_hba:
1: |
parameters: null
pg_hba:
- host replication postgres all scram-sha-256
cluster with custom pgparams:
1: |
parameters:
timezone: Europe/Paris
work_mem: 512MB
pg_hba: null
cluster with enabled backup and recovery:
1: |
concurrencyPolicy: Forbid
Expand Down Expand Up @@ -104,6 +110,7 @@ cluster with enabled backup and recovery:
enablePodMonitor: false
postgresql:
parameters: null
pg_hba: null
storage:
size: 8Gi
3: |
Expand Down Expand Up @@ -140,8 +147,25 @@ cluster with recovery enabled:
enablePodMonitor: false
postgresql:
parameters: null
pg_hba: null
storage:
size: 8Gi
cluster with replication:
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
3: |
enabled: true
source: source-cluster
cluster with scheduled backup enabled:
1: |
backup:
Expand All @@ -164,6 +188,7 @@ cluster with scheduled backup enabled:
database: app
owner: app
postInitTemplateSQL: null
externalClusters: null
imageName: ghcr.io/cloudnative-pg/postgis:15
imagePullPolicy: IfNotPresent
instances: 1
Expand All @@ -173,5 +198,6 @@ cluster with scheduled backup enabled:
enablePodMonitor: false
postgresql:
parameters: null
pg_hba: null
storage:
size: 8Gi
20 changes: 20 additions & 0 deletions charts/cnpg-cluster/tests/cnpg-cluster_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,23 @@ tests:
- template: cluster.cnpg.yaml
matchSnapshot:
path: spec.postgresql
- it: cluster with custom pg_hba
values:
- ./values/pg_hba.yaml
asserts:
- template: cluster.cnpg.yaml
matchSnapshot:
path: spec.postgresql
- it: cluster with replication
values:
- ./values/replication.yaml
asserts:
- template: cluster.cnpg.yaml
matchSnapshot:
path: spec.externalClusters
- template: cluster.cnpg.yaml
matchSnapshot:
path: spec.bootstrap
- template: cluster.cnpg.yaml
matchSnapshot:
path: spec.replica
3 changes: 3 additions & 0 deletions charts/cnpg-cluster/tests/values/pg_hba.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
postgresql:
pg_hba:
- host replication postgres all scram-sha-256
15 changes: 15 additions & 0 deletions charts/cnpg-cluster/tests/values/replication.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
imageName: ghcr.io/cloudnative-pg/postgis:14

replica:
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
9 changes: 9 additions & 0 deletions charts/cnpg-cluster/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,17 @@ poolers: {}
minSyncReplicas: 0
maxSyncReplicas: 0

# https://www.postgresql.org/docs/9.3/auth-pg-hba-conf.html
pg_hba: []

postgresqlParameters: {}

# https://cloudnative-pg.io/documentation/1.19/api_reference/#externalcluster
externalClusters: []

replica:
enabled: false

extensions: []

dbName: app
Expand Down

0 comments on commit 3930869

Please sign in to comment.