Skip to content

Commit 8aee0a6

Browse files
committed
[WIP] Add Patroni failsafe_mode parameter
1 parent 84fe38a commit 8aee0a6

File tree

12 files changed

+39
-16
lines changed

12 files changed

+39
-16
lines changed

charts/postgres-operator/crds/postgresqls.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,8 @@ spec:
320320
patroni:
321321
type: object
322322
properties:
323+
failsafe_mode:
324+
type: boolean
323325
initdb:
324326
type: object
325327
additionalProperties:

docs/reference/cluster_manifest.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,9 @@ explanation of `ttl` and `loop_wait` parameters.
316316

317317
* **synchronous_node_count**
318318
Patroni `synchronous_node_count` parameter value. Note, this option is only available for Spilo images with Patroni 2.0+. The default is set to `1`. Optional.
319+
320+
* **failsafe_mode**
321+
Patroni `failsafe_mode` parameter value. Note, this option is currently not included in any Patroni release. The default is set to `false`. Optional.
319322

320323
## Postgres container resources
321324

e2e/tests/test_e2e.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@ def test_config_update(self):
365365
"ttl": 29,
366366
"loop_wait": 9,
367367
"retry_timeout": 9,
368-
"synchronous_mode": True
368+
"synchronous_mode": True,
369+
"failsafe_mode": True,
369370
}
370371
}
371372
}
@@ -392,6 +393,8 @@ def compare_config():
392393
"retry_timeout not updated")
393394
self.assertEqual(desired_config["synchronous_mode"], effective_config["synchronous_mode"],
394395
"synchronous_mode not updated")
396+
self.assertEqual(desired_config["failsafe_mode"], effective_config["failsafe_mode"],
397+
"failsafe_mode not updated")
395398
return True
396399

397400
# check if Patroni config has been updated

manifests/complete-postgres-manifest.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ spec:
109109
cpu: 500m
110110
memory: 500Mi
111111
patroni:
112+
failsafe_mode: false
112113
initdb:
113114
encoding: "UTF8"
114115
locale: "en_US.UTF-8"

manifests/postgresql.crd.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,8 @@ spec:
318318
patroni:
319319
type: object
320320
properties:
321+
failsafe_mode:
322+
type: boolean
321323
initdb:
322324
type: object
323325
additionalProperties:

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,9 @@ var PostgresCRDResourceValidation = apiextv1.CustomResourceValidation{
503503
"patroni": {
504504
Type: "object",
505505
Properties: map[string]apiextv1.JSONSchemaProps{
506+
"failsafe_mode": {
507+
Type: "boolean",
508+
},
506509
"initdb": {
507510
Type: "object",
508511
AdditionalProperties: &apiextv1.JSONSchemaPropsOrBool{

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ type Patroni struct {
171171
SynchronousMode bool `json:"synchronous_mode,omitempty"`
172172
SynchronousModeStrict bool `json:"synchronous_mode_strict,omitempty"`
173173
SynchronousNodeCount uint32 `json:"synchronous_node_count,omitempty" defaults:"1"`
174+
FailsafeMode bool `json:"failsafe_mode,omitempty"`
174175
}
175176

176177
// StandbyDescription contains remote primary config or s3/gs wal path

pkg/cluster/k8sres.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ type patroniDCS struct {
5959
SynchronousNodeCount uint32 `json:"synchronous_node_count,omitempty"`
6060
PGBootstrapConfiguration map[string]interface{} `json:"postgresql,omitempty"`
6161
Slots map[string]map[string]string `json:"slots,omitempty"`
62+
FailsafeMode bool `json:"failsafe_mode,omitempty"`
6263
}
6364

6465
type pgBootstrap struct {
@@ -378,6 +379,9 @@ PatroniInitDBParams:
378379
if patroni.SynchronousNodeCount >= 1 {
379380
config.Bootstrap.DCS.SynchronousNodeCount = patroni.SynchronousNodeCount
380381
}
382+
if patroni.FailsafeMode {
383+
config.Bootstrap.DCS.FailsafeMode = patroni.FailsafeMode
384+
}
381385

382386
config.PgLocalConfiguration = make(map[string]interface{})
383387

pkg/cluster/k8sres_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,11 @@ func TestGenerateSpiloJSONConfiguration(t *testing.T) {
9999
SynchronousModeStrict: true,
100100
SynchronousNodeCount: 1,
101101
Slots: map[string]map[string]string{"permanent_logical_1": {"type": "logical", "database": "foo", "plugin": "pgoutput"}},
102+
FailsafeMode: true,
102103
},
103104
role: "zalandos",
104105
opConfig: config.Config{},
105-
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,"synchronous_node_count":1,"slots":{"permanent_logical_1":{"database":"foo","plugin":"pgoutput","type":"logical"}}}}}`,
106+
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,"synchronous_node_count":1,"slots":{"permanent_logical_1":{"database":"foo","plugin":"pgoutput","type":"logical"}},"failsafe_mode":true}}}`,
106107
},
107108
}
108109
for _, tt := range tests {

pkg/cluster/sync.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,9 @@ func (c *Cluster) checkAndSetGlobalPostgreSQLConfiguration(pod *v1.Pod, effectiv
566566
if desiredPatroniConfig.TTL > 0 && desiredPatroniConfig.TTL != effectivePatroniConfig.TTL {
567567
configToSet["ttl"] = desiredPatroniConfig.TTL
568568
}
569+
if desiredPatroniConfig.FailsafeMode != effectivePatroniConfig.FailsafeMode {
570+
configToSet["failsafe_mode"] = desiredPatroniConfig.FailsafeMode
571+
}
569572

570573
// check if specified slots exist in config and if they differ
571574
slotsToSet := make(map[string]map[string]string)

0 commit comments

Comments
 (0)