Skip to content

Commit dc9a5b1

Browse files
sdudoladovSergey Dudoladov
andauthored
Introduce PGVERSION (#1172)
* introduce PGVERSION Co-authored-by: Sergey Dudoladov <sergey.dudoladov@zalando.de>
1 parent 6f5751f commit dc9a5b1

File tree

11 files changed

+29
-6
lines changed

11 files changed

+29
-6
lines changed

charts/postgres-operator/values-crd.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ configGeneral:
2121
enable_crd_validation: true
2222
# update only the statefulsets without immediately doing the rolling update
2323
enable_lazy_spilo_upgrade: false
24+
# set the PGVERSION env var instead of providing the version via postgresql.bin_dir in SPILO_CONFIGURATION
25+
enable_pgversion_env_var: "false"
2426
# start any new database pod without limitations on shm memory
2527
enable_shm_volume: true
2628
# etcd connection string for Patroni. Empty uses K8s-native DCS.

charts/postgres-operator/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ configGeneral:
2424
enable_crd_validation: "true"
2525
# update only the statefulsets without immediately doing the rolling update
2626
enable_lazy_spilo_upgrade: "false"
27+
# set the PGVERSION env var instead of providing the version via postgresql.bin_dir in SPILO_CONFIGURATION
28+
enable_pgversion_env_var: "false"
2729
# start any new database pod without limitations on shm memory
2830
enable_shm_volume: "true"
2931
# etcd connection string for Patroni. Empty uses K8s-native DCS.

docs/reference/operator_parameters.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ Those are top-level keys, containing both leaf keys and groups.
118118
This option is global for an operator object, and can be overwritten by
119119
`enableShmVolume` parameter from Postgres manifest. The default is `true`.
120120

121+
* **enable_pgversion_env_var**
122+
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`.
123+
121124
* **workers**
122125
number of working routines the operator spawns to process requests to
123126
create/update/delete/sync clusters concurrently. The default is `4`.

e2e/tests/test_e2e.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,7 @@ def assert_distributed_pods(self, master_node, replica_nodes, cluster_label):
10801080
"enable_pod_antiaffinity": "false"
10811081
}
10821082
}
1083-
k8s.update_config(patch_disable_antiaffinity, "disalbe antiaffinity")
1083+
k8s.update_config(patch_disable_antiaffinity, "disable antiaffinity")
10841084
k8s.wait_for_pod_start('spilo-role=master')
10851085
k8s.wait_for_pod_start('spilo-role=replica')
10861086
return True

manifests/configmap.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ data:
4545
# enable_postgres_team_crd_superusers: "false"
4646
enable_replica_load_balancer: "false"
4747
# enable_shm_volume: "true"
48+
# enable_pgversion_env_var: "false"
4849
# enable_sidecars: "true"
4950
# enable_team_superuser: "false"
5051
enable_teams_api: "false"

manifests/operatorconfiguration.crd.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ spec:
6565
type: boolean
6666
enable_lazy_spilo_upgrade:
6767
type: boolean
68+
enable_pgversion_env_var:
69+
type: boolean
6870
enable_shm_volume:
6971
type: boolean
7072
etcd_host:

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ type ScalyrConfiguration struct {
167167
ScalyrMemoryLimit string `json:"scalyr_memory_limit,omitempty"`
168168
}
169169

170-
// Defines default configuration for connection pooler
170+
// ConnectionPoolerConfiguration defines default configuration for connection pooler
171171
type ConnectionPoolerConfiguration struct {
172172
NumberOfInstances *int32 `json:"connection_pooler_number_of_instances,omitempty"`
173173
Schema string `json:"connection_pooler_schema,omitempty"`
@@ -197,6 +197,7 @@ type OperatorLogicalBackupConfiguration struct {
197197
type OperatorConfigurationData struct {
198198
EnableCRDValidation *bool `json:"enable_crd_validation,omitempty"`
199199
EnableLazySpiloUpgrade bool `json:"enable_lazy_spilo_upgrade,omitempty"`
200+
EnablePgVersionEnvVar bool `json:"enable_pgversion_env_var,omitempty"`
200201
EtcdHost string `json:"etcd_host,omitempty"`
201202
KubernetesUseConfigMaps bool `json:"kubernetes_use_configmaps,omitempty"`
202203
DockerImage string `json:"docker_image,omitempty"`

pkg/cluster/k8sres.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func fillResourceList(spec acidv1.ResourceDescription, defaults acidv1.ResourceD
189189
return requests, nil
190190
}
191191

192-
func generateSpiloJSONConfiguration(pg *acidv1.PostgresqlParam, patroni *acidv1.Patroni, pamRoleName string, logger *logrus.Entry) (string, error) {
192+
func generateSpiloJSONConfiguration(pg *acidv1.PostgresqlParam, patroni *acidv1.Patroni, pamRoleName string, EnablePgVersionEnvVar bool, logger *logrus.Entry) (string, error) {
193193
config := spiloConfiguration{}
194194

195195
config.Bootstrap = pgBootstrap{}
@@ -270,7 +270,14 @@ PatroniInitDBParams:
270270
}
271271

272272
config.PgLocalConfiguration = make(map[string]interface{})
273-
config.PgLocalConfiguration[patroniPGBinariesParameterName] = fmt.Sprintf(pgBinariesLocationTemplate, pg.PgVersion)
273+
274+
// the newer and preferred way to specify the PG version is to use the `PGVERSION` env variable
275+
// setting postgresq.bin_dir in the SPILO_CONFIGURATION still works and takes precedence over PGVERSION
276+
// so we add postgresq.bin_dir only if PGVERSION is unused
277+
// see PR 222 in Spilo
278+
if !EnablePgVersionEnvVar {
279+
config.PgLocalConfiguration[patroniPGBinariesParameterName] = fmt.Sprintf(pgBinariesLocationTemplate, pg.PgVersion)
280+
}
274281
if len(pg.Parameters) > 0 {
275282
local, bootstrap := getLocalAndBoostrapPostgreSQLParameters(pg.Parameters)
276283

@@ -696,6 +703,9 @@ func (c *Cluster) generateSpiloPodEnvVars(uid types.UID, spiloConfiguration stri
696703
Value: c.OpConfig.PamRoleName,
697704
},
698705
}
706+
if c.OpConfig.EnablePgVersionEnvVar {
707+
envVars = append(envVars, v1.EnvVar{Name: "PGVERSION", Value: c.Spec.PgVersion})
708+
}
699709
// Spilo expects cluster labels as JSON
700710
if clusterLabels, err := json.Marshal(labels.Set(c.OpConfig.ClusterLabels)); err != nil {
701711
envVars = append(envVars, v1.EnvVar{Name: "KUBERNETES_LABELS", Value: labels.Set(c.OpConfig.ClusterLabels).String()})
@@ -1012,7 +1022,7 @@ func (c *Cluster) generateStatefulSet(spec *acidv1.PostgresSpec) (*appsv1.Statef
10121022
}
10131023
}
10141024

1015-
spiloConfiguration, err := generateSpiloJSONConfiguration(&spec.PostgresqlParam, &spec.Patroni, c.OpConfig.PamRoleName, c.logger)
1025+
spiloConfiguration, err := generateSpiloJSONConfiguration(&spec.PostgresqlParam, &spec.Patroni, c.OpConfig.PamRoleName, c.OpConfig.EnablePgVersionEnvVar, c.logger)
10161026
if err != nil {
10171027
return nil, fmt.Errorf("could not generate Spilo JSON configuration: %v", err)
10181028
}

pkg/cluster/k8sres_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func TestGenerateSpiloJSONConfiguration(t *testing.T) {
9393
}
9494
for _, tt := range tests {
9595
cluster.OpConfig = tt.opConfig
96-
result, err := generateSpiloJSONConfiguration(tt.pgParam, tt.patroni, tt.role, logger)
96+
result, err := generateSpiloJSONConfiguration(tt.pgParam, tt.patroni, tt.role, false, logger)
9797
if err != nil {
9898
t.Errorf("Unexpected error: %v", err)
9999
}

pkg/controller/operator_config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func (c *Controller) importConfigurationFromCRD(fromCRD *acidv1.OperatorConfigur
3535
// general config
3636
result.EnableCRDValidation = util.CoalesceBool(fromCRD.EnableCRDValidation, util.True())
3737
result.EnableLazySpiloUpgrade = fromCRD.EnableLazySpiloUpgrade
38+
result.EnablePgVersionEnvVar = fromCRD.EnablePgVersionEnvVar
3839
result.EtcdHost = fromCRD.EtcdHost
3940
result.KubernetesUseConfigMaps = fromCRD.KubernetesUseConfigMaps
4041
result.DockerImage = util.Coalesce(fromCRD.DockerImage, "registry.opensource.zalan.do/acid/spilo-12:1.6-p3")

0 commit comments

Comments
 (0)