@@ -3,6 +3,7 @@ package podtemplatespec
33import (
44 "github.com/imdario/mergo"
55 "github.com/mongodb/mongodb-kubernetes-operator/pkg/kube/container"
6+ "github.com/mongodb/mongodb-kubernetes-operator/pkg/util/envvar"
67 corev1 "k8s.io/api/core/v1"
78 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
89)
@@ -297,11 +298,14 @@ func mergeContainers(defaultContainers, customContainers []corev1.Container) ([]
297298 for _ , defaultContainer := range defaultContainers {
298299 if customContainer , ok := customMap [defaultContainer .Name ]; ok {
299300 // The container is present in both maps, so we need to merge
300- // Merge mounts
301+ // MergeWithOverride mounts
301302 mergedMounts , err := mergeVolumeMounts (defaultContainer .VolumeMounts , customContainer .VolumeMounts )
302303 if err != nil {
303304 return nil , err
304305 }
306+
307+ mergedEnvs := envvar .MergeWithOverride (defaultContainer .Env , customContainer .Env )
308+
305309 if err := mergo .Merge (& defaultContainer , customContainer , mergo .WithOverride ); err != nil { //nolint
306310 return nil , err
307311 }
@@ -310,6 +314,7 @@ func mergeContainers(defaultContainers, customContainers []corev1.Container) ([]
310314 // to the defaulted limits
311315 defaultContainer .Resources = customContainer .Resources
312316 defaultContainer .VolumeMounts = mergedMounts
317+ defaultContainer .Env = mergedEnvs
313318 }
314319 // The default container was not modified by the override, so just add it
315320 mergedContainers = append (mergedContainers , defaultContainer )
0 commit comments