From 1bbf41fb6607327fb7ac0752b2de28f9c61bb5f7 Mon Sep 17 00:00:00 2001 From: Sergey Dudoladov Date: Wed, 25 Nov 2020 15:59:59 +0100 Subject: [PATCH] make parameter overwrite explicit --- docs/reference/operator_parameters.md | 2 +- pkg/cluster/k8sres.go | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/docs/reference/operator_parameters.md b/docs/reference/operator_parameters.md index e1fef7137..5a5a7edc0 100644 --- a/docs/reference/operator_parameters.md +++ b/docs/reference/operator_parameters.md @@ -119,7 +119,7 @@ Those are top-level keys, containing both leaf keys and groups. `enableShmVolume` parameter from Postgres manifest. The default is `true`. * **enable_pgversion_env_var** - With newer versions of Spilo, it is preferable to use `PGVERSION` pod environment variable instead of the setting `postgresql.bin_dir` in the `SPILO_CONFIGURATION` env variable. This option instructs operator if the newer way of specifying the version is to be used. Using both ways produces identical results. However, the newer way may break old Spilo images. Use at your own discretion. The default is `false`. + With newer versions of Spilo, it is preferable to use `PGVERSION` pod environment variable instead of the setting `postgresql.bin_dir` in the `SPILO_CONFIGURATION` env variable. When this option is true, the operator sets `PGVERSION` and omits `postgresql.bin_dir` from `SPILO_CONFIGURATION`. When false, the `postgresql.bin_dir` is set. This setting takes precedence over `PGVERSION`; see PR 222 in Spilo. The default is `false`. * **workers** number of working routines the operator spawns to process requests to diff --git a/pkg/cluster/k8sres.go b/pkg/cluster/k8sres.go index 7465fe222..f3758cd2c 100644 --- a/pkg/cluster/k8sres.go +++ b/pkg/cluster/k8sres.go @@ -189,7 +189,7 @@ func fillResourceList(spec acidv1.ResourceDescription, defaults acidv1.ResourceD return requests, nil } -func generateSpiloJSONConfiguration(pg *acidv1.PostgresqlParam, patroni *acidv1.Patroni, pamRoleName string, logger *logrus.Entry) (string, error) { +func generateSpiloJSONConfiguration(pg *acidv1.PostgresqlParam, patroni *acidv1.Patroni, pamRoleName string, logger *logrus.Entry, EnablePgVersionEnvVar bool) (string, error) { config := spiloConfiguration{} config.Bootstrap = pgBootstrap{} @@ -270,6 +270,14 @@ PatroniInitDBParams: } config.PgLocalConfiguration = make(map[string]interface{}) + + // the newer and preferred way to specify the PG version is to use the `PGVERSION` env variable + // setting postgresq.bin_dir in the SPILO_CONFIGURATION still works and takes precedence over PGVERSION + // so we add postgresq.bin_dir only if PGVERSION is unused + // see PR 222 in Spilo + if !EnablePgVersionEnvVar { + config.PgLocalConfiguration[patroniPGBinariesParameterName] = fmt.Sprintf(pgBinariesLocationTemplate, pg.PgVersion) + } if len(pg.Parameters) > 0 { local, bootstrap := getLocalAndBoostrapPostgreSQLParameters(pg.Parameters) @@ -694,10 +702,9 @@ func (c *Cluster) generateSpiloPodEnvVars(uid types.UID, spiloConfiguration stri Name: "HUMAN_ROLE", Value: c.OpConfig.PamRoleName, }, - { - Name: "PGVERSION", - Value: c.Spec.PgVersion, - }, + } + if c.OpConfig.EnablePgVersionEnvVar { + envVars = append(envVars, v1.EnvVar{Name: "PGVERSION", Value: c.Spec.PgVersion}) } // Spilo expects cluster labels as JSON if clusterLabels, err := json.Marshal(labels.Set(c.OpConfig.ClusterLabels)); err != nil { @@ -1015,7 +1022,7 @@ func (c *Cluster) generateStatefulSet(spec *acidv1.PostgresSpec) (*appsv1.Statef } } - spiloConfiguration, err := generateSpiloJSONConfiguration(&spec.PostgresqlParam, &spec.Patroni, c.OpConfig.PamRoleName, c.logger) + spiloConfiguration, err := generateSpiloJSONConfiguration(&spec.PostgresqlParam, &spec.Patroni, c.OpConfig.PamRoleName, c.logger, c.OpConfig.EnablePgVersionEnvVar) if err != nil { return nil, fmt.Errorf("could not generate Spilo JSON configuration: %v", err) }