Skip to content

Commit c756cb2

Browse files
authored
spec.env can override clone and standby variables (#2159)
1 parent becf8a4 commit c756cb2

File tree

3 files changed

+55
-8
lines changed

3 files changed

+55
-8
lines changed

docs/administrator.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -631,9 +631,9 @@ order (e.g. a variable defined in 4. overrides a variable with the same name
631631
in 5.):
632632

633633
1. Assigned by the operator
634-
2. Clone section (with WAL settings from operator config when `s3_wal_path` is empty)
635-
3. Standby section
636-
4. `env` section in cluster manifest
634+
2. `env` section in cluster manifest
635+
3. Clone section (with WAL settings from operator config when `s3_wal_path` is empty)
636+
4. Standby section
637637
5. Pod environment secret via operator config
638638
6. Pod environment config map via operator config
639639
7. WAL and logical backup settings from operator config

pkg/cluster/k8sres.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,11 @@ func (c *Cluster) generateSpiloPodEnvVars(
962962
envVars = append(envVars, v1.EnvVar{Name: "KUBERNETES_USE_CONFIGMAPS", Value: "true"})
963963
}
964964

965+
// fetch cluster-specific variables that will override all subsequent global variables
966+
if len(spec.Env) > 0 {
967+
envVars = appendEnvVars(envVars, spec.Env...)
968+
}
969+
965970
if spec.Clone != nil && spec.Clone.ClusterName != "" {
966971
envVars = append(envVars, c.generateCloneEnvironment(spec.Clone)...)
967972
}
@@ -970,11 +975,6 @@ func (c *Cluster) generateSpiloPodEnvVars(
970975
envVars = append(envVars, c.generateStandbyEnvironment(spec.StandbyCluster)...)
971976
}
972977

973-
// fetch cluster-specific variables that will override all subsequent global variables
974-
if len(spec.Env) > 0 {
975-
envVars = appendEnvVars(envVars, spec.Env...)
976-
}
977-
978978
// fetch variables from custom environment Secret
979979
// that will override all subsequent global variables
980980
secretEnvVarsList, err := c.getPodEnvironmentSecretVariables()

pkg/cluster/k8sres_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,23 @@ func TestGenerateSpiloPodEnvVars(t *testing.T) {
602602
envVarValue: "s3.eu-central-1.amazonaws.com",
603603
},
604604
}
605+
expectedCloneEnvSpecEnv := []ExpectedValue{
606+
{
607+
envIndex: 15,
608+
envVarConstant: "CLONE_WAL_BUCKET_SCOPE_PREFIX",
609+
envVarValue: "test-cluster",
610+
},
611+
{
612+
envIndex: 17,
613+
envVarConstant: "CLONE_WALE_S3_PREFIX",
614+
envVarValue: "s3://another-bucket",
615+
},
616+
{
617+
envIndex: 21,
618+
envVarConstant: "CLONE_AWS_ENDPOINT",
619+
envVarValue: "s3.eu-central-1.amazonaws.com",
620+
},
621+
}
605622
expectedCloneEnvConfigMap := []ExpectedValue{
606623
{
607624
envIndex: 16,
@@ -821,6 +838,36 @@ func TestGenerateSpiloPodEnvVars(t *testing.T) {
821838
standbyDescription: &acidv1.StandbyDescription{},
822839
expectedValues: expectedCloneEnvSpec,
823840
},
841+
{
842+
subTest: "will set CLONE_ parameters from manifest `env` section, followed by other options",
843+
opConfig: config.Config{
844+
Resources: config.Resources{
845+
PodEnvironmentConfigMap: spec.NamespacedName{
846+
Name: testPodEnvironmentConfigMapName,
847+
},
848+
},
849+
WALES3Bucket: "global-s3-bucket",
850+
},
851+
cloneDescription: &acidv1.CloneDescription{
852+
ClusterName: "test-cluster",
853+
EndTimestamp: "somewhen",
854+
UID: dummyUUID,
855+
S3WalPath: "s3://another-bucket",
856+
S3Endpoint: "s3.eu-central-1.amazonaws.com",
857+
},
858+
standbyDescription: &acidv1.StandbyDescription{},
859+
expectedValues: expectedCloneEnvSpecEnv,
860+
pgsql: acidv1.Postgresql{
861+
Spec: acidv1.PostgresSpec{
862+
Env: []v1.EnvVar{
863+
{
864+
Name: "CLONE_WAL_BUCKET_SCOPE_PREFIX",
865+
Value: "test-cluster",
866+
},
867+
},
868+
},
869+
},
870+
},
824871
{
825872
subTest: "will set CLONE_AWS_ENDPOINT parameter from pod environment config map",
826873
opConfig: config.Config{

0 commit comments

Comments
 (0)