Skip to content

Commit 640581f

Browse files
authored
Fix the Operator rolling update statefulsets unnecessary whien Kube API down (zalando#2031) (zalando#2064)
1 parent 03ccb42 commit 640581f

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

pkg/cluster/k8sres.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ func (c *Cluster) generatePodTemplate(
799799
func (c *Cluster) generateSpiloPodEnvVars(
800800
spec *acidv1.PostgresSpec,
801801
uid types.UID,
802-
spiloConfiguration string) []v1.EnvVar {
802+
spiloConfiguration string) ([]v1.EnvVar, error) {
803803

804804
// hard-coded set of environment variables we need
805805
// to guarantee core functionality of the operator
@@ -922,15 +922,15 @@ func (c *Cluster) generateSpiloPodEnvVars(
922922
// that will override all subsequent global variables
923923
secretEnvVarsList, err := c.getPodEnvironmentSecretVariables()
924924
if err != nil {
925-
c.logger.Warningf("%v", err)
925+
return nil, err
926926
}
927927
envVars = appendEnvVars(envVars, secretEnvVarsList...)
928928

929929
// fetch variables from custom environment ConfigMap
930930
// that will override all subsequent global variables
931931
configMapEnvVarsList, err := c.getPodEnvironmentConfigMapVariables()
932932
if err != nil {
933-
c.logger.Warningf("%v", err)
933+
return nil, err
934934
}
935935
envVars = appendEnvVars(envVars, configMapEnvVarsList...)
936936

@@ -966,7 +966,7 @@ func (c *Cluster) generateSpiloPodEnvVars(
966966

967967
envVars = appendEnvVars(envVars, opConfigEnvVars...)
968968

969-
return envVars
969+
return envVars, nil
970970
}
971971

972972
func appendEnvVars(envs []v1.EnvVar, appEnv ...v1.EnvVar) []v1.EnvVar {
@@ -1185,7 +1185,10 @@ func (c *Cluster) generateStatefulSet(spec *acidv1.PostgresSpec) (*appsv1.Statef
11851185
}
11861186

11871187
// generate environment variables for the spilo container
1188-
spiloEnvVars := c.generateSpiloPodEnvVars(spec, c.Postgresql.GetUID(), spiloConfiguration)
1188+
spiloEnvVars, err := c.generateSpiloPodEnvVars(spec, c.Postgresql.GetUID(), spiloConfiguration)
1189+
if err != nil {
1190+
return nil, fmt.Errorf("could not generate Spilo env vars: %v", err)
1191+
}
11891192

11901193
// pickup the docker image for the spilo container
11911194
effectiveDockerImage := util.Coalesce(spec.DockerImage, c.OpConfig.DockerImage)

pkg/cluster/k8sres_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,8 @@ func TestGenerateSpiloPodEnvVars(t *testing.T) {
841841
pgsql.Spec.StandbyCluster = tt.standbyDescription
842842
c.Postgresql = pgsql
843843

844-
actualEnvs := c.generateSpiloPodEnvVars(&pgsql.Spec, types.UID(dummyUUID), exampleSpiloConfig)
844+
actualEnvs, err := c.generateSpiloPodEnvVars(&pgsql.Spec, types.UID(dummyUUID), exampleSpiloConfig)
845+
assert.NoError(t, err)
845846

846847
for _, ev := range tt.expectedValues {
847848
env := actualEnvs[ev.envIndex]

0 commit comments

Comments
 (0)