You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2021/01/12 12:03:50 UTC

[airflow] branch master updated: Allow customization of probes path and host (#12634)

This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/master by this push:
     new 75fd5f8  Allow customization of probes path and host (#12634)
75fd5f8 is described below

commit 75fd5f8254a6ecf616475a485f6da76240a34776
Author: Ruben Laguna <ru...@gmail.com>
AuthorDate: Tue Jan 12 13:03:39 2021 +0100

    Allow customization of probes path and host (#12634)
---
 .../templates/webserver/webserver-deployment.yaml  |  14 ++-
 chart/tests/test_webserver_deployment.py           | 108 +++++++++++++++++++++
 2 files changed, 120 insertions(+), 2 deletions(-)

diff --git a/chart/templates/webserver/webserver-deployment.yaml b/chart/templates/webserver/webserver-deployment.yaml
index 7674e21..d12d1f6 100644
--- a/chart/templates/webserver/webserver-deployment.yaml
+++ b/chart/templates/webserver/webserver-deployment.yaml
@@ -129,16 +129,26 @@ spec:
               containerPort: {{ .Values.ports.airflowUI }}
           livenessProbe:
             httpGet:
-              path: /health
+              path: {{if .Values.config.webserver.base_url }}{{- with urlParse .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  "" }}
+{{- 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: /health
+              path: {{if .Values.config.webserver.base_url }}{{- with urlParse .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  "" }}
+{{- end }}
             initialDelaySeconds: {{ .Values.webserver.readinessProbe.initialDelaySeconds | default 15 }}
             timeoutSeconds: {{ .Values.webserver.readinessProbe.timeoutSeconds | default 30 }}
             failureThreshold: {{ .Values.webserver.readinessProbe.failureThreshold | default 20 }}
diff --git a/chart/tests/test_webserver_deployment.py b/chart/tests/test_webserver_deployment.py
new file mode 100644
index 0000000..9d63106
--- /dev/null
+++ b/chart/tests/test_webserver_deployment.py
@@ -0,0 +1,108 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import unittest
+
+import jmespath
+
+from tests.helm_template_generator import render_chart
+
+
+class WebserverDeploymentTest(unittest.TestCase):
+    def test_should_add_host_header_to_liveness_and_readiness_probes(self):
+        docs = render_chart(
+            values={
+                "config": {
+                    "webserver": {"base_url": "https://example.com:21222/mypath/path"},
+                }
+            },
+            show_only=["templates/webserver/webserver-deployment.yaml"],
+        )
+
+        assert {"name": "Host", "value": "example.com"} in jmespath.search(
+            "spec.template.spec.containers[0].livenessProbe.httpGet.httpHeaders", docs[0]
+        )
+        assert {"name": "Host", "value": "example.com"} in jmespath.search(
+            "spec.template.spec.containers[0].readinessProbe.httpGet.httpHeaders", docs[0]
+        )
+
+    def test_should_add_path_to_liveness_and_readiness_probes(self):
+        docs = render_chart(
+            values={
+                "config": {
+                    "webserver": {"base_url": "https://example.com:21222/mypath/path"},
+                }
+            },
+            show_only=["templates/webserver/webserver-deployment.yaml"],
+        )
+
+        assert (
+            jmespath.search("spec.template.spec.containers[0].livenessProbe.httpGet.path", docs[0])
+            == "/mypath/path/health"
+        )
+        assert (
+            jmespath.search("spec.template.spec.containers[0].readinessProbe.httpGet.path", docs[0])
+            == "/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"],
+        )
+
+        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
+        )
+
+    def test_should_not_contain_host_header_if_base_url_not_set(self):
+        docs = render_chart(
+            values={
+                "config": {
+                    "webserver": {"base_url": ""},
+                }
+            },
+            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
+        )
+
+    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
+        )