From 60a55aaea8af90cb5d1a5d805ea55f72d2e04f4d Mon Sep 17 00:00:00 2001 From: Julien Mailleret <8582351+jmlrt@users.noreply.github.com> Date: Mon, 21 Dec 2020 08:48:58 +0100 Subject: [PATCH] [7.x] [all] add hostaliases (#970) (#985) This commit allow to define hostAliases in all charts kubernetes.io/docs/concepts/services-networking/add-entries-to-pod-etc-hosts-with-host-aliases --- apm-server/README.md | 2 ++ apm-server/templates/deployment.yaml | 3 ++ apm-server/tests/apmserver_test.py | 15 +++++++++ apm-server/values.yaml | 6 ++++ elasticsearch/README.md | 2 ++ elasticsearch/templates/statefulset.yaml | 3 ++ elasticsearch/tests/elasticsearch_test.py | 14 ++++++++ elasticsearch/values.yaml | 6 ++++ filebeat/README.md | 7 ++-- filebeat/templates/daemonset.yaml | 3 ++ filebeat/tests/filebeat_test.py | 14 ++++++++ filebeat/values.yaml | 5 +++ kibana/README.md | 2 ++ kibana/templates/deployment.yaml | 3 ++ kibana/tests/kibana_test.py | 15 +++++++++ kibana/values.yaml | 6 ++++ logstash/README.md | 2 ++ logstash/templates/statefulset.yaml | 3 ++ logstash/tests/logstash_test.py | 14 ++++++++ logstash/values.yaml | 6 ++++ metricbeat/README.md | 3 ++ metricbeat/templates/daemonset.yaml | 3 ++ metricbeat/templates/deployment.yaml | 3 ++ metricbeat/tests/metricbeat_test.py | 39 +++++++++++++++++++++++ metricbeat/values.yaml | 10 ++++++ 25 files changed, 186 insertions(+), 3 deletions(-) diff --git a/apm-server/README.md b/apm-server/README.md index b7e1f67b6..eae1e0f41 100644 --- a/apm-server/README.md +++ b/apm-server/README.md @@ -97,6 +97,7 @@ as a reference. They are also used in the automated testing of this chart. | `extraVolumeMounts` | List of additional `volumeMounts` | `[]` | | `extraVolumes` | List of additional `volumes` | `[]` | | `fullnameOverride` | Overrides the full name of the resources. If not set the name will default to `.Release.Name` - `.Values.nameOverride` or `.Chart.Name` | `""` | +| `hostAliases` | Configurable [hostAliases][] | `[]` | | `imagePullPolicy` | The Kubernetes [imagePullPolicy][] value | `IfNotPresent` | | `imagePullSecrets` | Configuration for [imagePullSecrets][] so that you can use a private registry for your image | `[]` | | `imageTag` | The APM Server Docker image tag | `7.11.0-SNAPSHOT` | @@ -163,6 +164,7 @@ about our development and testing process. [examples/security]: https://github.com/elastic/helm-charts/tree/7.x/apm-server/examples/security [helm]: https://helm.sh [horizontal pod autoscaler]: https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/ +[hostAliases]: https://kubernetes.io/docs/concepts/services-networking/add-entries-to-pod-etc-hosts-with-host-aliases/ [imagePullPolicy]: https://kubernetes.io/docs/concepts/containers/images/#updating-images [imagePullSecrets]: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/#create-a-pod-that-uses-your-secret [ingress]: https://kubernetes.io/docs/concepts/services-networking/ingress/ diff --git a/apm-server/templates/deployment.yaml b/apm-server/templates/deployment.yaml index 0cf3b50d9..ca3248cd2 100644 --- a/apm-server/templates/deployment.yaml +++ b/apm-server/templates/deployment.yaml @@ -34,6 +34,9 @@ spec: priorityClassName: {{ .Values.priorityClassName }} {{- end }} serviceAccountName: {{ template "apm.serviceAccount" . }} + {{- if .Values.hostAliases }} + hostAliases: {{ toYaml .Values.hostAliases | nindent 6 }} + {{- end }} volumes: {{- range .Values.secretMounts }} - name: {{ .name }} diff --git a/apm-server/tests/apmserver_test.py b/apm-server/tests/apmserver_test.py index a3b1419df..b6b8218af 100644 --- a/apm-server/tests/apmserver_test.py +++ b/apm-server/tests/apmserver_test.py @@ -26,6 +26,8 @@ def test_defaults(): assert c["image"].startswith("docker.elastic.co/apm/apm-server:") assert c["ports"][0]["containerPort"] == 8200 + assert "hostAliases" not in r["deployment"][name]["spec"]["template"]["spec"] + def test_adding_a_extra_container(): config = """ @@ -351,3 +353,16 @@ def test_enabling_horizontal_pod_autoscaler(): r = helm_template(config) assert "horizontalpodautoscaler" in r + + +def test_hostaliases(): + config = """ +hostAliases: +- ip: "127.0.0.1" + hostnames: + - "foo.local" + - "bar.local" +""" + r = helm_template(config) + hostAliases = r["deployment"][name]["spec"]["template"]["spec"]["hostAliases"] + assert {"ip": "127.0.0.1", "hostnames": ["foo.local", "bar.local"]} in hostAliases diff --git a/apm-server/values.yaml b/apm-server/values.yaml index 0d3d3326a..3c0a49875 100755 --- a/apm-server/values.yaml +++ b/apm-server/values.yaml @@ -61,6 +61,12 @@ extraVolumes: [] # - name: extras # emptyDir: {} +hostAliases: [] +#- ip: "127.0.0.1" +# hostnames: +# - "foo.local" +# - "bar.local" + image: "docker.elastic.co/apm/apm-server" imageTag: "7.11.0-SNAPSHOT" imagePullPolicy: "IfNotPresent" diff --git a/elasticsearch/README.md b/elasticsearch/README.md index 160d191f8..b1e238024 100644 --- a/elasticsearch/README.md +++ b/elasticsearch/README.md @@ -124,6 +124,7 @@ support multiple versions with minimal changes. | `extraVolumeMounts` | Templatable string of additional `volumeMounts` to be passed to the `tpl` function | `""` | | `extraVolumes` | Templatable string of additional `volumes` to be passed to the `tpl` function | `""` | | `fullnameOverride` | Overrides the `clusterName` and `nodeGroup` when used in the naming of resources. This should only be used when using a single `nodeGroup`, otherwise you will have name conflicts | `""` | +| `hostAliases` | Configurable [hostAliases][] | `[]` | | `httpPort` | The http port that Kubernetes will use for the healthchecks and the service. If you change this you will also need to set [http.port][] in `extraEnvs` | `9200` | | `imagePullPolicy` | The Kubernetes [imagePullPolicy][] value | `IfNotPresent` | | `imagePullSecrets` | Configuration for [imagePullSecrets][] so that you can use a private registry for your image | `[]` | @@ -423,6 +424,7 @@ about our development and testing process. [ingress]: https://kubernetes.io/docs/concepts/services-networking/ingress/ [java options]: https://www.elastic.co/guide/en/elasticsearch/reference/7.x/jvm-options.html [jvm heap size]: https://www.elastic.co/guide/en/elasticsearch/reference/7.x/heap-size.html +[hostAliases]: https://kubernetes.io/docs/concepts/services-networking/add-entries-to-pod-etc-hosts-with-host-aliases/ [kind]: https://github.com/elastic/helm-charts/tree/7.x/elasticsearch/examples/kubernetes-kind [kubernetes secrets]: https://kubernetes.io/docs/concepts/configuration/secret/ [labels]: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ diff --git a/elasticsearch/templates/statefulset.yaml b/elasticsearch/templates/statefulset.yaml index 70dd1a3cc..e44a01624 100644 --- a/elasticsearch/templates/statefulset.yaml +++ b/elasticsearch/templates/statefulset.yaml @@ -153,6 +153,9 @@ spec: {{ toYaml .Values.imagePullSecrets | indent 8 }} {{- end }} enableServiceLinks: {{ .Values.enableServiceLinks }} + {{- if .Values.hostAliases }} + hostAliases: {{ toYaml .Values.hostAliases | nindent 8 }} + {{- end }} {{- if or (.Values.extraInitContainers) (.Values.sysctlInitContainer.enabled) (.Values.keystore) }} initContainers: {{- if .Values.sysctlInitContainer.enabled }} diff --git a/elasticsearch/tests/elasticsearch_test.py b/elasticsearch/tests/elasticsearch_test.py index a55132f64..f414d68e1 100755 --- a/elasticsearch/tests/elasticsearch_test.py +++ b/elasticsearch/tests/elasticsearch_test.py @@ -141,6 +141,7 @@ def test_defaults(): assert "tolerations" not in r["statefulset"][uname]["spec"]["template"]["spec"] assert "nodeSelector" not in r["statefulset"][uname]["spec"]["template"]["spec"] assert "ingress" not in r + assert "hostAliases" not in r["statefulset"][uname]["spec"]["template"]["spec"] def test_increasing_the_replicas(): @@ -1361,3 +1362,16 @@ def test_initial_master_nodes_when_using_full_name_override(): "name": "cluster.initial_master_nodes", "value": "customfullName-0," + "customfullName-1," + "customfullName-2,", } in env + + +def test_hostaliases(): + config = """ +hostAliases: +- ip: "127.0.0.1" + hostnames: + - "foo.local" + - "bar.local" +""" + r = helm_template(config) + hostAliases = r["statefulset"][uname]["spec"]["template"]["spec"]["hostAliases"] + assert {"ip": "127.0.0.1", "hostnames": ["foo.local", "bar.local"]} in hostAliases diff --git a/elasticsearch/values.yaml b/elasticsearch/values.yaml index 4705c2757..40583e8be 100755 --- a/elasticsearch/values.yaml +++ b/elasticsearch/values.yaml @@ -52,6 +52,12 @@ secretMounts: [] # path: /usr/share/elasticsearch/config/certs # defaultMode: 0755 +hostAliases: [] +#- ip: "127.0.0.1" +# hostnames: +# - "foo.local" +# - "bar.local" + image: "docker.elastic.co/elasticsearch/elasticsearch" imageTag: "7.11.0-SNAPSHOT" imagePullPolicy: "IfNotPresent" diff --git a/filebeat/README.md b/filebeat/README.md index c961da056..9f5abc3c9 100644 --- a/filebeat/README.md +++ b/filebeat/README.md @@ -93,6 +93,7 @@ as a reference. They are also used in the automated testing of this chart. | Parameter | Description | Default | |-----------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------| | `affinity` | Configurable [affinity][] | `{}` | +| `dnsConfig` | Configurable [dnsConfig][] | `{}` | | `envFrom` | Templatable string of envFrom to be passed to the [environment from variables][] which will be appended to the `envFrom:` definition for the container | `[]` | | `extraContainers` | List of additional init containers to be added at the DaemonSet | `""` | | `extraEnvs` | Extra [environment variables][] which will be appended to the `env:` definition for the container | `[]` | @@ -101,8 +102,8 @@ as a reference. They are also used in the automated testing of this chart. | `extraVolumes` | List of additional volumes to be mounted on the DaemonSet | `[]` | | `filebeatConfig` | Allows you to add any config files in `/usr/share/filebeat` such as `filebeat.yml` | see [values.yaml][] | | `fullnameOverride` | Overrides the full name of the resources. If not set the name will default to " `.Release.Name` - `.Values.nameOverride or .Chart.Name` " | `""` | +| `hostAliases` | Configurable [hostAliases][] | `[]` | | `hostNetworking` | Use host networking in the DaemonSet so that hostname is reported correctly | `false` | -| `dnsConfig` | Configurable [dnsConfig][] | `{}` | | `hostPathRoot` | Fully-qualified [hostPath][] that will be used to persist Filebeat registry data | `/var/lib` | | `imagePullPolicy` | The Kubernetes [imagePullPolicy][] value | `IfNotPresent` | | `imagePullSecrets` | Configuration for [imagePullSecrets][] so that you can use a private registry for your image | `[]` | @@ -191,7 +192,7 @@ about our development and testing process. [CONTRIBUTING.md]: https://github.com/elastic/helm-charts/blob/master/CONTRIBUTING.md [affinity]: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity [annotations]: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/ -[default Filebeat Helm chart]: https://github.com/elastic/helm-charts/tree/7.x/filebeat/README.md#default +[dnsConfig]: https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/ [environment variables]: https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/#using-environment-variables-inside-of-your-config [environment from variables]: https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#configure-all-key-value-pairs-in-a-configmap-as-container-environment-variables [examples]: https://github.com/elastic/helm-charts/tree/7.x/filebeat/examples @@ -201,8 +202,8 @@ about our development and testing process. [filebeat oss docker image]: https://www.docker.elastic.co/r/beats/filebeat-oss [filebeat outputs]: https://www.elastic.co/guide/en/beats/filebeat/7.x/configuring-output.html [helm]: https://helm.sh +[hostAliases]: https://kubernetes.io/docs/concepts/services-networking/add-entries-to-pod-etc-hosts-with-host-aliases/ [hostNetwork]: https://kubernetes.io/docs/concepts/policy/pod-security-policy/#host-namespaces -[dnsConfig]: https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/ [hostPath]: https://kubernetes.io/docs/concepts/storage/volumes/#hostpath [imagePullPolicy]: https://kubernetes.io/docs/concepts/containers/images/#updating-images [imagePullSecrets]: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/#create-a-pod-that-uses-your-secret diff --git a/filebeat/templates/daemonset.yaml b/filebeat/templates/daemonset.yaml index 94e286bdf..1708eb5e6 100644 --- a/filebeat/templates/daemonset.yaml +++ b/filebeat/templates/daemonset.yaml @@ -59,6 +59,9 @@ spec: {{- if .Values.dnsConfig }} dnsConfig: {{ toYaml .Values.dnsConfig | nindent 8 }} {{- end }} + {{- if .Values.hostAliases }} + hostAliases: {{ toYaml .Values.hostAliases | nindent 6 }} + {{- end }} volumes: {{- range .Values.secretMounts }} - name: {{ .name }} diff --git a/filebeat/tests/filebeat_test.py b/filebeat/tests/filebeat_test.py index 7c8dc0ad0..feaba4f56 100644 --- a/filebeat/tests/filebeat_test.py +++ b/filebeat/tests/filebeat_test.py @@ -30,6 +30,7 @@ def test_defaults(): # Empty customizable defaults assert "imagePullSecrets" not in r["daemonset"][name]["spec"]["template"]["spec"] assert "tolerations" not in r["daemonset"][name]["spec"]["template"]["spec"] + assert "hostAliases" not in r["daemonset"][name]["spec"]["template"]["spec"] assert r["daemonset"][name]["spec"]["updateStrategy"]["type"] == "RollingUpdate" @@ -400,3 +401,16 @@ def test_setting_fullnameOverride(): "type": "DirectoryOrCreate", }, } in volumes + + +def test_hostaliases(): + config = """ +hostAliases: +- ip: "127.0.0.1" + hostnames: + - "foo.local" + - "bar.local" +""" + r = helm_template(config) + hostAliases = r["daemonset"][name]["spec"]["template"]["spec"]["hostAliases"] + assert {"ip": "127.0.0.1", "hostnames": ["foo.local", "bar.local"]} in hostAliases diff --git a/filebeat/values.yaml b/filebeat/values.yaml index bbccfdfc3..9c0fcd7d8 100755 --- a/filebeat/values.yaml +++ b/filebeat/values.yaml @@ -55,6 +55,11 @@ dnsConfig: {} # options: # - name: ndots # value: "2" +hostAliases: [] +#- ip: "127.0.0.1" +# hostnames: +# - "foo.local" +# - "bar.local" image: "docker.elastic.co/beats/filebeat" imageTag: "7.11.0-SNAPSHOT" imagePullPolicy: "IfNotPresent" diff --git a/kibana/README.md b/kibana/README.md index 0155e457e..b5ced97a7 100644 --- a/kibana/README.md +++ b/kibana/README.md @@ -89,6 +89,7 @@ as a reference. They are also used in the automated testing of this chart. | `extraInitContainers` | Templatable string of additional containers to be passed to the `tpl` function | `""` | | `fullnameOverride` | Overrides the full name of the resources. If not set the name will default to " `.Release.Name` - `.Values.nameOverride orChart.Name` " | `""` | | `healthCheckPath` | The path used for the readinessProbe to check that Kibana is ready. If you are setting `server.basePath` you will also need to update this to `/${basePath}/app/kibana` | `/app/kibana` | +| `hostAliases` | Configurable [hostAliases][] | `[]` | | `httpPort` | The http port that Kubernetes will use for the healthchecks and the service | `5601` | | `imagePullPolicy` | The Kubernetes [imagePullPolicy][]value | `IfNotPresent` | | `imagePullSecrets` | Configuration for [imagePullSecrets][] so that you can use a private registry for your image | `[]` | @@ -217,6 +218,7 @@ about our development and testing process. [examples/security]: https://github.com/elastic/helm-charts/tree/7.x/kibana/examples/security [gke]: https://cloud.google.com/kubernetes-engine [helm]: https://helm.sh +[hostAliases]: https://kubernetes.io/docs/concepts/services-networking/add-entries-to-pod-etc-hosts-with-host-aliases/ [imagePullPolicy]: https://kubernetes.io/docs/concepts/containers/images/#updating-images [imagePullSecrets]: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/#create-a-pod-that-uses-your-secret [ingress]: https://kubernetes.io/docs/concepts/services-networking/ingress/ diff --git a/kibana/templates/deployment.yaml b/kibana/templates/deployment.yaml index 44920abb9..ba4400b78 100644 --- a/kibana/templates/deployment.yaml +++ b/kibana/templates/deployment.yaml @@ -36,6 +36,9 @@ spec: {{- if .Values.serviceAccount }} serviceAccount: {{ .Values.serviceAccount }} {{- end }} + {{- if .Values.hostAliases }} + hostAliases: {{ toYaml .Values.hostAliases | nindent 6 }} + {{- end }} volumes: {{- range .Values.secretMounts }} - name: {{ .name }} diff --git a/kibana/tests/kibana_test.py b/kibana/tests/kibana_test.py index d58da0301..b188db456 100644 --- a/kibana/tests/kibana_test.py +++ b/kibana/tests/kibana_test.py @@ -54,6 +54,8 @@ def test_defaults(): # Make sure that the default 'loadBalancerIP' string is empty assert "loadBalancerIP" not in r["service"][name]["spec"] + assert "hostAliases" not in r["deployment"][name]["spec"]["template"]["spec"] + def test_overriding_the_elasticsearch_hosts(): config = """ @@ -642,3 +644,16 @@ def test_service_port_name(): r = helm_template(config) assert r["service"][name]["spec"]["ports"][0]["name"] == "istio" + + +def test_hostaliases(): + config = """ +hostAliases: +- ip: "127.0.0.1" + hostnames: + - "foo.local" + - "bar.local" +""" + r = helm_template(config) + hostAliases = r["deployment"][name]["spec"]["template"]["spec"]["hostAliases"] + assert {"ip": "127.0.0.1", "hostnames": ["foo.local", "bar.local"]} in hostAliases diff --git a/kibana/values.yaml b/kibana/values.yaml index c83ca14fe..8169e80db 100755 --- a/kibana/values.yaml +++ b/kibana/values.yaml @@ -28,6 +28,12 @@ secretMounts: [] # path: /usr/share/kibana/data/kibana.keystore # subPath: kibana.keystore # optional +hostAliases: [] +#- ip: "127.0.0.1" +# hostnames: +# - "foo.local" +# - "bar.local" + image: "docker.elastic.co/kibana/kibana" imageTag: "7.11.0-SNAPSHOT" imagePullPolicy: "IfNotPresent" diff --git a/logstash/README.md b/logstash/README.md index 1698bf59d..bbfd8bc57 100644 --- a/logstash/README.md +++ b/logstash/README.md @@ -114,6 +114,7 @@ useful for the [http input plugin][], for instance. | `extraVolumeMounts` | Templatable string of additional `volumeMounts` to be passed to the `tpl` function | `""` | | `extraVolumes` | Templatable string of additional `volumes` to be passed to the `tpl` function | `""` | | `fullnameOverride` | Overrides the full name of the resources. If not set the name will default to " `.Release.Name` - `.Values.nameOverride or .Chart.Name` " | `""` | +| `hostAliases` | Configurable [hostAliases][] | `[]` | | `httpPort` | The http port that Kubernetes will use for the healthchecks and the service | `9600` | | `imagePullPolicy` | The Kubernetes [imagePullPolicy][] value | `IfNotPresent` | | `imagePullSecrets` | Configuration for [imagePullSecrets][] so that you can use a private registry for your image | `[]` | @@ -205,6 +206,7 @@ about our development and testing process. [examples]: https://github.com/elastic/helm-charts/tree/7.x/logstash/examples [examples/oss]: https://github.com/elastic/helm-charts/tree/7.x/logstash/examples/oss [helm]: https://helm.sh +[hostAliases]: https://kubernetes.io/docs/concepts/services-networking/add-entries-to-pod-etc-hosts-with-host-aliases/ [http input plugin]: https://www.elastic.co/guide/en/logstash/current/plugins-inputs-http.html [imagePullPolicy]: https://kubernetes.io/docs/concepts/containers/images/#updating-images [imagePullSecrets]: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/#create-a-pod-that-uses-your-secret diff --git a/logstash/templates/statefulset.yaml b/logstash/templates/statefulset.yaml index 55548eced..7f17586b4 100644 --- a/logstash/templates/statefulset.yaml +++ b/logstash/templates/statefulset.yaml @@ -133,6 +133,9 @@ spec: {{- if .Values.imagePullSecrets }} imagePullSecrets: {{ toYaml .Values.imagePullSecrets | indent 8 }} + {{- end}} + {{- if .Values.hostAliases }} + hostAliases: {{ toYaml .Values.hostAliases | nindent 6 }} {{- end }} {{- if .Values.extraInitContainers }} initContainers: diff --git a/logstash/tests/logstash_test.py b/logstash/tests/logstash_test.py index 1555b960c..ac5633e05 100755 --- a/logstash/tests/logstash_test.py +++ b/logstash/tests/logstash_test.py @@ -100,6 +100,7 @@ def test_defaults(): assert "imagePullSecrets" not in r["statefulset"][name]["spec"]["template"]["spec"] assert "tolerations" not in r["statefulset"][name]["spec"]["template"]["spec"] assert "nodeSelector" not in r["statefulset"][name]["spec"]["template"]["spec"] + assert "hostAliases" not in r["statefulset"][name]["spec"]["template"]["spec"] def test_increasing_the_replicas(): @@ -902,3 +903,16 @@ def test_adding_an_ingress(): ] }, } + + +def test_hostaliases(): + config = """ +hostAliases: +- ip: "127.0.0.1" + hostnames: + - "foo.local" + - "bar.local" +""" + r = helm_template(config) + hostAliases = r["statefulset"][name]["spec"]["template"]["spec"]["hostAliases"] + assert {"ip": "127.0.0.1", "hostnames": ["foo.local", "bar.local"]} in hostAliases diff --git a/logstash/values.yaml b/logstash/values.yaml index d197fb6a9..23ac43895 100755 --- a/logstash/values.yaml +++ b/logstash/values.yaml @@ -59,6 +59,12 @@ secrets: [] # A list of secrets and their paths to mount inside the pod secretMounts: [] +hostAliases: [] +#- ip: "127.0.0.1" +# hostnames: +# - "foo.local" +# - "bar.local" + image: "docker.elastic.co/logstash/logstash" imageTag: "7.11.0-SNAPSHOT" imagePullPolicy: "IfNotPresent" diff --git a/metricbeat/README.md b/metricbeat/README.md index 190f5d631..57462ba74 100644 --- a/metricbeat/README.md +++ b/metricbeat/README.md @@ -99,6 +99,7 @@ as a reference. They are also used in the automated testing of this chart. | `daemonset.extraEnvs` | Extra [environment variables][] which will be appended to Metricbeat container for DaemonSet | `[]` | | `daemonset.extraVolumeMounts` | Templatable string of additional `volumeMounts` to be passed to the `tpl` function or DaemonSet | `[]` | | `daemonset.extraVolumes` | Templatable string of additional `volumes` to be passed to the `tpl` function or DaemonSet | `[]` | +| `daemonset.hostAliases` | Configurable [hostAliases][] for Metricbeat DaemonSet | `[]` | | `daemonset.hostNetworking` | Enable Metricbeat DaemonSet to use `hostNetwork` | `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 | `{}` | @@ -114,6 +115,7 @@ as a reference. They are also used in the automated testing of this chart. | `deployment.extraEnvs` | Extra [environment variables][] which will be appended to Metricbeat container for Deployment | `[]` | | `deployment.extraVolumeMounts` | Templatable string of additional `volumeMounts` to be passed to the `tpl` function or DaemonSet | `[]` | | `deployment.extraVolumes` | Templatable string of additional `volumes` to be passed to the `tpl` function or Deployment | `[]` | +| `deployment.hostAliases` | Configurable [hostAliases][] for Metricbeat Deployment | `[]` | | `deployment.metricbeatConfig` | Allows you to add any config files in `/usr/share/metricbeat` such as `metricbeat.yml` for Metricbeat Deployment | see [values.yaml][] | | `deployment.nodeSelector` | Configurable [nodeSelector][] for Metricbeat Deployment | `{}` | | `deployment.resources` | Allows you to set the [resources][] for Metricbeat Deployment | see [values.yaml][] | @@ -225,6 +227,7 @@ about our development and testing process. [examples/oss]: https://github.com/elastic/helm-charts/tree/7.x/metricbeat/examples/oss [examples/security]: https://github.com/elastic/helm-charts/tree/7.x/metricbeat/examples/security [helm]: https://helm.sh +[hostAliases]: https://kubernetes.io/docs/concepts/services-networking/add-entries-to-pod-etc-hosts-with-host-aliases/ [hostPath]: https://kubernetes.io/docs/concepts/storage/volumes/#hostpath [hostNetwork]: https://kubernetes.io/docs/concepts/policy/pod-security-policy/#host-namespaces [imagePullPolicy]: https://kubernetes.io/docs/concepts/containers/images/#updating-images diff --git a/metricbeat/templates/daemonset.yaml b/metricbeat/templates/daemonset.yaml index e8ef55ac9..b96b876d4 100644 --- a/metricbeat/templates/daemonset.yaml +++ b/metricbeat/templates/daemonset.yaml @@ -69,6 +69,9 @@ spec: {{- end }} serviceAccountName: {{ template "metricbeat.serviceAccount" . }} terminationGracePeriodSeconds: {{ .Values.terminationGracePeriod }} + {{- if .Values.daemonset.hostAliases }} + hostAliases: {{ toYaml .Values.daemonset.hostAliases | nindent 6 }} + {{- end }} volumes: {{- range .Values.secretMounts | default .Values.daemonset.secretMounts }} - name: {{ .name }} diff --git a/metricbeat/templates/deployment.yaml b/metricbeat/templates/deployment.yaml index cc97f20e5..740c1b7b1 100644 --- a/metricbeat/templates/deployment.yaml +++ b/metricbeat/templates/deployment.yaml @@ -63,6 +63,9 @@ spec: {{- end }} serviceAccountName: {{ template "metricbeat.serviceAccount" . }} terminationGracePeriodSeconds: {{ .Values.terminationGracePeriod }} + {{- if .Values.deployment.hostAliases }} + hostAliases: {{ toYaml .Values.deployment.hostAliases | nindent 6 }} + {{- end }} volumes: {{- range .Values.secretMounts | default .Values.deployment.secretMounts }} - name: {{ .name }} diff --git a/metricbeat/tests/metricbeat_test.py b/metricbeat/tests/metricbeat_test.py index 557fd9cdb..bcfcb5d8a 100644 --- a/metricbeat/tests/metricbeat_test.py +++ b/metricbeat/tests/metricbeat_test.py @@ -160,6 +160,12 @@ def test_defaults(): "limits": {"cpu": "1000m", "memory": "200Mi"}, } + assert "hostAliases" not in r["daemonset"][name]["spec"]["template"]["spec"] + assert ( + "hostAliases" + not in r["deployment"][name + "-metrics"]["spec"]["template"]["spec"] + ) + def test_adding_a_extra_container(): config = """ @@ -1458,3 +1464,36 @@ def test_adding_multiple_secrets(): "cert.crt": content_b64["cert_crt"], "cert.key": content_b64["cert_key"], } + + +def test_hostaliases(): + config = """ +daemonset: + hostAliases: + - ip: "127.0.0.1" + hostnames: + - "foo.local" + - "bar.local" +""" + r = helm_template(config) + assert ( + "hostAliases" + not in r["deployment"][name + "-metrics"]["spec"]["template"]["spec"] + ) + hostAliases = r["daemonset"][name]["spec"]["template"]["spec"]["hostAliases"] + assert {"ip": "127.0.0.1", "hostnames": ["foo.local", "bar.local"]} in hostAliases + + config = """ +deployment: + hostAliases: + - ip: "127.0.0.1" + hostnames: + - "foo.local" + - "bar.local" +""" + r = helm_template(config) + assert "hostAliases" not in r["daemonset"][name]["spec"]["template"]["spec"] + hostAliases = r["deployment"][name + "-metrics"]["spec"]["template"]["spec"][ + "hostAliases" + ] + assert {"ip": "127.0.0.1", "hostnames": ["foo.local", "bar.local"]} in hostAliases diff --git a/metricbeat/values.yaml b/metricbeat/values.yaml index a7ae34b41..c8c88662c 100755 --- a/metricbeat/values.yaml +++ b/metricbeat/values.yaml @@ -22,6 +22,11 @@ daemonset: # - name: extras # mountPath: /usr/share/extras # readOnly: true + hostAliases: [] + #- ip: "127.0.0.1" + # hostnames: + # - "foo.local" + # - "bar.local" hostNetworking: false # Allows you to add any config files in /usr/share/metricbeat # such as metricbeat.yml for daemonset @@ -120,6 +125,11 @@ deployment: # mountPath: /usr/share/extras # readOnly: true # such as metricbeat.yml for deployment + hostAliases: [] + #- ip: "127.0.0.1" + # hostnames: + # - "foo.local" + # - "bar.local" metricbeatConfig: metricbeat.yml: | metricbeat.modules: