diff --git a/metricbeat/README.md b/metricbeat/README.md index 1a413cce5..8e3e2ed36 100644 --- a/metricbeat/README.md +++ b/metricbeat/README.md @@ -72,6 +72,7 @@ helm install --name metricbeat elastic/metricbeat --set imageTag=7.6.2 | `daemonset.extraEnvs` | Extra [environment variables][] which will be appended to Metricbeat container for `DaemonSet`. | `[]` | | `daemonset.extraVolumes` | Templatable string of additional volumes to be passed to the `tpl` function or `DaemonSet`. | `[]` | | `daemonset.extraVolumeMounts` | Templatable string of additional volumeMounts to be passed to the `tpl` function or `DaemonSet`. | `[]` | +| `daemonset.hostNetworking` | Enable Metricbeat `DaemonSet` to use host network | `false` | | `daemonset.metricbeatConfig` | Allows you to add any config files in `/usr/share/metricbeat` such as `metricbeat.yml` for Metricbeat `DaemonSet`. | see [values.yaml][] | | `daemonset.nodeSelector` | Configurable [nodeSelector][] for Metricbeat `DaemonSet`. | `{}` | | `daemonset.secretMounts` | Allows you easily mount a secret as a file inside the `DaemonSet`. Useful for mounting certificates and other secrets. See [values.yaml][] for an example | `[]` | diff --git a/metricbeat/templates/daemonset.yaml b/metricbeat/templates/daemonset.yaml index b057059e0..188db442b 100644 --- a/metricbeat/templates/daemonset.yaml +++ b/metricbeat/templates/daemonset.yaml @@ -41,6 +41,10 @@ spec: affinity: {{ toYaml ( .Values.affinity | default .Values.daemonset.affinity ) | nindent 8 }} nodeSelector: {{ toYaml ( .Values.nodeSelector | default .Values.daemonset.nodeSelector ) | nindent 8 }} tolerations: {{ toYaml ( .Values.tolerations | default .Values.daemonset.tolerations ) | nindent 8 }} + {{- if .Values.daemonset.hostNetworking }} + hostNetwork: true + dnsPolicy: ClusterFirstWithHostNet + {{- end }} {{- if .Values.priorityClassName }} priorityClassName: {{ .Values.priorityClassName }} {{- end }} diff --git a/metricbeat/tests/metricbeat_test.py b/metricbeat/tests/metricbeat_test.py index 91c1bfeed..83265498d 100644 --- a/metricbeat/tests/metricbeat_test.py +++ b/metricbeat/tests/metricbeat_test.py @@ -28,6 +28,18 @@ def test_defaults(): assert "metricbeat test output" in c["readinessProbe"]["exec"]["command"][-1] assert r["daemonset"][name]["spec"]["template"]["spec"]["tolerations"] == [] + + assert "hostNetwork" not in r["daemonset"][name]["spec"]["template"]["spec"] + assert "dnsPolicy" not in r["daemonset"][name]["spec"]["template"]["spec"] + assert ( + "hostNetwork" + not in r["deployment"][name + "-metrics"]["spec"]["template"]["spec"] + ) + assert ( + "dnsPolicy" + not in r["deployment"][name + "-metrics"]["spec"]["template"]["spec"] + ) + assert ( r["deployment"][name + "-metrics"]["spec"]["template"]["spec"]["tolerations"] == [] @@ -249,6 +261,27 @@ def test_adding_image_pull_secrets(): ) +def test_adding_host_networking(): + config = """ +daemonset: + hostNetworking: true +""" + r = helm_template(config) + assert r["daemonset"][name]["spec"]["template"]["spec"]["hostNetwork"] is True + assert ( + r["daemonset"][name]["spec"]["template"]["spec"]["dnsPolicy"] + == "ClusterFirstWithHostNet" + ) + assert ( + "hostNetwork" + not in r["deployment"][name + "-metrics"]["spec"]["template"]["spec"] + ) + assert ( + "dnsPolicy" + not in r["deployment"][name + "-metrics"]["spec"]["template"]["spec"] + ) + + def test_adding_tolerations(): config = """ daemonset: diff --git a/metricbeat/values.yaml b/metricbeat/values.yaml index a2b328d1a..8ec384bc6 100755 --- a/metricbeat/values.yaml +++ b/metricbeat/values.yaml @@ -16,6 +16,7 @@ daemonset: # - name: extras # mountPath: /usr/share/extras # readOnly: true + hostNetworking: false # Allows you to add any config files in /usr/share/metricbeat # such as metricbeat.yml for daemonset metricbeatConfig: