Skip to content

Commit 9471885

Browse files
committed
apply recommendations
Signed-off-by: Benedikt Bongartz <[email protected]>
1 parent 5773a44 commit 9471885

File tree

5 files changed

+18
-12
lines changed

5 files changed

+18
-12
lines changed

.chloggen/native_sidecar.yaml

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
change_type: enhancement
33

44
# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
5-
component: pkg/sidecar
5+
component: collector
66

77
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
88
note: Add native sidecar injection behind a feature gate which is disabled by default.
@@ -13,4 +13,9 @@ issues: [2376]
1313
# (Optional) One or more lines of additional information to render under the primary note.
1414
# These lines will be padded with 2 spaces and then inserted directly into the document.
1515
# Use pipe (|) for multiline entries.
16-
subtext:
16+
subtext: |
17+
Native sidecars are supported since Kubernetes version `1.28` and are availabe by default since `1.29`.
18+
To use native sidecars on Kubernetes v1.28 make sure the "SidecarContainers" feature gate on kubernetes is enabled.
19+
If native sidecars are available, the operator can be advised to use them by adding adding
20+
the `--feature-gates=operator.sidecarcontainers.native` to the Operator args.
21+
In the future this may will become availabe as deployment mode on the Collector CR. See [#3356](https://github.com/open-telemetry/opentelemetry-operator/issues/3356)

pkg/sidecar/pod.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -70,34 +70,34 @@ func add(cfg config.Config, logger logr.Logger, otelcol v1beta1.OpenTelemetryCol
7070
return pod, nil
7171
}
7272

73+
func isOtelColContainer(c corev1.Container) bool { return c.Name == naming.Container() }
74+
7375
// remove the sidecar container from the given pod.
7476
func remove(pod corev1.Pod) corev1.Pod {
7577
if !existsIn(pod) {
7678
return pod
7779
}
7880

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)
8182

8283
if featuregate.EnableNativeSidecarContainers.IsEnabled() {
8384
// NOTE: we also remove init containers (native sidecars) since k8s 1.28.
8485
// 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)
8687
}
8788
return pod
8889
}
8990

9091
// existsIn checks whether a sidecar container exists in the given pod.
9192
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) {
9494
return true
9595
}
9696

9797
if featuregate.EnableNativeSidecarContainers.IsEnabled() {
9898
// NOTE: we also check init containers (native sidecars) since k8s 1.28.
9999
// This should have no side effects.
100-
if slices.ContainsFunc(pod.Spec.InitContainers, fn) {
100+
if slices.ContainsFunc(pod.Spec.InitContainers, isOtelColContainer) {
101101
return true
102102
}
103103
}

pkg/sidecar/pod_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232

3333
var logger = logf.Log.WithName("unit-tests")
3434

35-
func sidecarFeatureGate(t *testing.T) {
35+
func enableSidecarFeatureGate(t *testing.T) {
3636
originalVal := featuregate.EnableNativeSidecarContainers.IsEnabled()
3737
t.Logf("original is: %+v", originalVal)
3838
require.NoError(t, colfeaturegate.GlobalRegistry().Set(featuregate.EnableNativeSidecarContainers.ID(), true))
@@ -42,7 +42,7 @@ func sidecarFeatureGate(t *testing.T) {
4242
}
4343

4444
func TestAddNativeSidecar(t *testing.T) {
45-
sidecarFeatureGate(t)
45+
enableSidecarFeatureGate(t)
4646
// prepare
4747
pod := corev1.Pod{
4848
Spec: corev1.PodSpec{
@@ -269,7 +269,7 @@ func TestRemoveNonExistingSidecar(t *testing.T) {
269269
}
270270

271271
func TestExistsIn(t *testing.T) {
272-
sidecarFeatureGate(t)
272+
enableSidecarFeatureGate(t)
273273

274274
for _, tt := range []struct {
275275
desc string

tests/e2e-native-sidecar/00-assert.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ spec:
1010
- name: myapp
1111
initContainers:
1212
- name: otc-container
13+
restartPolicy: Always
1314
status:
1415
containerStatuses:
1516
- name: myapp

tests/e2e-native-sidecar/00-install.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ metadata:
3535
spec:
3636
containers:
3737
- name: myapp
38-
image: jaegertracing/vertx-create-span:operator-e2e-tests
38+
image: ghcr.io/open-telemetry/opentelemetry-operator/e2e-test-app-python:main
3939
ports:
4040
- containerPort: 8080
4141
protocol: TCP

0 commit comments

Comments
 (0)