Skip to content

Commit

Permalink
feat/add shareProcessNamespace capability (#2472)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmiguel-teixeira authored Jan 18, 2024
1 parent 7a22896 commit e2773be
Show file tree
Hide file tree
Showing 13 changed files with 205 additions and 21 deletions.
16 changes: 16 additions & 0 deletions .chloggen/add_shared_process_namespace_cap.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. operator, target allocator, github action)
component: operator

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add SharedProcessNamespace capabilities to the OpenTelemetryCollector CRD

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

# (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:
3 changes: 3 additions & 0 deletions apis/v1alpha1/opentelemetrycollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
// ShareProcessNamespace indicates if the pod's containers should share process namespace.
// +optional
ShareProcessNamespace bool `json:"shareProcessNamespace,omitempty"`
// If specified, indicates the pod's priority.
// If not specified, the pod priority will be default or zero if there is no
// default.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4257,6 +4257,10 @@ spec:
account to use with this instance. When set, the operator will not
automatically create a ServiceAccount for the collector.
type: string
shareProcessNamespace:
description: ShareProcessNamespace 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4254,6 +4254,10 @@ spec:
account to use with this instance. When set, the operator will not
automatically create a ServiceAccount for the collector.
type: string
shareProcessNamespace:
description: ShareProcessNamespace 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.
Expand Down
26 changes: 16 additions & 10 deletions controllers/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"

colfeaturegate "go.opentelemetry.io/collector/featuregate"
Expand Down Expand Up @@ -209,8 +210,9 @@ service:
},
},
},
DNSPolicy: "ClusterFirst",
ServiceAccountName: "test-collector",
ShareProcessNamespace: ptr.To(false),
DNSPolicy: "ClusterFirst",
ServiceAccountName: "test-collector",
},
},
},
Expand Down Expand Up @@ -452,8 +454,9 @@ service:
},
},
},
DNSPolicy: "ClusterFirst",
ServiceAccountName: "test-collector",
ShareProcessNamespace: ptr.To(false),
DNSPolicy: "ClusterFirst",
ServiceAccountName: "test-collector",
},
},
},
Expand Down Expand Up @@ -728,8 +731,9 @@ service:
},
},
},
DNSPolicy: "ClusterFirst",
ServiceAccountName: "my-special-sa",
ShareProcessNamespace: ptr.To(false),
DNSPolicy: "ClusterFirst",
ServiceAccountName: "my-special-sa",
},
},
},
Expand Down Expand Up @@ -1238,8 +1242,9 @@ service:
},
},
},
DNSPolicy: "ClusterFirst",
ServiceAccountName: "test-collector",
ShareProcessNamespace: ptr.To(false),
DNSPolicy: "ClusterFirst",
ServiceAccountName: "test-collector",
},
},
PodManagementPolicy: "Parallel",
Expand Down Expand Up @@ -1629,8 +1634,9 @@ label_selector:
},
},
},
DNSPolicy: "ClusterFirst",
ServiceAccountName: "test-collector",
ShareProcessNamespace: ptr.To(false),
DNSPolicy: "ClusterFirst",
ServiceAccountName: "test-collector",
},
},
PodManagementPolicy: "Parallel",
Expand Down
23 changes: 12 additions & 11 deletions internal/manifests/collector/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: &params.OtelCol.Spec.ShareProcessNamespace,
DNSPolicy: getDNSPolicy(params.OtelCol),
SecurityContext: params.OtelCol.Spec.PodSecurityContext,
PriorityClassName: params.OtelCol.Spec.PriorityClassName,
Affinity: params.OtelCol.Spec.Affinity,
},
},
UpdateStrategy: params.OtelCol.Spec.UpdateStrategy,
Expand Down
32 changes: 32 additions & 0 deletions internal/manifests/collector/daemonset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
ShareProcessNamespace: true,
},
},
Log: logger,
}
d2 := DaemonSet(params2)
assert.True(t, *d2.Spec.Template.Spec.ShareProcessNamespace)
}
1 change: 1 addition & 0 deletions internal/manifests/collector/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func Deployment(params manifests.Params) *appsv1.Deployment {
Volumes: Volumes(params.Config, params.OtelCol),
DNSPolicy: getDNSPolicy(params.OtelCol),
HostNetwork: params.OtelCol.Spec.HostNetwork,
ShareProcessNamespace: &params.OtelCol.Spec.ShareProcessNamespace,
Tolerations: params.OtelCol.Spec.Tolerations,
NodeSelector: params.OtelCol.Spec.NodeSelector,
SecurityContext: params.OtelCol.Spec.PodSecurityContext,
Expand Down
41 changes: 41 additions & 0 deletions internal/manifests/collector/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,3 +587,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{
ShareProcessNamespace: true,
},
}

cfg = config.New()

params2 := manifests.Params{
Config: cfg,
OtelCol: otelcol2,
Log: logger,
}

d2 := Deployment(params2)
assert.True(t, *d2.Spec.Template.Spec.ShareProcessNamespace)
}
1 change: 1 addition & 0 deletions internal/manifests/collector/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: &params.OtelCol.Spec.ShareProcessNamespace,
Tolerations: params.OtelCol.Spec.Tolerations,
NodeSelector: params.OtelCol.Spec.NodeSelector,
SecurityContext: params.OtelCol.Spec.PodSecurityContext,
Expand Down
41 changes: 41 additions & 0 deletions internal/manifests/collector/statefulset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
ShareProcessNamespace: true,
},
}

cfg = config.New()

params2 := manifests.Params{
OtelCol: otelcol2,
Config: cfg,
Log: logger,
}

d2 := StatefulSet(params2)
assert.True(t, *d2.Spec.Template.Spec.ShareProcessNamespace)
}
8 changes: 8 additions & 0 deletions tests/e2e/smoke-shareprocessnamespace/00-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-shareprocns-collector
spec:
template:
spec:
shareProcessNamespace: true
26 changes: 26 additions & 0 deletions tests/e2e/smoke-shareprocessnamespace/00-install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apiVersion: opentelemetry.io/v1alpha1
kind: OpenTelemetryCollector
metadata:
name: test-shareprocns
spec:
shareProcessNamespace: true
config: |
receivers:
jaeger:
protocols:
grpc:
otlp:
protocols:
grpc:
http:
processors:
exporters:
debug:
service:
pipelines:
traces:
receivers: [jaeger,otlp]
processors: []
exporters: [debug]

0 comments on commit e2773be

Please sign in to comment.