Skip to content

Commit babb7c2

Browse files
committed
Consider global value in sync + tiny refactoring
1 parent d7466d2 commit babb7c2

File tree

13 files changed

+163
-34
lines changed

13 files changed

+163
-34
lines changed

charts/postgres-operator/crds/operatorconfigurations.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ spec:
636636
patroni:
637637
type: object
638638
properties:
639-
enable_failsafe_mode:
639+
failsafe_mode:
640640
type: boolean
641641
default: false
642642
status:

charts/postgres-operator/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ configConnectionPooler:
411411

412412
configPatroni:
413413
# enable Patroni DCS failsafe_mode feature
414-
enable_failsafe_mode: false
414+
failsafe_mode: false
415415

416416
# Zalando's internal CDC stream feature
417417
enableStreams: false

manifests/operatorconfiguration.crd.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ spec:
634634
patroni:
635635
type: object
636636
properties:
637-
enable_failsafe_mode:
637+
failsafe_mode:
638638
type: boolean
639639
default: false
640640
status:

manifests/postgresql-operator-default-configuration.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,4 @@ configuration:
199199
# connection_pooler_schema: "pooler"
200200
# connection_pooler_user: "pooler"
201201
patroni:
202-
# enable_failsafe_mode: "false"
202+
# failsafe_mode: "false"

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,6 +1461,14 @@ var OperatorConfigCRDResourceValidation = apiextv1.CustomResourceValidation{
14611461
},
14621462
},
14631463
},
1464+
"patroni": {
1465+
Type: "object",
1466+
Properties: map[string]apiextv1.JSONSchemaProps{
1467+
"failsafe_mode": {
1468+
Type: "boolean",
1469+
},
1470+
},
1471+
},
14641472
"postgres_pod_resources": {
14651473
Type: "object",
14661474
Properties: map[string]apiextv1.JSONSchemaProps{

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ type OperatorLogicalBackupConfiguration struct {
229229

230230
// PatroniConfiguration defines configuration for Patroni
231231
type PatroniConfiguration struct {
232-
EnableFailsafeMode bool `json:"enable_failsafe_mode,omitempty"`
232+
FailsafeMode *bool `json:"failsafe_mode,omitempty"`
233233
}
234234

235235
// OperatorConfigurationData defines the operation config
@@ -264,7 +264,7 @@ type OperatorConfigurationData struct {
264264
Scalyr ScalyrConfiguration `json:"scalyr"`
265265
LogicalBackup OperatorLogicalBackupConfiguration `json:"logical_backup"`
266266
ConnectionPooler ConnectionPoolerConfiguration `json:"connection_pooler"`
267-
Patroni PatroniConfiguration `json:"patroni_configuration"`
267+
Patroni PatroniConfiguration `json:"patroni"`
268268

269269
MinInstances int32 `json:"min_instances,omitempty"`
270270
MaxInstances int32 `json:"max_instances,omitempty"`

pkg/apis/acid.zalan.do/v1/zz_generated.deepcopy.go

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/cluster/k8sres.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +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"`
62+
FailsafeMode *bool `json:"failsafe_mode,omitempty"`
6363
}
6464

6565
type pgBootstrap struct {
@@ -380,8 +380,8 @@ PatroniInitDBParams:
380380
config.Bootstrap.DCS.SynchronousNodeCount = patroni.SynchronousNodeCount
381381
}
382382
if patroni.FailsafeMode != nil {
383-
config.Bootstrap.DCS.FailsafeMode = *patroni.FailsafeMode
384-
} else {
383+
config.Bootstrap.DCS.FailsafeMode = patroni.FailsafeMode
384+
} else if opConfig.EnablePatroniFailsafeMode != nil {
385385
config.Bootstrap.DCS.FailsafeMode = opConfig.EnablePatroniFailsafeMode
386386
}
387387

pkg/cluster/k8sres_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func TestGenerateSpiloJSONConfiguration(t *testing.T) {
118118
Auth: config.Auth{
119119
PamRoleName: "zalandos",
120120
},
121-
EnablePatroniFailsafeMode: true,
121+
EnablePatroniFailsafeMode: util.True(),
122122
},
123123
result: `{"postgresql":{"bin_dir":"/usr/lib/postgresql/14/bin"},"bootstrap":{"initdb":[{"auth-host":"md5"},{"auth-local":"trust"}],"users":{"zalandos":{"password":"","options":["CREATEDB","NOLOGIN"]}},"dcs":{"failsafe_mode":true}}}`,
124124
},
@@ -132,9 +132,9 @@ func TestGenerateSpiloJSONConfiguration(t *testing.T) {
132132
Auth: config.Auth{
133133
PamRoleName: "zalandos",
134134
},
135-
EnablePatroniFailsafeMode: true,
135+
EnablePatroniFailsafeMode: util.True(),
136136
},
137-
result: `{"postgresql":{"bin_dir":"/usr/lib/postgresql/14/bin"},"bootstrap":{"initdb":[{"auth-host":"md5"},{"auth-local":"trust"}],"users":{"zalandos":{"password":"","options":["CREATEDB","NOLOGIN"]}},"dcs":{}}}`,
137+
result: `{"postgresql":{"bin_dir":"/usr/lib/postgresql/14/bin"},"bootstrap":{"initdb":[{"auth-host":"md5"},{"auth-local":"trust"}],"users":{"zalandos":{"password":"","options":["CREATEDB","NOLOGIN"]}},"dcs":{"failsafe_mode":false}}}`,
138138
},
139139
{
140140
subtest: "Patroni failsafe_mode disabled globally, configured for cluster",
@@ -146,7 +146,7 @@ func TestGenerateSpiloJSONConfiguration(t *testing.T) {
146146
Auth: config.Auth{
147147
PamRoleName: "zalandos",
148148
},
149-
EnablePatroniFailsafeMode: false,
149+
EnablePatroniFailsafeMode: util.False(),
150150
},
151151
result: `{"postgresql":{"bin_dir":"/usr/lib/postgresql/14/bin"},"bootstrap":{"initdb":[{"auth-host":"md5"},{"auth-local":"trust"}],"users":{"zalandos":{"password":"","options":["CREATEDB","NOLOGIN"]}},"dcs":{"failsafe_mode":true}}}`,
152152
},

pkg/cluster/sync.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,8 +566,21 @@ 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
569+
570+
var desiredFailsafe *bool
571+
if desiredPatroniConfig.FailsafeMode != nil {
572+
desiredFailsafe = desiredPatroniConfig.FailsafeMode
573+
} else if c.OpConfig.EnablePatroniFailsafeMode != nil {
574+
desiredFailsafe = c.OpConfig.EnablePatroniFailsafeMode
575+
}
576+
577+
effectiveFailsafe := effectivePatroniConfig.FailsafeMode
578+
579+
if desiredFailsafe != nil {
580+
c.logger.Info("desiredFailsafe is not nil")
581+
if effectiveFailsafe == nil || *desiredFailsafe != *effectiveFailsafe {
582+
configToSet["failsafe_mode"] = *desiredFailsafe
583+
}
571584
}
572585

573586
// check if specified slots exist in config and if they differ

0 commit comments

Comments
 (0)