diff --git a/apis/v1alpha1/opentelemetrycollector_types.go b/apis/v1alpha1/opentelemetrycollector_types.go index cb346ca80f..a8a9e7976c 100644 --- a/apis/v1alpha1/opentelemetrycollector_types.go +++ b/apis/v1alpha1/opentelemetrycollector_types.go @@ -215,6 +215,9 @@ type OpenTelemetryCollectorSpec struct { // HostNetwork indicates if the pod should run in the host networking namespace. // +optional HostNetwork bool `json:"hostNetwork,omitempty"` + // ShareNetworkProcess indicates if the pod's containers should share process namespace. + // +optional + ShareNetworkProcess bool `json:"shareNetworkProcess,omitempty"` // If specified, indicates the pod's priority. // If not specified, the pod priority will be default or zero if there is no // default. diff --git a/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml b/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml index 56f84cbb6e..a8aa28fd4f 100644 --- a/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml +++ b/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml @@ -4223,6 +4223,10 @@ spec: account to use with this instance. When set, the operator will not automatically create a ServiceAccount for the collector. type: string + shareNetworkProcess: + description: ShareNetworkProcess indicates if the pod's containers + should share process namespace. + type: boolean targetAllocator: description: TargetAllocator indicates a value which determines whether to spawn a target allocation resource or not. diff --git a/internal/manifests/collector/daemonset.go b/internal/manifests/collector/daemonset.go index 8566ee0828..91cecbfd5e 100644 --- a/internal/manifests/collector/daemonset.go +++ b/internal/manifests/collector/daemonset.go @@ -48,17 +48,18 @@ func DaemonSet(params manifests.Params) *appsv1.DaemonSet { Annotations: podAnnotations, }, Spec: corev1.PodSpec{ - ServiceAccountName: ServiceAccountName(params.OtelCol), - InitContainers: params.OtelCol.Spec.InitContainers, - Containers: append(params.OtelCol.Spec.AdditionalContainers, Container(params.Config, params.Log, params.OtelCol, true)), - Volumes: Volumes(params.Config, params.OtelCol), - Tolerations: params.OtelCol.Spec.Tolerations, - NodeSelector: params.OtelCol.Spec.NodeSelector, - HostNetwork: params.OtelCol.Spec.HostNetwork, - DNSPolicy: getDNSPolicy(params.OtelCol), - SecurityContext: params.OtelCol.Spec.PodSecurityContext, - PriorityClassName: params.OtelCol.Spec.PriorityClassName, - Affinity: params.OtelCol.Spec.Affinity, + ServiceAccountName: ServiceAccountName(params.OtelCol), + InitContainers: params.OtelCol.Spec.InitContainers, + Containers: append(params.OtelCol.Spec.AdditionalContainers, Container(params.Config, params.Log, params.OtelCol, true)), + Volumes: Volumes(params.Config, params.OtelCol), + Tolerations: params.OtelCol.Spec.Tolerations, + NodeSelector: params.OtelCol.Spec.NodeSelector, + HostNetwork: params.OtelCol.Spec.HostNetwork, + ShareProcessNamespace: ¶ms.OtelCol.Spec.ShareNetworkProcess, + DNSPolicy: getDNSPolicy(params.OtelCol), + SecurityContext: params.OtelCol.Spec.PodSecurityContext, + PriorityClassName: params.OtelCol.Spec.PriorityClassName, + Affinity: params.OtelCol.Spec.Affinity, }, }, UpdateStrategy: params.OtelCol.Spec.UpdateStrategy, diff --git a/internal/manifests/collector/daemonset_test.go b/internal/manifests/collector/daemonset_test.go index 656591e6d8..3933bf7911 100644 --- a/internal/manifests/collector/daemonset_test.go +++ b/internal/manifests/collector/daemonset_test.go @@ -489,3 +489,35 @@ func TestDaemonSetOnDeleteUpdateStrategy(t *testing.T) { assert.Equal(t, &intstr.IntOrString{Type: intstr.Int, IntVal: int32(1)}, d.Spec.UpdateStrategy.RollingUpdate.MaxSurge) assert.Equal(t, &intstr.IntOrString{Type: intstr.Int, IntVal: int32(1)}, d.Spec.UpdateStrategy.RollingUpdate.MaxUnavailable) } + +func TestDaemonsetShareProcessNamespace(t *testing.T) { + params1 := manifests.Params{ + Config: config.New(), + OtelCol: v1alpha1.OpenTelemetryCollector{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-instance", + }, + Spec: v1alpha1.OpenTelemetryCollectorSpec{}, + }, + Log: logger, + } + // test + d1 := DaemonSet(params1) + assert.False(t, *d1.Spec.Template.Spec.ShareProcessNamespace) + + // verify custom + params2 := manifests.Params{ + Config: config.New(), + OtelCol: v1alpha1.OpenTelemetryCollector{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-instance-with-shareprocessnamespace", + }, + Spec: v1alpha1.OpenTelemetryCollectorSpec{ + ShareNetworkProcess: true, + }, + }, + Log: logger, + } + d2 := DaemonSet(params2) + assert.True(t, *d2.Spec.Template.Spec.ShareProcessNamespace) +} diff --git a/internal/manifests/collector/deployment.go b/internal/manifests/collector/deployment.go index 3a1b0abf21..96ad0def84 100644 --- a/internal/manifests/collector/deployment.go +++ b/internal/manifests/collector/deployment.go @@ -56,6 +56,7 @@ func Deployment(params manifests.Params) *appsv1.Deployment { Volumes: Volumes(params.Config, params.OtelCol), DNSPolicy: getDNSPolicy(params.OtelCol), HostNetwork: params.OtelCol.Spec.HostNetwork, + ShareProcessNamespace: ¶ms.OtelCol.Spec.ShareNetworkProcess, Tolerations: params.OtelCol.Spec.Tolerations, NodeSelector: params.OtelCol.Spec.NodeSelector, SecurityContext: params.OtelCol.Spec.PodSecurityContext, diff --git a/internal/manifests/collector/deployment_test.go b/internal/manifests/collector/deployment_test.go index baa66f42ad..ee21255269 100644 --- a/internal/manifests/collector/deployment_test.go +++ b/internal/manifests/collector/deployment_test.go @@ -554,3 +554,44 @@ func TestDeploymentAdditionalContainers(t *testing.T) { assert.Len(t, d.Spec.Template.Spec.Containers, 2) assert.Equal(t, v1.Container{Name: "test"}, d.Spec.Template.Spec.Containers[0]) } + +func TestDeploymentShareProcessNamespace(t *testing.T) { + // Test default + otelcol1 := v1alpha1.OpenTelemetryCollector{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-instance", + }, + } + + cfg := config.New() + + params1 := manifests.Params{ + Config: cfg, + OtelCol: otelcol1, + Log: logger, + } + + d1 := Deployment(params1) + assert.False(t, *d1.Spec.Template.Spec.ShareProcessNamespace) + + // Test hostNetwork=true + otelcol2 := v1alpha1.OpenTelemetryCollector{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-instance-with-shareprocessnamespace", + }, + Spec: v1alpha1.OpenTelemetryCollectorSpec{ + ShareNetworkProcess: true, + }, + } + + cfg = config.New() + + params2 := manifests.Params{ + Config: cfg, + OtelCol: otelcol2, + Log: logger, + } + + d2 := Deployment(params2) + assert.True(t, *d2.Spec.Template.Spec.ShareProcessNamespace) +} diff --git a/internal/manifests/collector/statefulset.go b/internal/manifests/collector/statefulset.go index a08304807d..ffb46b50f4 100644 --- a/internal/manifests/collector/statefulset.go +++ b/internal/manifests/collector/statefulset.go @@ -56,6 +56,7 @@ func StatefulSet(params manifests.Params) *appsv1.StatefulSet { Volumes: Volumes(params.Config, params.OtelCol), DNSPolicy: getDNSPolicy(params.OtelCol), HostNetwork: params.OtelCol.Spec.HostNetwork, + ShareProcessNamespace: ¶ms.OtelCol.Spec.ShareNetworkProcess, Tolerations: params.OtelCol.Spec.Tolerations, NodeSelector: params.OtelCol.Spec.NodeSelector, SecurityContext: params.OtelCol.Spec.PodSecurityContext, diff --git a/internal/manifests/collector/statefulset_test.go b/internal/manifests/collector/statefulset_test.go index 142f87004d..a1ceac1635 100644 --- a/internal/manifests/collector/statefulset_test.go +++ b/internal/manifests/collector/statefulset_test.go @@ -551,3 +551,44 @@ func TestStatefulSetAdditionalContainers(t *testing.T) { assert.Len(t, s.Spec.Template.Spec.Containers, 2) assert.Equal(t, v1.Container{Name: "test"}, s.Spec.Template.Spec.Containers[0]) } + +func TestStatefulSetShareProcessNamespace(t *testing.T) { + // Test default + otelcol1 := v1alpha1.OpenTelemetryCollector{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-instance", + }, + } + + cfg := config.New() + + params1 := manifests.Params{ + OtelCol: otelcol1, + Config: cfg, + Log: logger, + } + + d1 := StatefulSet(params1) + assert.False(t, *d1.Spec.Template.Spec.ShareProcessNamespace) + + // Test shareProcessNamespace=true + otelcol2 := v1alpha1.OpenTelemetryCollector{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-instance-with-shareprocessnamespace", + }, + Spec: v1alpha1.OpenTelemetryCollectorSpec{ + ShareNetworkProcess: true, + }, + } + + cfg = config.New() + + params2 := manifests.Params{ + OtelCol: otelcol2, + Config: cfg, + Log: logger, + } + + d2 := StatefulSet(params2) + assert.True(t, *d2.Spec.Template.Spec.ShareProcessNamespace) +}