Skip to content

Commit 990dc64

Browse files
feat(cluster): expose replicationSlots on the CNPG Cluster (#877)
Surfaces CloudNativePG's `spec.replicationSlots` on the cluster chart so chart users can enable synchronization of user-created logical replication slots between the primary and standbys. With PostgreSQL 17+ failover slots, this lets CDC consumers (e.g. Debezium) survive a CNPG failover without losing the slot. To make logical decoding slots survive failover, users must: - enable `cluster.replicationSlots.highAvailability.synchronizeLogicalDecoding` - set `cluster.postgresql.parameters.hot_standby_feedback: "on"` - set `cluster.postgresql.parameters.sync_replication_slots: "on"` - create the CDC client's logical slot with `failover = true` Requires CloudNativePG 1.27+ and PostgreSQL 17+ for native failover slots. The block is omitted entirely when the value is empty, so existing deployments are unaffected. The non-default-configuration chainsaw test is extended with a `replicationSlots` block and the matching PostgreSQL parameters, and asserts they appear verbatim on the rendered Cluster CR. Signed-off-by: Philippe Noël <philippemnoel@gmail.com>
1 parent 3c89afd commit 990dc64

6 files changed

Lines changed: 41 additions & 0 deletions

File tree

charts/cluster/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ Kubernetes: `>=1.29.0-0`
195195
| cluster.primaryUpdateMethod | string | `"switchover"` | Method to follow to upgrade the primary server during a rolling update procedure, after all replicas have been successfully updated. It can be switchover (default) or restart. |
196196
| cluster.primaryUpdateStrategy | string | `"unsupervised"` | Strategy to follow to upgrade the primary server during a rolling update procedure, after all replicas have been successfully updated: it can be automated (unsupervised - default) or manual (supervised) |
197197
| cluster.priorityClassName | string | `""` | |
198+
| cluster.replicationSlots | object | `{}` | Replication slot management. To make logical decoding slots survive failover for CDC consumers (e.g. Debezium), enable `highAvailability.synchronizeLogicalDecoding`, set `cluster.postgresql.parameters.hot_standby_feedback: "on"` and `cluster.postgresql.parameters.sync_replication_slots: "on"`, and ensure the CDC client creates its logical slot with `failover = true`. Requires CloudNativePG 1.27+ and PostgreSQL 17+ for native failover slots. See: https://cloudnative-pg.io/documentation/current/replication/#replication-slots |
198199
| cluster.resources | object | `{}` | Resources requirements of every generated Pod. Please refer to https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ for more information. We strongly advise you use the same setting for limits and requests so that your cluster pods are given a Guaranteed QoS. See: https://kubernetes.io/docs/concepts/workloads/pods/pod-qos/ |
199200
| cluster.roles | list | `[]` | This feature enables declarative management of existing roles, as well as the creation of new roles if they are not already present in the database. See: https://cloudnative-pg.io/documentation/current/declarative_role_management/ |
200201
| cluster.securityContext | object | `{}` | Configure Container Security Context. See: https://cloudnative-pg.io/documentation/preview/security/ |

charts/cluster/templates/cluster.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ spec:
101101
{{- toYaml . | nindent 6 }}
102102
{{- end }}
103103

104+
{{- with .Values.cluster.replicationSlots }}
105+
replicationSlots:
106+
{{- toYaml . | nindent 4 }}
107+
{{- end }}
108+
104109
{{- if not (and (empty .Values.cluster.roles) (empty .Values.cluster.services)) }}
105110
managed:
106111
{{- with .Values.cluster.services }}

charts/cluster/test/postgresql-cluster-configuration/01-non_default_configuration_cluster-assert.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ spec:
1212
postgresUID: 1001
1313
postgresGID: 1002
1414
instances: 2
15+
replicationSlots:
16+
highAvailability:
17+
enabled: true
18+
slotPrefix: "_cnpg_"
19+
synchronizeLogicalDecoding: true
20+
updateInterval: 30
1521
postgresql:
1622
ldap:
1723
server: 'openldap.default.svc.cluster.local'
@@ -23,7 +29,9 @@ spec:
2329
key: 'data'
2430
searchAttribute: 'uid'
2531
parameters:
32+
hot_standby_feedback: "on"
2633
max_connections: "42"
34+
sync_replication_slots: "on"
2735
pg_hba:
2836
- host all 1.2.3.4/32 trust
2937
pg_ident:

charts/cluster/test/postgresql-cluster-configuration/01-non_default_configuration_cluster.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ cluster:
8787
inRoles:
8888
- pg_monitor
8989
- pg_signal_backend
90+
replicationSlots:
91+
highAvailability:
92+
enabled: true
93+
slotPrefix: "_cnpg_"
94+
synchronizeLogicalDecoding: true
95+
updateInterval: 30
9096
postgresql:
9197
ldap:
9298
server: 'openldap.default.svc.cluster.local'
@@ -98,7 +104,9 @@ cluster:
98104
key: 'data'
99105
searchAttribute: 'uid'
100106
parameters:
107+
hot_standby_feedback: "on"
101108
max_connections: "42"
109+
sync_replication_slots: "on"
102110
pg_hba:
103111
- host all 1.2.3.4/32 trust
104112
pg_ident:

charts/cluster/values.schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,11 @@
510510
"default": "",
511511
"type": "string"
512512
},
513+
"replicationSlots": {
514+
"description": "Replication slot management. To make logical decoding slots survive\nfailover for CDC consumers (e.g. Debezium), enable\n`highAvailability.synchronizeLogicalDecoding`, set\n`cluster.postgresql.parameters.hot_standby_feedback: \"on\"` and\n`cluster.postgresql.parameters.sync_replication_slots: \"on\"`, and ensure\nthe CDC client creates its logical slot with `failover = true`.\nRequires CloudNativePG 1.27+ and PostgreSQL 17+ for native failover slots.\nSee: https://cloudnative-pg.io/documentation/current/replication/#replication-slots",
515+
"required": [],
516+
"type": "object"
517+
},
513518
"resources": {
514519
"description": "Resources requirements of every generated Pod.\nPlease refer to https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ for more information.\nWe strongly advise you use the same setting for limits and requests so that your cluster pods are given a Guaranteed QoS.\nSee: https://kubernetes.io/docs/concepts/workloads/pods/pod-qos/",
515520
"required": [],

charts/cluster/values.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,20 @@ cluster:
390390
# key: 'data'
391391
# searchAttribute: 'uid'
392392

393+
# -- Replication slot management. To make logical decoding slots survive
394+
# failover for CDC consumers (e.g. Debezium), enable
395+
# `highAvailability.synchronizeLogicalDecoding`, set
396+
# `cluster.postgresql.parameters.hot_standby_feedback: "on"` and
397+
# `cluster.postgresql.parameters.sync_replication_slots: "on"`, and ensure
398+
# the CDC client creates its logical slot with `failover = true`.
399+
# Requires CloudNativePG 1.27+ and PostgreSQL 17+ for native failover slots.
400+
# See: https://cloudnative-pg.io/documentation/current/replication/#replication-slots
401+
replicationSlots: {}
402+
# highAvailability:
403+
# enabled: true
404+
# slotPrefix: "_cnpg_"
405+
# synchronizeLogicalDecoding: true
406+
# updateInterval: 30
393407

394408
# -- BootstrapInitDB is the configuration of the bootstrap process when initdb is used.
395409
# See: https://cloudnative-pg.io/documentation/current/bootstrap/

0 commit comments

Comments
 (0)