diff --git a/charts/postgres-operator/crds/postgresqls.yaml b/charts/postgres-operator/crds/postgresqls.yaml index e304aa340..1f8010b1b 100644 --- a/charts/postgres-operator/crds/postgresqls.yaml +++ b/charts/postgres-operator/crds/postgresqls.yaml @@ -340,6 +340,8 @@ spec: type: string retry_timeout: type: integer + master_start_timeout: + type: integer slots: type: object additionalProperties: diff --git a/docs/reference/cluster_manifest.md b/docs/reference/cluster_manifest.md index 0f4f0bab6..634db1af3 100644 --- a/docs/reference/cluster_manifest.md +++ b/docs/reference/cluster_manifest.md @@ -339,7 +339,11 @@ explanation of `ttl` and `loop_wait` parameters. [here](https://patroni.readthedocs.io/en/master/dcs_failsafe_mode.html) for more details. This feature is included since Patroni 3.0.0. Hence, check the container image in use if this feature is included in the used Patroni version. The - default is set to `false`. Optional. + default is set to `false`. Optional. + +* **master_start_timeout** + Patroni `master_start_timeout` parameter value. The default is set by the + Spilo Docker image. Optional. ## Postgres container resources diff --git a/e2e/tests/test_e2e.py b/e2e/tests/test_e2e.py index ff5b6d4bf..82b90728c 100644 --- a/e2e/tests/test_e2e.py +++ b/e2e/tests/test_e2e.py @@ -408,6 +408,7 @@ def test_config_update(self): "ttl": 29, "loop_wait": 9, "retry_timeout": 9, + "master_start_timeout": 400, "synchronous_mode": True, "failsafe_mode": True, } @@ -434,6 +435,8 @@ def compare_config(): "loop_wait not updated") self.assertEqual(desired_config["retry_timeout"], effective_config["retry_timeout"], "retry_timeout not updated") + self.assertEqual(desired_config["master_start_timeout"], effective_config["master_start_timeout"], + "master_start_timeout not updated") self.assertEqual(desired_config["synchronous_mode"], effective_config["synchronous_mode"], "synchronous_mode not updated") self.assertEqual(desired_config["failsafe_mode"], effective_config["failsafe_mode"], diff --git a/manifests/complete-postgres-manifest.yaml b/manifests/complete-postgres-manifest.yaml index 5d23b028d..5a0d31bf3 100644 --- a/manifests/complete-postgres-manifest.yaml +++ b/manifests/complete-postgres-manifest.yaml @@ -133,6 +133,7 @@ spec: ttl: 30 loop_wait: 10 retry_timeout: 10 + master_start_timeout: 300 synchronous_mode: false synchronous_mode_strict: false synchronous_node_count: 1 diff --git a/manifests/postgresql.crd.yaml b/manifests/postgresql.crd.yaml index f0174c80f..f8764f690 100644 --- a/manifests/postgresql.crd.yaml +++ b/manifests/postgresql.crd.yaml @@ -338,6 +338,8 @@ spec: type: string retry_timeout: type: integer + master_start_timeout: + type: integer slots: type: object additionalProperties: diff --git a/pkg/apis/acid.zalan.do/v1/postgresql_type.go b/pkg/apis/acid.zalan.do/v1/postgresql_type.go index edce944f1..d5bbd6cf8 100644 --- a/pkg/apis/acid.zalan.do/v1/postgresql_type.go +++ b/pkg/apis/acid.zalan.do/v1/postgresql_type.go @@ -172,6 +172,7 @@ type Patroni struct { TTL uint32 `json:"ttl,omitempty"` LoopWait uint32 `json:"loop_wait,omitempty"` RetryTimeout uint32 `json:"retry_timeout,omitempty"` + MasterStartTimeout uint32 `json:"master_start_timeout,omitempty"` MaximumLagOnFailover float32 `json:"maximum_lag_on_failover,omitempty"` // float32 because https://github.com/kubernetes/kubernetes/issues/30213 Slots map[string]map[string]string `json:"slots,omitempty"` SynchronousMode bool `json:"synchronous_mode,omitempty"` diff --git a/pkg/cluster/k8sres.go b/pkg/cluster/k8sres.go index b60c4ecb3..94477efd2 100644 --- a/pkg/cluster/k8sres.go +++ b/pkg/cluster/k8sres.go @@ -55,6 +55,7 @@ type patroniDCS struct { TTL uint32 `json:"ttl,omitempty"` LoopWait uint32 `json:"loop_wait,omitempty"` RetryTimeout uint32 `json:"retry_timeout,omitempty"` + MasterStartTimeout uint32 `json:"master_start_timeout,omitempty"` MaximumLagOnFailover float32 `json:"maximum_lag_on_failover,omitempty"` SynchronousMode bool `json:"synchronous_mode,omitempty"` SynchronousModeStrict bool `json:"synchronous_mode_strict,omitempty"` @@ -395,6 +396,9 @@ PatroniInitDBParams: if patroni.RetryTimeout != 0 { config.Bootstrap.DCS.RetryTimeout = patroni.RetryTimeout } + if patroni.MasterStartTimeout != 0 { + config.Bootstrap.DCS.MasterStartTimeout = patroni.MasterStartTimeout + } if patroni.TTL != 0 { config.Bootstrap.DCS.TTL = patroni.TTL } diff --git a/pkg/cluster/k8sres_test.go b/pkg/cluster/k8sres_test.go index 483463c21..87ad3d340 100644 --- a/pkg/cluster/k8sres_test.go +++ b/pkg/cluster/k8sres_test.go @@ -94,6 +94,7 @@ func TestGenerateSpiloJSONConfiguration(t *testing.T) { TTL: 30, LoopWait: 10, RetryTimeout: 10, + MasterStartTimeout: 200, MaximumLagOnFailover: 33554432, SynchronousMode: true, SynchronousModeStrict: true, @@ -102,7 +103,7 @@ func TestGenerateSpiloJSONConfiguration(t *testing.T) { FailsafeMode: util.True(), }, opConfig: &config.Config{}, - result: `{"postgresql":{"bin_dir":"/usr/lib/postgresql/15/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"}],"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}}}`, + result: `{"postgresql":{"bin_dir":"/usr/lib/postgresql/15/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"}],"dcs":{"ttl":30,"loop_wait":10,"retry_timeout":10,"master_start_timeout":200,"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}}}`, }, { subtest: "Patroni failsafe_mode configured globally", diff --git a/pkg/cluster/sync.go b/pkg/cluster/sync.go index e22778458..d77265d21 100644 --- a/pkg/cluster/sync.go +++ b/pkg/cluster/sync.go @@ -629,6 +629,9 @@ func (c *Cluster) checkAndSetGlobalPostgreSQLConfiguration(pod *v1.Pod, effectiv if desiredPatroniConfig.RetryTimeout > 0 && desiredPatroniConfig.RetryTimeout != effectivePatroniConfig.RetryTimeout { configToSet["retry_timeout"] = desiredPatroniConfig.RetryTimeout } + if desiredPatroniConfig.MasterStartTimeout > 0 && desiredPatroniConfig.MasterStartTimeout != effectivePatroniConfig.MasterStartTimeout { + configToSet["master_start_timeout"] = desiredPatroniConfig.MasterStartTimeout + } if desiredPatroniConfig.SynchronousMode != effectivePatroniConfig.SynchronousMode { configToSet["synchronous_mode"] = desiredPatroniConfig.SynchronousMode }