Always inject ENV variables, and also in init containers
@@ -676,9 +676,9 @@ func (r *ReconcileExtendedStatefulSet) generateSingleStatefulSet(extendedStatefu
statefulSet.Spec.Template.SetAnnotations(podAnnotations)
statefulSet = r.updateAffinity(statefulSet, extendedStatefulSet.Spec.ZoneNodeLabel, zoneIndex, zone)
+ }
r.injectContainerEnv(&statefulSet.Spec.Template.Spec, zoneIndex, zone, extendedStatefulSet.Spec.Template.Spec.Replicas)
- }
annotations[essv1a1.AnnotationStatefulSetSHA1] = templateSha1
annotations[essv1a1.AnnotationVersion] = fmt.Sprintf("%d", version)
@@ -753,16 +753,29 @@ func (r *ReconcileExtendedStatefulSet) updateAffinity(statefulSet *v1beta2.State
// injectContainerEnv inject AZ info to container envs
func (r *ReconcileExtendedStatefulSet) injectContainerEnv(podSpec *corev1.PodSpec, zoneIndex int, zoneName string, replicas *int32) {
+
+ containers := []*corev1.Container{}
for i := 0; i < len(podSpec.Containers); i++ {
- envs := podSpec.Containers[i].Env
+ containers = append(containers, &podSpec.Containers[i])
+ }
+ for i := 0; i < len(podSpec.InitContainers); i++ {
+ containers = append(containers, &podSpec.InitContainers[i])
+ }
+ for _, container := range containers {
+ envs := container.Env
+ if zoneIndex >= 0 {
envs = upsertEnvs(envs, EnvKubeAz, zoneName)
envs = upsertEnvs(envs, EnvBoshAz, zoneName)
envs = upsertEnvs(envs, EnvCfOperatorAz, zoneName)
- envs = upsertEnvs(envs, EnvCfOperatorAzIndex, strconv.Itoa(zoneIndex))
+ envs = upsertEnvs(envs, EnvCfOperatorAzIndex, strconv.Itoa(zoneIndex+1))
+ } else {
+ // Default to zone 1
+ envs = upsertEnvs(envs, EnvCfOperatorAzIndex, "1")
+ }
envs = upsertEnvs(envs, EnvReplicas, strconv.Itoa(int(*replicas)))
- podSpec.Containers[i].Env = envs
+ container.Env = envs
}
}
