Skip to content
This repository has been archived by the owner on May 28, 2024. It is now read-only.

Commit

Permalink
[7.x] [all] add hostaliases (elastic#970) (elastic#985)
Browse files Browse the repository at this point in the history
This commit allow to define hostAliases in all charts

kubernetes.io/docs/concepts/services-networking/add-entries-to-pod-etc-hosts-with-host-aliases
  • Loading branch information
jmlrt committed Dec 21, 2020
1 parent 86d6e17 commit 60a55aa
Show file tree
Hide file tree
Showing 25 changed files with 186 additions and 3 deletions.
2 changes: 2 additions & 0 deletions apm-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand Down Expand Up @@ -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/
Expand Down
3 changes: 3 additions & 0 deletions apm-server/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
15 changes: 15 additions & 0 deletions apm-server/tests/apmserver_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
Expand Down Expand Up @@ -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
6 changes: 6 additions & 0 deletions apm-server/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions elasticsearch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | `[]` |
Expand Down Expand Up @@ -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/
Expand Down
3 changes: 3 additions & 0 deletions elasticsearch/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
14 changes: 14 additions & 0 deletions elasticsearch/tests/elasticsearch_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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
6 changes: 6 additions & 0 deletions elasticsearch/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 4 additions & 3 deletions filebeat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | `[]` |
Expand All @@ -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 | `[]` |
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions filebeat/templates/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
14 changes: 14 additions & 0 deletions filebeat/tests/filebeat_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
5 changes: 5 additions & 0 deletions filebeat/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions kibana/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | `[]` |
Expand Down Expand Up @@ -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/
Expand Down
3 changes: 3 additions & 0 deletions kibana/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
15 changes: 15 additions & 0 deletions kibana/tests/kibana_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
Expand Down Expand Up @@ -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
6 changes: 6 additions & 0 deletions kibana/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading

0 comments on commit 60a55aa

Please sign in to comment.