diff --git a/.changelog/3993.added.txt b/.changelog/3993.added.txt new file mode 100644 index 0000000000..af70b490cb --- /dev/null +++ b/.changelog/3993.added.txt @@ -0,0 +1 @@ +Making hostNetwork and dnsPolicy configurable in otellogs.daemonset diff --git a/deploy/helm/sumologic/templates/logs/collector/otelcol/daemonset.yaml b/deploy/helm/sumologic/templates/logs/collector/otelcol/daemonset.yaml index e2aa47d7a9..c90ca42cd8 100644 --- a/deploy/helm/sumologic/templates/logs/collector/otelcol/daemonset.yaml +++ b/deploy/helm/sumologic/templates/logs/collector/otelcol/daemonset.yaml @@ -76,6 +76,12 @@ spec: {{- if $tolerations }} tolerations: {{ $tolerations | indent 8 }} +{{- end }} +{{- if $daemonset.hostNetwork }} + hostNetwork: {{ $daemonset.hostNetwork }} +{{- end }} +{{- if $daemonset.dnsPolicy }} + dnsPolicy: {{ $daemonset.dnsPolicy }} {{- end }} securityContext: {{- toYaml $daemonset.securityContext | nindent 8 }} diff --git a/deploy/helm/sumologic/values.yaml b/deploy/helm/sumologic/values.yaml index c4ba636a45..9c597b71dc 100644 --- a/deploy/helm/sumologic/values.yaml +++ b/deploy/helm/sumologic/values.yaml @@ -2108,6 +2108,11 @@ otellogs: override: {} daemonset: + ## Enable host network for the daemonset pods + hostNetwork: false + ## DNS policy for the daemonset pods + dnsPolicy: ClusterFirst + ## Set securityContext for containers running in pods in log collector daemonset securityContext: ## In order to reliably read logs from mounted node logging paths, we need to run as root diff --git a/tests/helm/logs_test.go b/tests/helm/logs_test.go index 4fb3401728..2af7fff574 100644 --- a/tests/helm/logs_test.go +++ b/tests/helm/logs_test.go @@ -587,3 +587,65 @@ otellogs: require.Equal(t, "50%", logsCollectorDaemonset.Spec.UpdateStrategy.RollingUpdate.MaxUnavailable) } + +func TestCollectorDaemonsetHostNetwork(t *testing.T) { + t.Parallel() + + valuesYaml := ` +otellogs: + daemonset: + hostNetwork: true + dnsPolicy: ClusterFirstWithHostNet +` + templatePath := "templates/logs/collector/otelcol/daemonset.yaml" + + renderedTemplate, err := RenderTemplateFromValuesStringE(t, valuesYaml, templatePath) + require.NoError(t, err) + + var logsCollectorDaemonset struct { + Spec struct { + Template struct { + Spec struct { + HostNetwork bool `yaml:"hostNetwork"` + DnsPolicy string `yaml:"dnsPolicy"` + } + } + } + } + err = yaml.Unmarshal([]byte(renderedTemplate), &logsCollectorDaemonset) + require.NoError(t, err) + + require.Equal(t, true, logsCollectorDaemonset.Spec.Template.Spec.HostNetwork) + require.Equal(t, "ClusterFirstWithHostNet", logsCollectorDaemonset.Spec.Template.Spec.DnsPolicy) +} + +func TestCollectorDaemonsetHostNetworkDefault(t *testing.T) { + t.Parallel() + + valuesYaml := ` +otellogs: + daemonset: {} +` + templatePath := "templates/logs/collector/otelcol/daemonset.yaml" + + renderedTemplate, err := RenderTemplateFromValuesStringE(t, valuesYaml, templatePath) + require.NoError(t, err) + + var logsCollectorDaemonset struct { + Spec struct { + Template struct { + Spec struct { + HostNetwork bool `yaml:"hostNetwork"` + DnsPolicy string `yaml:"dnsPolicy"` + } + } + } + } + err = yaml.Unmarshal([]byte(renderedTemplate), &logsCollectorDaemonset) + require.NoError(t, err) + + // With default values (hostNetwork: false), the hostNetwork field should not be present + // and dnsPolicy should default to ClusterFirst + require.Equal(t, false, logsCollectorDaemonset.Spec.Template.Spec.HostNetwork) + require.Equal(t, "ClusterFirst", logsCollectorDaemonset.Spec.Template.Spec.DnsPolicy) +}