Skip to content

Commit 30ba9b7

Browse files
committed
use slices.DeleteFunc to remove init container
Signed-off-by: Benedikt Bongartz <[email protected]>
1 parent 60e8a8e commit 30ba9b7

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

pkg/sidecar/pod.go

+7-8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package sidecar
1717

1818
import (
1919
"fmt"
20+
"slices"
2021

2122
"github.com/go-logr/logr"
2223
corev1 "k8s.io/api/core/v1"
@@ -83,15 +84,13 @@ func remove(pod corev1.Pod) corev1.Pod {
8384
}
8485
pod.Spec.Containers = containers
8586

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+
})
9393
}
94-
pod.Spec.InitContainers = initContainers
9594
return pod
9695
}
9796

0 commit comments

Comments
 (0)