Skip to content

Commit

Permalink
feat/add shareProcessName capability
Browse files Browse the repository at this point in the history
  • Loading branch information
bmiguel-teixeira committed Dec 24, 2023
1 parent c2b3ece commit 764505c
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 11 deletions.
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"`
// 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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.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,
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{
ShareNetworkProcess: 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 @@ -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: &params.OtelCol.Spec.ShareNetworkProcess,
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 @@ -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)
}
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.ShareNetworkProcess,
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{
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)
}

0 comments on commit 764505c

Please sign in to comment.