Skip to content

Commit 0e255f8

Browse files
committed
Provide more information about variable conflicts.
They are mentioned in the documentation and the operator will emit a warning each time the variable from the pod environment configmap is ignored because the same variable is defined by the operator. Some minor changes in the variable names to make the code more readable. Per review from Sergey Dudoladov.
1 parent da4b662 commit 0e255f8

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ data:
178178

179179
This ConfigMap is then added as a source of environment variables to the Postgres StatefulSet/pods.
180180

181+
:exclamation: Note that there are environment variables defined by the operator itself in order to pass parameters to the Spilo image. The values from the operator for those variables will take precedence over those defined in the `pod_environment_configmap`.
182+
181183
# Setup development environment
182184

183185
The following steps guide you through the setup to work on the operator itself.

pkg/cluster/k8sres.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ func (c *Cluster) generatePodTemplate(resourceRequirements *v1.ResourceRequireme
282282
patroniParameters *spec.Patroni,
283283
cloneDescription *spec.CloneDescription,
284284
dockerImage *string,
285-
extraEnv map[string]string) *v1.PodTemplateSpec {
285+
customPodEnvVars map[string]string) *v1.PodTemplateSpec {
286286
spiloConfiguration := c.generateSpiloJSONConfiguration(pgParameters, patroniParameters)
287287

288288
envVars := []v1.EnvVar{
@@ -373,14 +373,17 @@ func (c *Cluster) generatePodTemplate(resourceRequirements *v1.ResourceRequireme
373373
for _, envVar := range envVars {
374374
envVarsMap[envVar.Name] = envVar.Value
375375
}
376-
for name := range extraEnv {
376+
for name := range customPodEnvVars {
377377
if _, ok := envVarsMap[name]; !ok {
378378
names = append(names, name)
379+
} else {
380+
c.logger.Warningf("variable %q value from %q is ignored: conflict with the definition from the operator",
381+
name, c.OpConfig.PodEnvironmentConfigMap)
379382
}
380383
}
381384
sort.Strings(names)
382385
for _, name := range names {
383-
envVars = append(envVars, v1.EnvVar{Name: name, Value: extraEnv[name]})
386+
envVars = append(envVars, v1.EnvVar{Name: name, Value: customPodEnvVars[name]})
384387
}
385388

386389
privilegedMode := true
@@ -447,15 +450,15 @@ func (c *Cluster) generateStatefulSet(spec *spec.PostgresSpec) (*v1beta1.Statefu
447450
if err != nil {
448451
return nil, fmt.Errorf("could not generate resource requirements: %v", err)
449452
}
450-
var extraEnv map[string]string
453+
var customPodEnvVars map[string]string
451454
if c.OpConfig.PodEnvironmentConfigMap != "" {
452455
if cm, err := c.KubeClient.ConfigMaps(c.Namespace).Get(c.OpConfig.PodEnvironmentConfigMap, metav1.GetOptions{}); err != nil {
453456
return nil, fmt.Errorf("could not read PodEnvironmentConfigMap: %v", err)
454457
} else {
455-
extraEnv = cm.Data
458+
customPodEnvVars = cm.Data
456459
}
457460
}
458-
podTemplate := c.generatePodTemplate(resourceRequirements, &spec.Tolerations, &spec.PostgresqlParam, &spec.Patroni, &spec.Clone, &spec.DockerImage, extraEnv)
461+
podTemplate := c.generatePodTemplate(resourceRequirements, &spec.Tolerations, &spec.PostgresqlParam, &spec.Patroni, &spec.Clone, &spec.DockerImage, customPodEnvVars)
459462
volumeClaimTemplate, err := generatePersistentVolumeClaimTemplate(spec.Volume.Size, spec.Volume.StorageClass)
460463
if err != nil {
461464
return nil, fmt.Errorf("could not generate volume claim template: %v", err)

0 commit comments

Comments
 (0)