Skip to content

Commit

Permalink
Allow running daemonset in hostNetwork mode
Browse files Browse the repository at this point in the history
  • Loading branch information
owais committed Aug 13, 2021
1 parent e31d095 commit 7af3df9
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions api/v1alpha1/opentelemetrycollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,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)
}

0 comments on commit 7af3df9

Please sign in to comment.