Skip to content

Commit 4dee891

Browse files
lalbersFxKu
andauthored
Allow configuration of patroni's replication mode (zalando#869)
* Add patroni parameters for `synchronous_mode` * Update complete-postgres-manifest.yaml, removed quotation marks * Update k8sres_test.go, adjust result for `Patroni configured` * Update k8sres_test.go, adjust result for `Patroni configured` * Update complete-postgres-manifest.yaml, set synchronous mode to false in this example * Update pkg/cluster/k8sres.go Does the same but is shorter. So we fix that it if you like. Co-Authored-By: Felix Kunde <felix-kunde@gmx.de> * Update docs/reference/cluster_manifest.md Co-Authored-By: Felix Kunde <felix-kunde@gmx.de> * Add patroni's `synchronous_mode_strict` * Extend `TestGenerateSpiloConfig` with `SynchronousModeStrict` Co-authored-by: Felix Kunde <felix-kunde@gmx.de>
1 parent 64389b8 commit 4dee891

File tree

8 files changed

+48
-14
lines changed

8 files changed

+48
-14
lines changed

charts/postgres-operator/crds/postgresqls.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ spec:
218218
type: integer
219219
retry_timeout:
220220
type: integer
221+
synchronous_mode:
222+
type: boolean
223+
synchronous_mode_strict:
224+
type: boolean
221225
maximum_lag_on_failover:
222226
type: integer
223227
podAnnotations:

docs/reference/cluster_manifest.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,12 @@ explanation of `ttl` and `loop_wait` parameters.
217217
automatically created by Patroni for cluster members and permanent replication
218218
slots. Optional.
219219

220+
* **synchronous_mode**
221+
Patroni `synchronous_mode` parameter value. The default is set to `false`. Optional.
222+
223+
* **synchronous_mode_strict**
224+
Patroni `synchronous_mode_strict` parameter value. Can be used in addition to `synchronous_mode`. The default is set to `false`. Optional.
225+
220226
## Postgres container resources
221227

222228
Those parameters define [CPU and memory requests and limits](https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/)

manifests/complete-postgres-manifest.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ spec:
6767
ttl: 30
6868
loop_wait: &loop_wait 10
6969
retry_timeout: 10
70+
synchronous_mode: false
71+
synchronous_mode_strict: false
7072
maximum_lag_on_failover: 33554432
7173

7274
# restore a Postgres DB with point-in-time-recovery

manifests/postgresql.crd.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ spec:
184184
type: integer
185185
maximum_lag_on_failover:
186186
type: integer
187+
synchronous_mode:
188+
type: boolean
189+
synchronous_mode_strict:
190+
type: boolean
187191
podAnnotations:
188192
type: object
189193
additionalProperties:

pkg/apis/acid.zalan.do/v1/crds.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,12 @@ var PostgresCRDResourceValidation = apiextv1beta1.CustomResourceValidation{
358358
"maximum_lag_on_failover": {
359359
Type: "integer",
360360
},
361+
"synchronous_mode": {
362+
Type: "boolean",
363+
},
364+
"synchronous_mode_strict": {
365+
Type: "boolean",
366+
},
361367
},
362368
},
363369
"podAnnotations": {

pkg/apis/acid.zalan.do/v1/postgresql_type.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,15 @@ type Resources struct {
118118

119119
// Patroni contains Patroni-specific configuration
120120
type Patroni struct {
121-
InitDB map[string]string `json:"initdb"`
122-
PgHba []string `json:"pg_hba"`
123-
TTL uint32 `json:"ttl"`
124-
LoopWait uint32 `json:"loop_wait"`
125-
RetryTimeout uint32 `json:"retry_timeout"`
126-
MaximumLagOnFailover float32 `json:"maximum_lag_on_failover"` // float32 because https://github.com/kubernetes/kubernetes/issues/30213
127-
Slots map[string]map[string]string `json:"slots"`
121+
InitDB map[string]string `json:"initdb"`
122+
PgHba []string `json:"pg_hba"`
123+
TTL uint32 `json:"ttl"`
124+
LoopWait uint32 `json:"loop_wait"`
125+
RetryTimeout uint32 `json:"retry_timeout"`
126+
MaximumLagOnFailover float32 `json:"maximum_lag_on_failover"` // float32 because https://github.com/kubernetes/kubernetes/issues/30213
127+
Slots map[string]map[string]string `json:"slots"`
128+
SynchronousMode bool `json:"synchronous_mode"`
129+
SynchronousModeStrict bool `json:"synchronous_mode_strict"`
128130
}
129131

130132
//StandbyCluster

pkg/cluster/k8sres.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ type patroniDCS struct {
4949
LoopWait uint32 `json:"loop_wait,omitempty"`
5050
RetryTimeout uint32 `json:"retry_timeout,omitempty"`
5151
MaximumLagOnFailover float32 `json:"maximum_lag_on_failover,omitempty"`
52+
SynchronousMode bool `json:"synchronous_mode,omitempty"`
53+
SynchronousModeStrict bool `json:"synchronous_mode_strict,omitempty"`
5254
PGBootstrapConfiguration map[string]interface{} `json:"postgresql,omitempty"`
5355
Slots map[string]map[string]string `json:"slots,omitempty"`
5456
}
@@ -283,6 +285,12 @@ PatroniInitDBParams:
283285
if patroni.Slots != nil {
284286
config.Bootstrap.DCS.Slots = patroni.Slots
285287
}
288+
if patroni.SynchronousMode {
289+
config.Bootstrap.DCS.SynchronousMode = patroni.SynchronousMode
290+
}
291+
if patroni.SynchronousModeStrict != false {
292+
config.Bootstrap.DCS.SynchronousModeStrict = patroni.SynchronousModeStrict
293+
}
286294

287295
config.PgLocalConfiguration = make(map[string]interface{})
288296
config.PgLocalConfiguration[patroniPGBinariesParameterName] = fmt.Sprintf(pgBinariesLocationTemplate, pg.PgVersion)

pkg/cluster/k8sres_test.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,18 @@ func TestGenerateSpiloJSONConfiguration(t *testing.T) {
6565
"locale": "en_US.UTF-8",
6666
"data-checksums": "true",
6767
},
68-
PgHba: []string{"hostssl all all 0.0.0.0/0 md5", "host all all 0.0.0.0/0 md5"},
69-
TTL: 30,
70-
LoopWait: 10,
71-
RetryTimeout: 10,
72-
MaximumLagOnFailover: 33554432,
73-
Slots: map[string]map[string]string{"permanent_logical_1": {"type": "logical", "database": "foo", "plugin": "pgoutput"}},
68+
PgHba: []string{"hostssl all all 0.0.0.0/0 md5", "host all all 0.0.0.0/0 md5"},
69+
TTL: 30,
70+
LoopWait: 10,
71+
RetryTimeout: 10,
72+
MaximumLagOnFailover: 33554432,
73+
SynchronousMode: true,
74+
SynchronousModeStrict: true,
75+
Slots: map[string]map[string]string{"permanent_logical_1": {"type": "logical", "database": "foo", "plugin": "pgoutput"}},
7476
},
7577
role: "zalandos",
7678
opConfig: config.Config{},
77-
result: `{"postgresql":{"bin_dir":"/usr/lib/postgresql/11/bin","pg_hba":["hostssl all all 0.0.0.0/0 md5","host all all 0.0.0.0/0 md5"]},"bootstrap":{"initdb":[{"auth-host":"md5"},{"auth-local":"trust"},"data-checksums",{"encoding":"UTF8"},{"locale":"en_US.UTF-8"}],"users":{"zalandos":{"password":"","options":["CREATEDB","NOLOGIN"]}},"dcs":{"ttl":30,"loop_wait":10,"retry_timeout":10,"maximum_lag_on_failover":33554432,"slots":{"permanent_logical_1":{"database":"foo","plugin":"pgoutput","type":"logical"}}}}}`,
79+
result: `{"postgresql":{"bin_dir":"/usr/lib/postgresql/11/bin","pg_hba":["hostssl all all 0.0.0.0/0 md5","host all all 0.0.0.0/0 md5"]},"bootstrap":{"initdb":[{"auth-host":"md5"},{"auth-local":"trust"},"data-checksums",{"encoding":"UTF8"},{"locale":"en_US.UTF-8"}],"users":{"zalandos":{"password":"","options":["CREATEDB","NOLOGIN"]}},"dcs":{"ttl":30,"loop_wait":10,"retry_timeout":10,"maximum_lag_on_failover":33554432,"synchronous_mode":true,"synchronous_mode_strict":true,"slots":{"permanent_logical_1":{"database":"foo","plugin":"pgoutput","type":"logical"}}}}}`,
7880
},
7981
}
8082
for _, tt := range tests {

0 commit comments

Comments
 (0)