Skip to content

Commit

Permalink
Chart: Allow webserver.base_url to be templated (#16126)
Browse files Browse the repository at this point in the history
As `config`'s documentation states values are passed through `tpl`,
one would expect `config.webserver.base_url` to also support templating.
  • Loading branch information
jedcunningham committed May 28, 2021
1 parent a7e1f7a commit a2bd872
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 31 deletions.
8 changes: 4 additions & 4 deletions chart/templates/webserver/webserver-deployment.yaml
Expand Up @@ -149,25 +149,25 @@ spec:
containerPort: {{ .Values.ports.airflowUI }}
livenessProbe:
httpGet:
path: {{if .Values.config.webserver.base_url }}{{- with urlParse .Values.config.webserver.base_url }}{{ .path }}{{end}}{{end}}/health
path: {{if .Values.config.webserver.base_url }}{{- with urlParse (tpl .Values.config.webserver.base_url .) }}{{ .path }}{{end}}{{end}}/health
port: {{ .Values.ports.airflowUI }}
{{- if .Values.config.webserver.base_url}}
httpHeaders:
- name: Host
value: {{ regexReplaceAll ":\\d+$" (urlParse .Values.config.webserver.base_url).host "" }}
value: {{ regexReplaceAll ":\\d+$" (urlParse (tpl .Values.config.webserver.base_url .)).host "" }}
{{- end }}
initialDelaySeconds: {{ .Values.webserver.livenessProbe.initialDelaySeconds | default 15 }}
timeoutSeconds: {{ .Values.webserver.livenessProbe.timeoutSeconds | default 30 }}
failureThreshold: {{ .Values.webserver.livenessProbe.failureThreshold | default 20 }}
periodSeconds: {{ .Values.webserver.livenessProbe.periodSeconds | default 5 }}
readinessProbe:
httpGet:
path: {{if .Values.config.webserver.base_url }}{{- with urlParse .Values.config.webserver.base_url }}{{ .path }}{{end}}{{end}}/health
path: {{if .Values.config.webserver.base_url }}{{- with urlParse (tpl .Values.config.webserver.base_url .) }}{{ .path }}{{end}}{{end}}/health
port: {{ .Values.ports.airflowUI }}
{{- if .Values.config.webserver.base_url}}
httpHeaders:
- name: Host
value: {{ regexReplaceAll ":\\d+$" (urlParse .Values.config.webserver.base_url).host "" }}
value: {{ regexReplaceAll ":\\d+$" (urlParse (tpl .Values.config.webserver.base_url .)).host "" }}
{{- end }}
initialDelaySeconds: {{ .Values.webserver.readinessProbe.initialDelaySeconds | default 15 }}
timeoutSeconds: {{ .Values.webserver.readinessProbe.timeoutSeconds | default 30 }}
Expand Down
47 changes: 20 additions & 27 deletions chart/tests/test_webserver.py
Expand Up @@ -60,11 +60,15 @@ def test_should_add_path_to_liveness_and_readiness_probes(self):
== "/mypath/path/health"
)

def test_should_not_contain_host_header_if_host_empty_string(self):
docs = render_chart(
values={},
show_only=["templates/webserver/webserver-deployment.yaml"],
)
@parameterized.expand(
[
({"config": {"webserver": {"base_url": ""}}},),
({},),
]
)
def test_should_not_contain_host_header(self, values):
print(values)
docs = render_chart(values=values, show_only=["templates/webserver/webserver-deployment.yaml"])

assert (
jmespath.search("spec.template.spec.containers[0].livenessProbe.httpGet.httpHeaders", docs[0])
Expand All @@ -75,38 +79,27 @@ def test_should_not_contain_host_header_if_host_empty_string(self):
is None
)

def test_should_not_contain_host_header_if_base_url_not_set(self):
def test_should_use_templated_base_url_for_probes(self):
docs = render_chart(
values={
"config": {
"webserver": {"base_url": ""},
"webserver": {
"base_url": "https://{{ .Release.Name }}.com:21222/mypath/{{ .Release.Name }}/path"
},
}
},
show_only=["templates/webserver/webserver-deployment.yaml"],
)
container = jmespath.search("spec.template.spec.containers[0]", docs[0])

assert (
jmespath.search("spec.template.spec.containers[0].livenessProbe.httpGet.httpHeaders", docs[0])
is None
assert {"name": "Host", "value": "RELEASE-NAME.com"} in jmespath.search(
"livenessProbe.httpGet.httpHeaders", container
)
assert (
jmespath.search("spec.template.spec.containers[0].readinessProbe.httpGet.httpHeaders", docs[0])
is None
)

def test_should_not_contain_host_header_by_default(self):
docs = render_chart(
show_only=["templates/webserver/webserver-deployment.yaml"],
)

assert (
jmespath.search("spec.template.spec.containers[0].livenessProbe.httpGet.httpHeaders", docs[0])
is None
)
assert (
jmespath.search("spec.template.spec.containers[0].readinessProbe.httpGet.httpHeaders", docs[0])
is None
assert {"name": "Host", "value": "RELEASE-NAME.com"} in jmespath.search(
"readinessProbe.httpGet.httpHeaders", container
)
assert "/mypath/RELEASE-NAME/path/health" == jmespath.search("livenessProbe.httpGet.path", container)
assert "/mypath/RELEASE-NAME/path/health" == jmespath.search("readinessProbe.httpGet.path", container)

def test_should_add_volume_and_volume_mount_when_exist_webserver_config(self):
docs = render_chart(
Expand Down

0 comments on commit a2bd872

Please sign in to comment.