spec.env can override clone and standby variables (#2159)

This commit is contained in:
Felix Kunde 2023-01-05 12:02:19 +01:00 committed by GitHub
parent becf8a4715
commit c756cb2f8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 8 deletions

View File

@ -631,9 +631,9 @@ order (e.g. a variable defined in 4. overrides a variable with the same name
in 5.): in 5.):
1. Assigned by the operator 1. Assigned by the operator
2. Clone section (with WAL settings from operator config when `s3_wal_path` is empty) 2. `env` section in cluster manifest
3. Standby section 3. Clone section (with WAL settings from operator config when `s3_wal_path` is empty)
4. `env` section in cluster manifest 4. Standby section
5. Pod environment secret via operator config 5. Pod environment secret via operator config
6. Pod environment config map via operator config 6. Pod environment config map via operator config
7. WAL and logical backup settings from operator config 7. WAL and logical backup settings from operator config

View File

@ -962,6 +962,11 @@ func (c *Cluster) generateSpiloPodEnvVars(
envVars = append(envVars, v1.EnvVar{Name: "KUBERNETES_USE_CONFIGMAPS", Value: "true"}) envVars = append(envVars, v1.EnvVar{Name: "KUBERNETES_USE_CONFIGMAPS", Value: "true"})
} }
// fetch cluster-specific variables that will override all subsequent global variables
if len(spec.Env) > 0 {
envVars = appendEnvVars(envVars, spec.Env...)
}
if spec.Clone != nil && spec.Clone.ClusterName != "" { if spec.Clone != nil && spec.Clone.ClusterName != "" {
envVars = append(envVars, c.generateCloneEnvironment(spec.Clone)...) envVars = append(envVars, c.generateCloneEnvironment(spec.Clone)...)
} }
@ -970,11 +975,6 @@ func (c *Cluster) generateSpiloPodEnvVars(
envVars = append(envVars, c.generateStandbyEnvironment(spec.StandbyCluster)...) envVars = append(envVars, c.generateStandbyEnvironment(spec.StandbyCluster)...)
} }
// fetch cluster-specific variables that will override all subsequent global variables
if len(spec.Env) > 0 {
envVars = appendEnvVars(envVars, spec.Env...)
}
// fetch variables from custom environment Secret // fetch variables from custom environment Secret
// that will override all subsequent global variables // that will override all subsequent global variables
secretEnvVarsList, err := c.getPodEnvironmentSecretVariables() secretEnvVarsList, err := c.getPodEnvironmentSecretVariables()

View File

@ -602,6 +602,23 @@ func TestGenerateSpiloPodEnvVars(t *testing.T) {
envVarValue: "s3.eu-central-1.amazonaws.com", envVarValue: "s3.eu-central-1.amazonaws.com",
}, },
} }
expectedCloneEnvSpecEnv := []ExpectedValue{
{
envIndex: 15,
envVarConstant: "CLONE_WAL_BUCKET_SCOPE_PREFIX",
envVarValue: "test-cluster",
},
{
envIndex: 17,
envVarConstant: "CLONE_WALE_S3_PREFIX",
envVarValue: "s3://another-bucket",
},
{
envIndex: 21,
envVarConstant: "CLONE_AWS_ENDPOINT",
envVarValue: "s3.eu-central-1.amazonaws.com",
},
}
expectedCloneEnvConfigMap := []ExpectedValue{ expectedCloneEnvConfigMap := []ExpectedValue{
{ {
envIndex: 16, envIndex: 16,
@ -821,6 +838,36 @@ func TestGenerateSpiloPodEnvVars(t *testing.T) {
standbyDescription: &acidv1.StandbyDescription{}, standbyDescription: &acidv1.StandbyDescription{},
expectedValues: expectedCloneEnvSpec, expectedValues: expectedCloneEnvSpec,
}, },
{
subTest: "will set CLONE_ parameters from manifest `env` section, followed by other options",
opConfig: config.Config{
Resources: config.Resources{
PodEnvironmentConfigMap: spec.NamespacedName{
Name: testPodEnvironmentConfigMapName,
},
},
WALES3Bucket: "global-s3-bucket",
},
cloneDescription: &acidv1.CloneDescription{
ClusterName: "test-cluster",
EndTimestamp: "somewhen",
UID: dummyUUID,
S3WalPath: "s3://another-bucket",
S3Endpoint: "s3.eu-central-1.amazonaws.com",
},
standbyDescription: &acidv1.StandbyDescription{},
expectedValues: expectedCloneEnvSpecEnv,
pgsql: acidv1.Postgresql{
Spec: acidv1.PostgresSpec{
Env: []v1.EnvVar{
{
Name: "CLONE_WAL_BUCKET_SCOPE_PREFIX",
Value: "test-cluster",
},
},
},
},
},
{ {
subTest: "will set CLONE_AWS_ENDPOINT parameter from pod environment config map", subTest: "will set CLONE_AWS_ENDPOINT parameter from pod environment config map",
opConfig: config.Config{ opConfig: config.Config{