diff --git a/pkg/server/webhook.go b/pkg/server/webhook.go index a966b50..77da745 100644 --- a/pkg/server/webhook.go +++ b/pkg/server/webhook.go @@ -396,6 +396,11 @@ func createPatch(pod *corev1.Pod, inj *config.InjectionConfig, annotations map[s mutatedInjectedContainers := mergeEnvVars(inj.Environment, inj.Containers) mutatedInjectedContainers = mergeVolumeMounts(inj.VolumeMounts, mutatedInjectedContainers) + // next, make sure any injected init containers in our config get the EnvVars and VolumeMounts injected + // this mutates inj.InitContainers with our environment vars + mutatedInjectedInitContainers := mergeEnvVars(inj.Environment, inj.InitContainers) + mutatedInjectedInitContainers = mergeVolumeMounts(inj.VolumeMounts, mutatedInjectedInitContainers) + // next, patch containers with our injected containers patch = append(patch, addContainers(pod.Spec.Containers, mutatedInjectedContainers, "/spec/containers")...) @@ -404,7 +409,7 @@ func createPatch(pod *corev1.Pod, inj *config.InjectionConfig, annotations map[s patch = append(patch, addVolumeMounts(pod.Spec.Containers, inj.VolumeMounts)...) // now, add initContainers, hostAliases and volumes - patch = append(patch, addContainers(pod.Spec.InitContainers, inj.InitContainers, "/spec/initContainers")...) + patch = append(patch, addContainers(pod.Spec.InitContainers, mutatedInjectedInitContainers, "/spec/initContainers")...) patch = append(patch, addHostAliases(pod.Spec.HostAliases, inj.HostAliases, "/spec/hostAliases")...) patch = append(patch, addVolumes(pod.Spec.Volumes, inj.Volumes, "/spec/volumes")...)