Skip to content

Commit

Permalink
add featuregate for k8s 1.28 native sidecar container
Browse files Browse the repository at this point in the history
Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>
  • Loading branch information
frzifus committed Mar 29, 2024
1 parent 60d37e1 commit 058c14f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
16 changes: 16 additions & 0 deletions .chloggen/native_sidecar.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add native sidecar injection behind a feature gate which is disabled by default.

# One or more tracking issues related to the change
issues: [2376]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
13 changes: 13 additions & 0 deletions pkg/featuregate/featuregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ const (
)

var (
// EnableNativeSidecarContainers is the feature gate that controls whether a
// sidecar should be injected as a native sidecar or the classic way.
// Native sidecar containers have been available since kubernetes v1.28 in
// alpha and v1.29 in beta.
// It needs to be enabled with +featureGate=SidecarContainers.
// See:
// https://kubernetes.io/docs/reference/command-line-tools-reference/feature-gates/#feature-gates-for-alpha-or-beta-features
EnableNativeSidecarContainers = featuregate.GlobalRegistry().MustRegister(
"operator.sidecarcontainers.native",
featuregate.StageAlpha,
featuregate.WithRegisterDescription("controls whether the operator supports sidecar containers as init containers"),
featuregate.WithRegisterFromVersion("v0.98.0"),
)
EnableJavaAutoInstrumentationSupport = featuregate.GlobalRegistry().MustRegister(
"operator.autoinstrumentation.java",
featuregate.StageBeta,
Expand Down
10 changes: 9 additions & 1 deletion pkg/sidecar/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/open-telemetry/opentelemetry-operator/internal/config"
"github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector"
"github.com/open-telemetry/opentelemetry-operator/internal/naming"
"github.com/open-telemetry/opentelemetry-operator/pkg/featuregate"
)

const (
Expand All @@ -47,7 +48,14 @@ func add(cfg config.Config, logger logr.Logger, otelcol v1beta1.OpenTelemetryCol
container.Env = append(container.Env, attributes...)
}
pod.Spec.InitContainers = append(pod.Spec.InitContainers, otelcol.Spec.InitContainers...)
pod.Spec.Containers = append(pod.Spec.Containers, container)

if featuregate.EnableNativeSidecarContainers.IsEnabled() {
policy := corev1.ContainerRestartPolicyAlways
container.RestartPolicy = &policy
pod.Spec.InitContainers = append(pod.Spec.InitContainers, container)
} else {
pod.Spec.Containers = append(pod.Spec.Containers, container)
}
pod.Spec.Volumes = append(pod.Spec.Volumes, otelcol.Spec.Volumes...)

if pod.Labels == nil {
Expand Down

0 comments on commit 058c14f

Please sign in to comment.