@@ -70,34 +70,34 @@ func add(cfg config.Config, logger logr.Logger, otelcol v1beta1.OpenTelemetryCol
70
70
return pod , nil
71
71
}
72
72
73
+ func isOtelColContainer (c corev1.Container ) bool { return c .Name == naming .Container () }
74
+
73
75
// remove the sidecar container from the given pod.
74
76
func remove (pod corev1.Pod ) corev1.Pod {
75
77
if ! existsIn (pod ) {
76
78
return pod
77
79
}
78
80
79
- fn := func (c corev1.Container ) bool { return c .Name == naming .Container () }
80
- pod .Spec .Containers = slices .DeleteFunc (pod .Spec .Containers , fn )
81
+ pod .Spec .Containers = slices .DeleteFunc (pod .Spec .Containers , isOtelColContainer )
81
82
82
83
if featuregate .EnableNativeSidecarContainers .IsEnabled () {
83
84
// NOTE: we also remove init containers (native sidecars) since k8s 1.28.
84
85
// This should have no side effects.
85
- pod .Spec .InitContainers = slices .DeleteFunc (pod .Spec .InitContainers , fn )
86
+ pod .Spec .InitContainers = slices .DeleteFunc (pod .Spec .InitContainers , isOtelColContainer )
86
87
}
87
88
return pod
88
89
}
89
90
90
91
// existsIn checks whether a sidecar container exists in the given pod.
91
92
func existsIn (pod corev1.Pod ) bool {
92
- fn := func (c corev1.Container ) bool { return c .Name == naming .Container () }
93
- if slices .ContainsFunc (pod .Spec .Containers , fn ) {
93
+ if slices .ContainsFunc (pod .Spec .Containers , isOtelColContainer ) {
94
94
return true
95
95
}
96
96
97
97
if featuregate .EnableNativeSidecarContainers .IsEnabled () {
98
98
// NOTE: we also check init containers (native sidecars) since k8s 1.28.
99
99
// This should have no side effects.
100
- if slices .ContainsFunc (pod .Spec .InitContainers , fn ) {
100
+ if slices .ContainsFunc (pod .Spec .InitContainers , isOtelColContainer ) {
101
101
return true
102
102
}
103
103
}
0 commit comments