Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow running daemonset in hostNetwork mode #393

Merged
merged 2 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions api/v1alpha1/opentelemetrycollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ type OpenTelemetryCollectorSpec struct {
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
SecurityContext *v1.SecurityContext `json:"securityContext,omitempty"`

// HostNetwork indicates if the pod should run in the host networking namespace.
// +optional
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
HostNetwork bool `json:"hostNetwork,omitempty"`

// VolumeClaimTemplates will provide stable storage using PersistentVolumes. Only available when the mode=statefulset.
// +optional
// +listType=atomic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ spec:
- name
type: object
type: array
hostNetwork:
description: HostNetwork indicates if the pod should run in the host
networking namespace.
type: boolean
image:
description: Image indicates the container image to use for the OpenTelemetry
Collector.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ spec:
- name
type: object
type: array
hostNetwork:
description: HostNetwork indicates if the pod should run in the host
networking namespace.
type: boolean
image:
description: Image indicates the container image to use for the OpenTelemetry
Collector.
Expand Down
3 changes: 3 additions & 0 deletions docs/otelcol_cr_spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ spec:

// +optional SecurityContext will be set as the container security context.
securityContext: {}

// +optional HostNetwork indicates if the pod should run in the host networking namespace.
hostNetwork: false

// +optional Toleration to schedule OpenTelemetry Collector pods.
// This is only relevant to daemonsets, statefulsets and deployments
Expand Down
1 change: 1 addition & 0 deletions pkg/collector/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func DaemonSet(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTelem
Containers: []corev1.Container{Container(cfg, logger, otelcol)},
Volumes: Volumes(cfg, otelcol),
Tolerations: otelcol.Spec.Tolerations,
HostNetwork: otelcol.Spec.HostNetwork,
},
},
},
Expand Down
16 changes: 16 additions & 0 deletions pkg/collector/daemonset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,19 @@ func TestDaemonSetNewDefault(t *testing.T) {
// the pod selector should match the pod spec's labels
assert.Equal(t, d.Spec.Selector.MatchLabels, d.Spec.Template.Labels)
}

func TestDaemonsetHostNetwork(t *testing.T) {
// test
d1 := DaemonSet(config.New(), logger, v1alpha1.OpenTelemetryCollector{
Spec: v1alpha1.OpenTelemetryCollectorSpec{},
})
assert.False(t, d1.Spec.Template.Spec.HostNetwork)

// verify custom
d2 := DaemonSet(config.New(), logger, v1alpha1.OpenTelemetryCollector{
Spec: v1alpha1.OpenTelemetryCollectorSpec{
HostNetwork: true,
},
})
assert.True(t, d2.Spec.Template.Spec.HostNetwork)
}
14 changes: 14 additions & 0 deletions tests/e2e/daemonset-features/00-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: daemonset-collector
spec:
template:
spec:
hostNetwork: true
containers:
- args:
- --config=/conf/collector.yaml
name: otc-container
status:
numberReady: 1
21 changes: 21 additions & 0 deletions tests/e2e/daemonset-features/00-install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: opentelemetry.io/v1alpha1
kind: OpenTelemetryCollector
metadata:
name: daemonset
spec:
mode: daemonset
hostNetwork: true
config: |
receivers:
jaeger:
protocols:
grpc:
processors:
exporters:
logging:
service:
pipelines:
traces:
receivers: [jaeger]
processors: []
exporters: [logging]