File tree 1 file changed +7
-8
lines changed
1 file changed +7
-8
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ package sidecar
17
17
18
18
import (
19
19
"fmt"
20
+ "slices"
20
21
21
22
"github.com/go-logr/logr"
22
23
corev1 "k8s.io/api/core/v1"
@@ -83,15 +84,13 @@ func remove(pod corev1.Pod) corev1.Pod {
83
84
}
84
85
pod .Spec .Containers = containers
85
86
86
- // NOTE: we also remove init containers (native sidecars) since k8s 1.28.
87
- // This should have no side effects.
88
- var initContainers []corev1.Container
89
- for _ , initContainer := range pod .Spec .InitContainers {
90
- if initContainer .Name != naming .Container () {
91
- initContainers = append (initContainers , initContainer )
92
- }
87
+ if featuregate .EnableNativeSidecarContainers .IsEnabled () {
88
+ // NOTE: we also remove init containers (native sidecars) since k8s 1.28.
89
+ // This should have no side effects.
90
+ pod .Spec .InitContainers = slices .DeleteFunc (pod .Spec .InitContainers , func (c corev1.Container ) bool {
91
+ return c .Name == naming .Container ()
92
+ })
93
93
}
94
- pod .Spec .InitContainers = initContainers
95
94
return pod
96
95
}
97
96
You can’t perform that action at this time.
0 commit comments