diff --git a/chart/templates/webserver/webserver-deployment.yaml b/chart/templates/webserver/webserver-deployment.yaml index 8ef76bdcf945d..8483454c1f08f 100644 --- a/chart/templates/webserver/webserver-deployment.yaml +++ b/chart/templates/webserver/webserver-deployment.yaml @@ -110,6 +110,10 @@ spec: {{ toYaml $tolerations | indent 8 }} topologySpreadConstraints: {{ toYaml $topologySpreadConstraints | indent 8 }} +{{- if .Values.webserver.hostAliases }} + hostAliases: +{{ toYaml .Values.webserver.hostAliases | indent 8 }} +{{- end }} restartPolicy: Always securityContext: {{ $securityContext | nindent 8 }} {{- if or .Values.registry.secretName .Values.registry.connection }} diff --git a/chart/values.schema.json b/chart/values.schema.json index 53a8b06d1cc6f..337420bd687a5 100644 --- a/chart/values.schema.json +++ b/chart/values.schema.json @@ -2908,6 +2908,28 @@ "$ref": "#/definitions/io.k8s.api.core.v1.TopologySpreadConstraint" } }, + "hostAliases": { + "description": "Specify HostAliases for webserver.", + "items": { + "$ref": "#/definitions/io.k8s.api.core.v1.HostAlias" + }, + "type": "array", + "default": [], + "examples": [ + { + "ip": "127.0.0.2", + "hostnames": [ + "test.hostname.one" + ] + }, + { + "ip": "127.0.0.3", + "hostnames": [ + "test.hostname.two" + ] + } + ] + }, "podAnnotations": { "description": "Annotations to add to the webserver pods.", "type": "object", diff --git a/chart/values.yaml b/chart/values.yaml index 0ec7be6bdd544..0c9ff964229b8 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -940,6 +940,16 @@ webserver: # weight: 100 tolerations: [] topologySpreadConstraints: [] + # hostAliases to use in webserver pod. + # See: + # https://kubernetes.io/docs/concepts/services-networking/add-entries-to-pod-etc-hosts-with-host-aliases/ + hostAliases: [] + # - ip: "127.0.0.2" + # hostnames: + # - "test.hostname.one" + # - ip: "127.0.0.3" + # hostnames: + # - "test.hostname.two" podAnnotations: {} diff --git a/tests/charts/test_webserver.py b/tests/charts/test_webserver.py index e7a84d1828124..b30ab51717cd9 100644 --- a/tests/charts/test_webserver.py +++ b/tests/charts/test_webserver.py @@ -184,6 +184,19 @@ def test_should_add_extra_init_containers(self): "image": "test-registry/test-repo:test-tag", } == jmespath.search("spec.template.spec.initContainers[-1]", docs[0]) + def test_webserver_host_aliases(self): + docs = render_chart( + values={ + "webserver": { + "hostAliases": [{"ip": "127.0.0.2", "hostnames": ["test.hostname"]}], + }, + }, + show_only=["templates/webserver/webserver-deployment.yaml"], + ) + + assert "127.0.0.2" == jmespath.search("spec.template.spec.hostAliases[0].ip", docs[0]) + assert "test.hostname" == jmespath.search("spec.template.spec.hostAliases[0].hostnames[0]", docs[0]) + def test_should_create_valid_affinity_tolerations_and_node_selector(self): docs = render_chart( values={