Skip to content

Commit c5b3cc9

Browse files
author
Pavel Zaytsev
committed
Allow user env vars to override operator-generated ones
This change modifies appendEnvVars() to allow environment variables defined in the PostgreSQL CRD spec.env to override operator-generated environment variables (like SPILO_CONFIGURATION) instead of being silently ignored. Previously, if an env var already existed in the list, user-provided values were skipped. Now, user values take precedence and replace the operator-generated ones. This enables users to customize SPILO_CONFIGURATION and other operator-managed env vars through the CRD, which is useful for adding custom Patroni DCS configuration like ignore_slots.
1 parent 2c57498 commit c5b3cc9

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

pkg/cluster/k8sres.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,20 @@ func (c *Cluster) generateSpiloPodEnvVars(
10881088
func appendEnvVars(envs []v1.EnvVar, appEnv ...v1.EnvVar) []v1.EnvVar {
10891089
collectedEnvs := envs
10901090
for _, env := range appEnv {
1091-
if !isEnvVarPresent(collectedEnvs, env.Name) {
1091+
// Check if env var already exists
1092+
existingIdx := -1
1093+
for i, existing := range collectedEnvs {
1094+
if strings.EqualFold(existing.Name, env.Name) {
1095+
existingIdx = i
1096+
break
1097+
}
1098+
}
1099+
1100+
if existingIdx >= 0 {
1101+
// Replace existing env var (user override takes precedence)
1102+
collectedEnvs[existingIdx] = env
1103+
} else {
1104+
// Add new env var
10921105
collectedEnvs = append(collectedEnvs, env)
10931106
}
10941107
}

0 commit comments

Comments
 (0)