From ab54882d4d1dae0afdfd363009be2a1bc97e15bd Mon Sep 17 00:00:00 2001 From: Julien Mailleret <8582351+jmlrt@users.noreply.github.com> Date: Thu, 10 Dec 2020 09:31:52 +0100 Subject: [PATCH 1/9] [filebeat] add hostaliases This commit allow to define hostAliases in Filebeat chart https://kubernetes.io/docs/concepts/services-networking/add-entries-to-pod-etc-hosts-with-host-aliases/ --- filebeat/README.md | 6 ++++-- filebeat/templates/daemonset.yaml | 3 +++ filebeat/values.yaml | 5 +++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/filebeat/README.md b/filebeat/README.md index fd4142c14..736b99713 100644 --- a/filebeat/README.md +++ b/filebeat/README.md @@ -91,6 +91,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 | `[]` | @@ -99,8 +100,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,6 +192,7 @@ about our development and testing process. [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 Elasticsearch Helm chart]: https://github.com/elastic/helm-charts/tree/master/elasticsearch/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/master/filebeat/examples @@ -200,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/current/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 4b9c411b8..9f320a77d 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 8 }} + {{- end }} volumes: {{- range .Values.secretMounts }} - name: {{ .name }} diff --git a/filebeat/values.yaml b/filebeat/values.yaml index 5a0e422d1..40646cddf 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: "8.0.0-SNAPSHOT" imagePullPolicy: "IfNotPresent" From 32ac85cf33ebe00b27e7715d3e992f967f7bf944 Mon Sep 17 00:00:00 2001 From: Julien Mailleret <8582351+jmlrt@users.noreply.github.com> Date: Thu, 10 Dec 2020 09:52:27 +0100 Subject: [PATCH 2/9] [filebeat] add test --- filebeat/tests/filebeat_test.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/filebeat/tests/filebeat_test.py b/filebeat/tests/filebeat_test.py index 7c8dc0ad0..d08f28420 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,17 @@ 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) + spec = r["daemonset"][name]["spec"]["template"]["spec"] + hostAliases = r["daemonset"][name]["spec"]["template"]["spec"]["hostAliases"] + assert {"ip": "127.0.0.1", "hostnames": ["foo.local", "bar.local"]} in hostAliases From ef8ecf4f01b4b53e4f5a5fd0e52014aff5e192e0 Mon Sep 17 00:00:00 2001 From: Julien Mailleret <8582351+jmlrt@users.noreply.github.com> Date: Thu, 10 Dec 2020 10:06:41 +0100 Subject: [PATCH 3/9] [apm-server] add hostaliases --- apm-server/README.md | 2 ++ apm-server/templates/deployment.yaml | 3 +++ apm-server/tests/apmserver_test.py | 17 +++++++++++++++++ apm-server/values.yaml | 6 ++++++ 4 files changed, 28 insertions(+) diff --git a/apm-server/README.md b/apm-server/README.md index c1b3cd576..9f0f0d61c 100644 --- a/apm-server/README.md +++ b/apm-server/README.md @@ -94,6 +94,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 | `8.0.0-SNAPSHOT` | @@ -161,6 +162,7 @@ about our development and testing process. [examples/security]: https://github.com/elastic/helm-charts/tree/master/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..d8a2bd41a 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,18 @@ 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) + spec = r["deployment"][name]["spec"]["template"]["spec"] + 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 3402fce6d..5165f4fcd 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: "8.0.0-SNAPSHOT" imagePullPolicy: "IfNotPresent" From 12a0c19249e513cc18a1025c43b9e878fd8ed5a2 Mon Sep 17 00:00:00 2001 From: Julien Mailleret <8582351+jmlrt@users.noreply.github.com> Date: Thu, 10 Dec 2020 10:16:06 +0100 Subject: [PATCH 4/9] [elasticsearch] add hostaliases --- elasticsearch/README.md | 2 ++ elasticsearch/templates/statefulset.yaml | 3 +++ elasticsearch/tests/elasticsearch_test.py | 15 +++++++++++++++ elasticsearch/values.yaml | 6 ++++++ 4 files changed, 26 insertions(+) diff --git a/elasticsearch/README.md b/elasticsearch/README.md index f0062d542..b5f336dcc 100644 --- a/elasticsearch/README.md +++ b/elasticsearch/README.md @@ -122,6 +122,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 | `[]` | @@ -422,6 +423,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/current/jvm-options.html [jvm heap size]: https://www.elastic.co/guide/en/elasticsearch/reference/current/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/master/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 ac2a58c1e..8c52f1dd9 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(): @@ -1305,3 +1306,17 @@ 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) + spec = r["statefulset"][uname]["spec"]["template"]["spec"] + 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 1402af0e2..6ef1f346d 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: "8.0.0-SNAPSHOT" imagePullPolicy: "IfNotPresent" From 1020255f4c9d31a20111857d71243b91842478d6 Mon Sep 17 00:00:00 2001 From: Julien Mailleret <8582351+jmlrt@users.noreply.github.com> Date: Thu, 10 Dec 2020 10:20:49 +0100 Subject: [PATCH 5/9] [kibana] add hostaliases --- kibana/README.md | 2 ++ kibana/templates/deployment.yaml | 3 +++ kibana/tests/kibana_test.py | 16 ++++++++++++++++ kibana/values.yaml | 6 ++++++ 4 files changed, 27 insertions(+) diff --git a/kibana/README.md b/kibana/README.md index 72e08cc3d..37ca22658 100644 --- a/kibana/README.md +++ b/kibana/README.md @@ -87,6 +87,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 | `[]` | @@ -216,6 +217,7 @@ about our development and testing process. [examples/security]: https://github.com/elastic/helm-charts/tree/master/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..eff40bfe5 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,17 @@ 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) + spec = r["deployment"][name]["spec"]["template"]["spec"] + 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 cf6980fed..23a3acb00 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: "8.0.0-SNAPSHOT" imagePullPolicy: "IfNotPresent" From d1defb90903422ade9d6d973dcdf6dfba6b1d084 Mon Sep 17 00:00:00 2001 From: Julien Mailleret <8582351+jmlrt@users.noreply.github.com> Date: Thu, 10 Dec 2020 10:24:17 +0100 Subject: [PATCH 6/9] [logstash] add hostaliases --- logstash/README.md | 2 ++ logstash/templates/statefulset.yaml | 3 +++ logstash/tests/logstash_test.py | 15 +++++++++++++++ logstash/values.yaml | 6 ++++++ 4 files changed, 26 insertions(+) diff --git a/logstash/README.md b/logstash/README.md index 5a3306253..db25375a5 100644 --- a/logstash/README.md +++ b/logstash/README.md @@ -110,6 +110,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 | `[]` | @@ -202,6 +203,7 @@ about our development and testing process. [examples]: https://github.com/elastic/helm-charts/tree/master/logstash/examples [examples/oss]: https://github.com/elastic/helm-charts/tree/master/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..67cf13054 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 8 }} {{- end }} {{- if .Values.extraInitContainers }} initContainers: diff --git a/logstash/tests/logstash_test.py b/logstash/tests/logstash_test.py index 1555b960c..bc1f8c69a 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,17 @@ def test_adding_an_ingress(): ] }, } + + +def test_hostaliases(): + config = """ +hostAliases: +- ip: "127.0.0.1" + hostnames: + - "foo.local" + - "bar.local" +""" + r = helm_template(config) + spec = r["statefulset"][name]["spec"]["template"]["spec"] + 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 ff242820c..adb92b578 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: "8.0.0-SNAPSHOT" imagePullPolicy: "IfNotPresent" From 2c3c35fc82df3b85eb1051b20ccc3b942fc9be4c Mon Sep 17 00:00:00 2001 From: Julien Mailleret <8582351+jmlrt@users.noreply.github.com> Date: Thu, 10 Dec 2020 10:52:20 +0100 Subject: [PATCH 7/9] fixup! [apm-server] add hostaliases --- apm-server/tests/apmserver_test.py | 1 - 1 file changed, 1 deletion(-) diff --git a/apm-server/tests/apmserver_test.py b/apm-server/tests/apmserver_test.py index d8a2bd41a..0e4ea653f 100644 --- a/apm-server/tests/apmserver_test.py +++ b/apm-server/tests/apmserver_test.py @@ -355,7 +355,6 @@ def test_enabling_horizontal_pod_autoscaler(): assert "horizontalpodautoscaler" in r - def test_hostaliases(): config = """ hostAliases: From 628c9edcd4270b52855680702e05cd79608245e6 Mon Sep 17 00:00:00 2001 From: Julien Mailleret <8582351+jmlrt@users.noreply.github.com> Date: Thu, 10 Dec 2020 11:00:00 +0100 Subject: [PATCH 8/9] [metricbeat] add hostaliases --- metricbeat/README.md | 3 +++ metricbeat/templates/daemonset.yaml | 3 +++ metricbeat/templates/deployment.yaml | 3 +++ metricbeat/tests/metricbeat_test.py | 39 ++++++++++++++++++++++++++++ metricbeat/values.yaml | 10 +++++++ 5 files changed, 58 insertions(+) diff --git a/metricbeat/README.md b/metricbeat/README.md index 9d1ee2ee0..e80e4cc33 100644 --- a/metricbeat/README.md +++ b/metricbeat/README.md @@ -97,6 +97,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 | `{}` | @@ -112,6 +113,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][] | @@ -224,6 +226,7 @@ about our development and testing process. [examples/oss]: https://github.com/elastic/helm-charts/tree/master/metricbeat/examples/oss [examples/security]: https://github.com/elastic/helm-charts/tree/master/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 4779e756c..269c131ad 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 8 }} + {{- 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..e14992ebf 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 8 }} + {{- 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 06993abc0..02f03d74f 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: From 24381672858d965b33b2b80370496f605fa2cc80 Mon Sep 17 00:00:00 2001 From: Julien Mailleret <8582351+jmlrt@users.noreply.github.com> Date: Thu, 10 Dec 2020 11:11:01 +0100 Subject: [PATCH 9/9] small fixes --- apm-server/tests/apmserver_test.py | 1 - elasticsearch/README.md | 2 +- elasticsearch/tests/elasticsearch_test.py | 1 - filebeat/templates/daemonset.yaml | 2 +- filebeat/tests/filebeat_test.py | 1 - kibana/README.md | 2 +- kibana/tests/kibana_test.py | 1 - logstash/README.md | 2 +- logstash/templates/statefulset.yaml | 2 +- logstash/tests/logstash_test.py | 1 - metricbeat/README.md | 4 ++-- metricbeat/templates/daemonset.yaml | 2 +- metricbeat/templates/deployment.yaml | 2 +- 13 files changed, 9 insertions(+), 14 deletions(-) diff --git a/apm-server/tests/apmserver_test.py b/apm-server/tests/apmserver_test.py index 0e4ea653f..b6b8218af 100644 --- a/apm-server/tests/apmserver_test.py +++ b/apm-server/tests/apmserver_test.py @@ -364,6 +364,5 @@ def test_hostaliases(): - "bar.local" """ r = helm_template(config) - spec = r["deployment"][name]["spec"]["template"]["spec"] hostAliases = r["deployment"][name]["spec"]["template"]["spec"]["hostAliases"] assert {"ip": "127.0.0.1", "hostnames": ["foo.local", "bar.local"]} in hostAliases diff --git a/elasticsearch/README.md b/elasticsearch/README.md index b5f336dcc..38b48131a 100644 --- a/elasticsearch/README.md +++ b/elasticsearch/README.md @@ -122,7 +122,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][] | `[]` | +| `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 | `[]` | diff --git a/elasticsearch/tests/elasticsearch_test.py b/elasticsearch/tests/elasticsearch_test.py index 8c52f1dd9..e70f5adde 100755 --- a/elasticsearch/tests/elasticsearch_test.py +++ b/elasticsearch/tests/elasticsearch_test.py @@ -1317,6 +1317,5 @@ def test_hostaliases(): - "bar.local" """ r = helm_template(config) - spec = r["statefulset"][uname]["spec"]["template"]["spec"] hostAliases = r["statefulset"][uname]["spec"]["template"]["spec"]["hostAliases"] assert {"ip": "127.0.0.1", "hostnames": ["foo.local", "bar.local"]} in hostAliases diff --git a/filebeat/templates/daemonset.yaml b/filebeat/templates/daemonset.yaml index 9f320a77d..522316170 100644 --- a/filebeat/templates/daemonset.yaml +++ b/filebeat/templates/daemonset.yaml @@ -60,7 +60,7 @@ spec: dnsConfig: {{ toYaml .Values.dnsConfig | nindent 8 }} {{- end }} {{- if .Values.hostAliases }} - hostAliases: {{ toYaml .Values.hostAliases | nindent 8 }} + hostAliases: {{ toYaml .Values.hostAliases | nindent 6 }} {{- end }} volumes: {{- range .Values.secretMounts }} diff --git a/filebeat/tests/filebeat_test.py b/filebeat/tests/filebeat_test.py index d08f28420..feaba4f56 100644 --- a/filebeat/tests/filebeat_test.py +++ b/filebeat/tests/filebeat_test.py @@ -412,6 +412,5 @@ def test_hostaliases(): - "bar.local" """ r = helm_template(config) - spec = r["daemonset"][name]["spec"]["template"]["spec"] hostAliases = r["daemonset"][name]["spec"]["template"]["spec"]["hostAliases"] assert {"ip": "127.0.0.1", "hostnames": ["foo.local", "bar.local"]} in hostAliases diff --git a/kibana/README.md b/kibana/README.md index 37ca22658..986114c9e 100644 --- a/kibana/README.md +++ b/kibana/README.md @@ -87,7 +87,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][] | `[]` | +| `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 | `[]` | diff --git a/kibana/tests/kibana_test.py b/kibana/tests/kibana_test.py index eff40bfe5..b188db456 100644 --- a/kibana/tests/kibana_test.py +++ b/kibana/tests/kibana_test.py @@ -655,6 +655,5 @@ def test_hostaliases(): - "bar.local" """ r = helm_template(config) - spec = r["deployment"][name]["spec"]["template"]["spec"] hostAliases = r["deployment"][name]["spec"]["template"]["spec"]["hostAliases"] assert {"ip": "127.0.0.1", "hostnames": ["foo.local", "bar.local"]} in hostAliases diff --git a/logstash/README.md b/logstash/README.md index db25375a5..813eb545c 100644 --- a/logstash/README.md +++ b/logstash/README.md @@ -110,7 +110,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][] | `[]` | +| `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 | `[]` | diff --git a/logstash/templates/statefulset.yaml b/logstash/templates/statefulset.yaml index 67cf13054..7f17586b4 100644 --- a/logstash/templates/statefulset.yaml +++ b/logstash/templates/statefulset.yaml @@ -135,7 +135,7 @@ spec: {{ toYaml .Values.imagePullSecrets | indent 8 }} {{- end}} {{- if .Values.hostAliases }} - hostAliases: {{ toYaml .Values.hostAliases | nindent 8 }} + 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 bc1f8c69a..ac5633e05 100755 --- a/logstash/tests/logstash_test.py +++ b/logstash/tests/logstash_test.py @@ -914,6 +914,5 @@ def test_hostaliases(): - "bar.local" """ r = helm_template(config) - spec = r["statefulset"][name]["spec"]["template"]["spec"] hostAliases = r["statefulset"][name]["spec"]["template"]["spec"]["hostAliases"] assert {"ip": "127.0.0.1", "hostnames": ["foo.local", "bar.local"]} in hostAliases diff --git a/metricbeat/README.md b/metricbeat/README.md index e80e4cc33..7cb7d90ed 100644 --- a/metricbeat/README.md +++ b/metricbeat/README.md @@ -97,7 +97,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.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 | `{}` | @@ -113,7 +113,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.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][] | diff --git a/metricbeat/templates/daemonset.yaml b/metricbeat/templates/daemonset.yaml index 269c131ad..c9d253eb0 100644 --- a/metricbeat/templates/daemonset.yaml +++ b/metricbeat/templates/daemonset.yaml @@ -70,7 +70,7 @@ spec: serviceAccountName: {{ template "metricbeat.serviceAccount" . }} terminationGracePeriodSeconds: {{ .Values.terminationGracePeriod }} {{- if .Values.daemonset.hostAliases }} - hostAliases: {{ toYaml .Values.daemonset.hostAliases | nindent 8 }} + hostAliases: {{ toYaml .Values.daemonset.hostAliases | nindent 6 }} {{- end }} volumes: {{- range .Values.secretMounts | default .Values.daemonset.secretMounts }} diff --git a/metricbeat/templates/deployment.yaml b/metricbeat/templates/deployment.yaml index e14992ebf..740c1b7b1 100644 --- a/metricbeat/templates/deployment.yaml +++ b/metricbeat/templates/deployment.yaml @@ -64,7 +64,7 @@ spec: serviceAccountName: {{ template "metricbeat.serviceAccount" . }} terminationGracePeriodSeconds: {{ .Values.terminationGracePeriod }} {{- if .Values.deployment.hostAliases }} - hostAliases: {{ toYaml .Values.deployment.hostAliases | nindent 8 }} + hostAliases: {{ toYaml .Values.deployment.hostAliases | nindent 6 }} {{- end }} volumes: {{- range .Values.secretMounts | default .Values.deployment.secretMounts }}