From f5550c337bf3064f074e9e1dcb53fd2eefc0e7e3 Mon Sep 17 00:00:00 2001 From: Oleksii Kliukin Date: Tue, 22 May 2018 16:47:39 +0200 Subject: [PATCH] Put special patroni parameters to the bootstrap. Some special patroni postgresql parameters, like max_connections, should reside in the bootstrap.dcs.postgresql.parameters section to come into effect. --- pkg/cluster/k8sres.go | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/pkg/cluster/k8sres.go b/pkg/cluster/k8sres.go index b0e0b8d67..53671bd60 100644 --- a/pkg/cluster/k8sres.go +++ b/pkg/cluster/k8sres.go @@ -30,10 +30,11 @@ type pgUser struct { } type patroniDCS struct { - TTL uint32 `json:"ttl,omitempty"` - LoopWait uint32 `json:"loop_wait,omitempty"` - RetryTimeout uint32 `json:"retry_timeout,omitempty"` - MaximumLagOnFailover float32 `json:"maximum_lag_on_failover,omitempty"` + TTL uint32 `json:"ttl,omitempty"` + LoopWait uint32 `json:"loop_wait,omitempty"` + RetryTimeout uint32 `json:"retry_timeout,omitempty"` + MaximumLagOnFailover float32 `json:"maximum_lag_on_failover,omitempty"` + PGBootstrapConfiguration map[string]interface{} `json:"postgresql,omitempty"` } type pgBootstrap struct { @@ -221,7 +222,22 @@ PatroniInitDBParams: config.PgLocalConfiguration = make(map[string]interface{}) config.PgLocalConfiguration[patroniPGBinariesParameterName] = fmt.Sprintf(pgBinariesLocationTemplate, pg.PgVersion) if len(pg.Parameters) > 0 { - config.PgLocalConfiguration[patroniPGParametersParameterName] = pg.Parameters + localParameters := make(map[string]string) + bootstrapParameters := make(map[string]string) + for param, val := range pg.Parameters { + if !isBootstrapOnlyParameter(param) { + localParameters[param] = val + } else { + bootstrapParameters[param] = val + } + } + if len(localParameters) > 0 { + config.PgLocalConfiguration[patroniPGParametersParameterName] = localParameters + } + if len(bootstrapParameters) > 0 { + config.Bootstrap.DCS.PGBootstrapConfiguration = make(map[string]interface{}) + config.Bootstrap.DCS.PGBootstrapConfiguration[patroniPGParametersParameterName] = bootstrapParameters + } } config.Bootstrap.Users = map[string]pgUser{ c.OpConfig.PamRoleName: { @@ -280,6 +296,16 @@ func (c *Cluster) tolerations(tolerationsSpec *[]v1.Toleration) []v1.Toleration return []v1.Toleration{} } +func isBootstrapOnlyParameter(param string) bool { + return param == "max_connections" || + param == "max_locks_per_transaction" || + param == "max_worker_processes" || + param == "max_prepared_transactions" || + param == "wal_level" || + param == "wal_log_hints" || + param == "track_commit_timestamp" +} + func (c *Cluster) generatePodTemplate( uid types.UID, resourceRequirements *v1.ResourceRequirements,