Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows webserver.base_url to be templated #16126

Merged
merged 1 commit into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions chart/templates/webserver/webserver-deployment.yaml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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