Skip to content

Commit

Permalink
Merge pull request #30 from h0n9/feature/29-make-injector-first-init-…
Browse files Browse the repository at this point in the history
…container

Make injector get injected as first init container
  • Loading branch information
h0n9 authored Jun 4, 2024
2 parents 5d3f314 + 222e411 commit 200454a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions webhook/mutator.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ func (mutator *Mutator) Handle(ctx context.Context, req admission.Request) admis
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{}},
})

// inject sidecar
pod.Spec.InitContainers = append(pod.Spec.InitContainers, corev1.Container{
// create init container for injection
initContainer := corev1.Container{
Name: injectorName,
Image: mutator.InjectorImage,
Args: []string{
Expand All @@ -87,7 +87,10 @@ func (mutator *Mutator) Handle(ctx context.Context, req admission.Request) admis
MountPath: csm.InjectorVolumeMountPath,
},
},
})
}

// append init container to pod's init containers
pod.Spec.InitContainers = append([]corev1.Container{initContainer}, pod.Spec.InitContainers...)

// mount volume to every containers
for i := range pod.Spec.Containers {
Expand Down

0 comments on commit 200454a

Please sign in to comment.