From 2976a56f8531d3ef9782ba251911e7c7f474eda1 Mon Sep 17 00:00:00 2001 From: Kim Minwoo Date: Mon, 14 Aug 2023 16:12:07 +0900 Subject: [PATCH] Allow templating webserver ingress hostnames (#33142) --- .../webserver/webserver-ingress.yaml | 2 +- chart/values.yaml | 1 + helm_tests/webserver/test_ingress_web.py | 33 +++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/chart/templates/webserver/webserver-ingress.yaml b/chart/templates/webserver/webserver-ingress.yaml index 45ad6c036e1c1..0f6b1d82d0818 100644 --- a/chart/templates/webserver/webserver-ingress.yaml +++ b/chart/templates/webserver/webserver-ingress.yaml @@ -101,7 +101,7 @@ spec: {{- $hostname = .name -}} {{- end }} {{- if $hostname }} - host: {{ $hostname | quote }} + host: {{ include "common.tplvalues.render" ( dict "value" $hostname "context" $ ) | quote }} {{- end }} {{- end }} {{- if .Values.ingress.web.ingressClassName }} diff --git a/chart/values.yaml b/chart/values.yaml index f0edd2861b8a8..9728eb9525bba 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -140,6 +140,7 @@ ingress: # The hostnames or hosts configuration for the web Ingress hosts: [] + # # The hostname for the web Ingress (can be templated) # - name: "" # # configs for web Ingress TLS # tls: diff --git a/helm_tests/webserver/test_ingress_web.py b/helm_tests/webserver/test_ingress_web.py index b90eee352de6a..798da6c719594 100644 --- a/helm_tests/webserver/test_ingress_web.py +++ b/helm_tests/webserver/test_ingress_web.py @@ -167,3 +167,36 @@ def test_should_add_component_specific_labels(self): ) assert "test_label" in jmespath.search("metadata.labels", docs[0]) assert jmespath.search("metadata.labels", docs[0])["test_label"] == "test_label_value" + + def test_can_ingress_hosts_be_templated(self): + docs = render_chart( + values={ + "testValues": { + "scalar": "aa", + "list": ["bb", "cc"], + "dict": { + "key": "dd", + }, + }, + "ingress": { + "web": { + "enabled": True, + "hosts": [ + {"name": "*.{{ .Release.Namespace }}.example.com"}, + {"name": "{{ .Values.testValues.scalar }}.example.com"}, + {"name": "{{ index .Values.testValues.list 1 }}.example.com"}, + {"name": "{{ .Values.testValues.dict.key }}.example.com"}, + ], + }, + }, + }, + show_only=["templates/webserver/webserver-ingress.yaml"], + namespace="airflow", + ) + + assert [ + "*.airflow.example.com", + "aa.example.com", + "cc.example.com", + "dd.example.com", + ] == jmespath.search("spec.rules[*].host", docs[0])