Skip to content

Commit 058c14f

Browse files
committed
add featuregate for k8s 1.28 native sidecar container
Signed-off-by: Benedikt Bongartz <[email protected]>
1 parent 60d37e1 commit 058c14f

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

.chloggen/native_sidecar.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
2+
change_type: enhancement
3+
4+
# 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
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: Add native sidecar injection behind a feature gate which is disabled by default.
9+
10+
# One or more tracking issues related to the change
11+
issues: [2376]
12+
13+
# (Optional) One or more lines of additional information to render under the primary note.
14+
# These lines will be padded with 2 spaces and then inserted directly into the document.
15+
# Use pipe (|) for multiline entries.
16+
subtext:

pkg/featuregate/featuregate.go

+13
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ const (
2525
)
2626

2727
var (
28+
// EnableNativeSidecarContainers is the feature gate that controls whether a
29+
// sidecar should be injected as a native sidecar or the classic way.
30+
// Native sidecar containers have been available since kubernetes v1.28 in
31+
// alpha and v1.29 in beta.
32+
// It needs to be enabled with +featureGate=SidecarContainers.
33+
// See:
34+
// https://kubernetes.io/docs/reference/command-line-tools-reference/feature-gates/#feature-gates-for-alpha-or-beta-features
35+
EnableNativeSidecarContainers = featuregate.GlobalRegistry().MustRegister(
36+
"operator.sidecarcontainers.native",
37+
featuregate.StageAlpha,
38+
featuregate.WithRegisterDescription("controls whether the operator supports sidecar containers as init containers"),
39+
featuregate.WithRegisterFromVersion("v0.98.0"),
40+
)
2841
EnableJavaAutoInstrumentationSupport = featuregate.GlobalRegistry().MustRegister(
2942
"operator.autoinstrumentation.java",
3043
featuregate.StageBeta,

pkg/sidecar/pod.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/open-telemetry/opentelemetry-operator/internal/config"
2626
"github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector"
2727
"github.com/open-telemetry/opentelemetry-operator/internal/naming"
28+
"github.com/open-telemetry/opentelemetry-operator/pkg/featuregate"
2829
)
2930

3031
const (
@@ -47,7 +48,14 @@ func add(cfg config.Config, logger logr.Logger, otelcol v1beta1.OpenTelemetryCol
4748
container.Env = append(container.Env, attributes...)
4849
}
4950
pod.Spec.InitContainers = append(pod.Spec.InitContainers, otelcol.Spec.InitContainers...)
50-
pod.Spec.Containers = append(pod.Spec.Containers, container)
51+
52+
if featuregate.EnableNativeSidecarContainers.IsEnabled() {
53+
policy := corev1.ContainerRestartPolicyAlways
54+
container.RestartPolicy = &policy
55+
pod.Spec.InitContainers = append(pod.Spec.InitContainers, container)
56+
} else {
57+
pod.Spec.Containers = append(pod.Spec.Containers, container)
58+
}
5159
pod.Spec.Volumes = append(pod.Spec.Volumes, otelcol.Spec.Volumes...)
5260

5361
if pod.Labels == nil {

0 commit comments

Comments
 (0)