Miretpl commented on code in PR #70425:
URL: https://github.com/apache/airflow/pull/70425#discussion_r3669196363
##########
chart/docs/production-guide.rst:
##########
@@ -429,13 +429,35 @@ the chart only creates the ``HTTPRoute`` resources and
attaches them to the Gate
hostnames:
- flower.example.com
+The Webserver exists only on Airflow 2 (the API server replaces it on Airflow
3), so its ``HTTPRoute``
+is configured in an Airflow 2 deployment:
+
+.. code-block:: yaml
+ :caption: values.yaml (Airflow 2)
+
+ defaultAirflowTag: "2.11.0"
+ airflowVersion: "2.11.0"
+
+ webserver:
+ httpRoute:
+ enabled: true
+ parentRefs:
+ - name: main-gateway
+ namespace: gateway-system
+ sectionName: https
+ hostnames:
+ - airflow.example.com
+
Flower HTTPRoute resources are only created when Flower itself is created, so
``flower.enabled`` must be
``true`` and the executor must include ``CeleryExecutor`` or
``CeleryKubernetesExecutor``.
-
-For fine-grained routing, supply ``apiServer.httpRoute.rules`` or
``flower.httpRoute.rules`` directly —
-the entry mirrors the upstream ``HTTPRouteRule`` schema and overrides the
default rule generated from
-the corresponding ``apiServer.httpRoute.path`` and
``apiServer.httpRoute.pathType``, or
-``flower.httpRoute.path`` and ``flower.httpRoute.pathType`` values.
+Webserver HTTPRoute resources are only created for Airflow 2 deployments
(``airflowVersion`` < 3.0.0).
Review Comment:
```suggestion
```
It is already stated a couple of lines above, so it should not be needed
here. Also, I think that below can be just added to the paragraph above.
##########
chart/values.yaml:
##########
@@ -2529,6 +2530,52 @@ apiServer:
webserver:
enabled: true
+ # Kubernetes Gateway API (HTTPRoute) configuration for the Webserver.
+ # Only applies to Airflow 2 (`airflowVersion` < 3.0.0), where the Webserver
exists.
Review Comment:
```suggestion
```
We have this info couple lines above.
##########
helm-tests/tests/helm_tests/airflow_aux/test_basic_helm_chart.py:
##########
@@ -384,35 +384,41 @@ def test_network_policies_are_valid(self,
airflow_version, executor):
"flower": {"enabled": True},
},
("flower-ingress", "Ingress", "flower-ingress"),
+ ("ingress", "Ingress", "airflow-ingress"),
[],
- id="flower-ingress",
+ id="ingress",
),
pytest.param(
{
- "ingress": {
- "web": {"enabled": True},
- "apiServer": {"enabled": True},
- },
+ "ingress": {"apiServer": {"enabled": True}},
Review Comment:
Why we are deleting `web` option?
##########
chart/values.schema.json:
##########
@@ -12519,6 +12339,101 @@
}
},
"definitions": {
+ "httpRoute": {
Review Comment:
Could you also do a similar change for the main (extraction of httpRoute def
to definitions)?
##########
helm-tests/tests/helm_tests/webserver/test_httproute_webserver.py:
##########
@@ -0,0 +1,409 @@
+# 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.
+from __future__ import annotations
+
+import jmespath
+import pytest
+from chart_utils.helm_template_generator import HelmFailedError, render_chart
+
+SHOW_ONLY = ["templates/webserver/webserver-httproute.yaml"]
+WEBSERVER_INGRESS_SHOW_ONLY = ["templates/webserver/webserver-ingress.yaml"]
+
+GATEWAY_API_VERSIONS = ["gateway.networking.k8s.io/v1"]
+MINIMAL_PARENT_REFS = [{"name": "main-gateway"}]
+# The Webserver only exists on Airflow 2 (`airflowVersion` < 3.0.0); the API
server replaces it on 3.
+AIRFLOW_2 = "2.11.0"
+
+
+class TestHTTPRouteWebserver:
+ """Tests HTTPRoute Webserver (Kubernetes Gateway API)."""
+
+ def test_should_pass_validation_with_minimal_config(self):
+ docs = render_chart(
+ values={
+ "airflowVersion": AIRFLOW_2,
+ "webserver": {
+ "enabled": True,
+ "httpRoute": {"enabled": True, "parentRefs":
MINIMAL_PARENT_REFS},
+ },
+ },
+ show_only=SHOW_ONLY,
+ api_versions=GATEWAY_API_VERSIONS,
+ )
+ assert len(docs) == 1
+ assert jmespath.search("kind", docs[0]) == "HTTPRoute"
+ assert jmespath.search("metadata.name", docs[0]) ==
"release-name-webserver-httproute"
+
+ def test_should_set_api_version_and_kind(self):
+ docs = render_chart(
+ values={
+ "airflowVersion": AIRFLOW_2,
+ "webserver": {
+ "enabled": True,
+ "httpRoute": {"enabled": True, "parentRefs":
MINIMAL_PARENT_REFS},
+ },
+ },
+ show_only=SHOW_ONLY,
+ api_versions=GATEWAY_API_VERSIONS,
+ )
+ assert jmespath.search("apiVersion", docs[0]) ==
"gateway.networking.k8s.io/v1"
+ assert jmespath.search("kind", docs[0]) == "HTTPRoute"
+
+ def test_should_allow_more_than_one_annotation(self):
+ docs = render_chart(
+ values={
+ "airflowVersion": AIRFLOW_2,
+ "webserver": {
+ "enabled": True,
+ "httpRoute": {
+ "enabled": True,
+ "parentRefs": MINIMAL_PARENT_REFS,
+ "annotations": {"aa": "bb", "cc": "dd"},
+ },
+ },
+ },
+ show_only=SHOW_ONLY,
+ api_versions=GATEWAY_API_VERSIONS,
+ )
+ assert jmespath.search("metadata.annotations", docs[0]) == {"aa":
"bb", "cc": "dd"}
+
+ def test_should_add_extra_labels(self):
+ docs = render_chart(
+ values={
+ "airflowVersion": AIRFLOW_2,
+ "webserver": {
+ "enabled": True,
+ "httpRoute": {
+ "enabled": True,
+ "parentRefs": MINIMAL_PARENT_REFS,
+ "labels": {"custom": "value"},
+ },
+ },
+ },
+ show_only=SHOW_ONLY,
+ api_versions=GATEWAY_API_VERSIONS,
+ )
+ assert jmespath.search('metadata.labels."custom"', docs[0]) == "value"
+
+ def test_should_pass_parent_refs_through(self):
+ docs = render_chart(
+ values={
+ "airflowVersion": AIRFLOW_2,
+ "webserver": {
+ "enabled": True,
+ "httpRoute": {
+ "enabled": True,
+ "parentRefs": [
+ {"name": "main-gateway", "namespace":
"gateway-system"},
+ {"name": "main-gateway", "namespace":
"gateway-system", "sectionName": "https"},
+ ],
+ },
+ },
+ },
+ show_only=SHOW_ONLY,
+ api_versions=GATEWAY_API_VERSIONS,
+ )
+ assert jmespath.search("spec.parentRefs", docs[0]) == [
+ {"name": "main-gateway", "namespace": "gateway-system"},
+ {"name": "main-gateway", "namespace": "gateway-system",
"sectionName": "https"},
+ ]
+
+ def test_should_set_hostnames(self):
+ docs = render_chart(
+ values={
+ "airflowVersion": AIRFLOW_2,
+ "webserver": {
+ "enabled": True,
+ "httpRoute": {
+ "enabled": True,
+ "parentRefs": MINIMAL_PARENT_REFS,
+ "hostnames": ["airflow.example.com",
"airflow2.example.com"],
+ },
+ },
+ },
+ show_only=SHOW_ONLY,
+ api_versions=GATEWAY_API_VERSIONS,
+ )
+ assert jmespath.search("spec.hostnames", docs[0]) == [
+ "airflow.example.com",
+ "airflow2.example.com",
+ ]
+
+ def test_hostnames_should_be_templated(self):
+ docs = render_chart(
+ name="airflow",
+ values={
+ "airflowVersion": AIRFLOW_2,
+ "webserver": {
+ "enabled": True,
+ "httpRoute": {
+ "enabled": True,
+ "parentRefs": MINIMAL_PARENT_REFS,
+ "hostnames": ["{{ .Release.Name }}.example.com"],
+ },
+ },
+ },
+ show_only=SHOW_ONLY,
+ api_versions=GATEWAY_API_VERSIONS,
+ )
+ assert jmespath.search("spec.hostnames", docs[0]) ==
["airflow.example.com"]
+
+ def test_should_default_to_path_prefix_and_webserver_backend(self):
+ docs = render_chart(
+ name="my-release",
+ values={
+ "airflowVersion": AIRFLOW_2,
+ "webserver": {
+ "enabled": True,
+ "httpRoute": {"enabled": True, "parentRefs":
MINIMAL_PARENT_REFS},
+ },
+ },
+ show_only=SHOW_ONLY,
+ api_versions=GATEWAY_API_VERSIONS,
+ )
+ assert jmespath.search("spec.rules", docs[0]) == [
+ {
+ "matches": [{"path": {"type": "PathPrefix", "value": "/"}}],
+ "backendRefs": [{"name": "my-release-webserver", "port":
8080}],
+ },
+ ]
+
+ def test_custom_path_and_path_type_should_apply(self):
+ docs = render_chart(
+ values={
+ "airflowVersion": AIRFLOW_2,
+ "webserver": {
+ "enabled": True,
+ "httpRoute": {
+ "enabled": True,
+ "parentRefs": MINIMAL_PARENT_REFS,
+ "path": "/web",
+ "pathType": "Exact",
+ },
+ },
+ },
+ show_only=SHOW_ONLY,
+ api_versions=GATEWAY_API_VERSIONS,
+ )
+ assert jmespath.search("spec.rules[0].matches[0].path.type", docs[0])
== "Exact"
+ assert jmespath.search("spec.rules[0].matches[0].path.value", docs[0])
== "/web"
+
+ def test_custom_rules_override_default_rule(self):
+ docs = render_chart(
+ values={
+ "airflowVersion": AIRFLOW_2,
+ "webserver": {
+ "enabled": True,
+ "httpRoute": {
+ "enabled": True,
+ "parentRefs": MINIMAL_PARENT_REFS,
+ "rules": [
+ {
+ "matches": [{"path": {"type": "PathPrefix",
"value": "/custom-web"}}],
+ "backendRefs": [{"name": "external-webserver",
"port": 8443}],
+ },
+ ],
+ },
+ },
+ },
+ show_only=SHOW_ONLY,
+ api_versions=GATEWAY_API_VERSIONS,
+ )
+ assert jmespath.search("spec.rules", docs[0]) == [
+ {
+ "matches": [{"path": {"type": "PathPrefix", "value":
"/custom-web"}}],
+ "backendRefs": [{"name": "external-webserver", "port": 8443}],
+ },
+ ]
+
+ def test_should_use_airflow_ui_port_for_default_backend(self):
+ docs = render_chart(
+ values={
+ "airflowVersion": AIRFLOW_2,
+ "ports": {"airflowUI": 9000},
+ "webserver": {
+ "enabled": True,
+ "httpRoute": {"enabled": True, "parentRefs":
MINIMAL_PARENT_REFS},
+ },
+ },
+ show_only=SHOW_ONLY,
+ api_versions=GATEWAY_API_VERSIONS,
+ )
+ assert jmespath.search("spec.rules[0].backendRefs[0].port", docs[0])
== 9000
+
+ def test_httproute_not_created_when_unset(self):
+ docs = render_chart(
+ values={"airflowVersion": AIRFLOW_2, "webserver": {"enabled":
True, "httpRoute": {}}},
+ show_only=SHOW_ONLY,
+ api_versions=GATEWAY_API_VERSIONS,
+ )
+ assert docs == []
+
+ def test_httproute_not_created_when_disabled(self):
+ docs = render_chart(
+ values={
+ "airflowVersion": AIRFLOW_2,
+ "webserver": {"enabled": True, "httpRoute": {"enabled":
False}},
+ },
+ show_only=SHOW_ONLY,
+ api_versions=GATEWAY_API_VERSIONS,
+ )
+ assert docs == []
+
+ def test_should_not_render_when_webserver_disabled(self):
+ docs = render_chart(
+ values={
+ "airflowVersion": AIRFLOW_2,
+ "webserver": {
+ "enabled": False,
+ "httpRoute": {"enabled": True, "parentRefs":
MINIMAL_PARENT_REFS},
+ },
+ },
+ show_only=SHOW_ONLY,
+ api_versions=GATEWAY_API_VERSIONS,
+ )
+ assert docs == []
+
+ @pytest.mark.parametrize("airflow_version", ["3.0.0", "3.3.0"])
+ def test_should_not_render_on_airflow_3(self, airflow_version):
+ docs = render_chart(
+ values={
+ "airflowVersion": airflow_version,
Review Comment:
```suggestion
def test_should_not_render_on_airflow_3(self):
docs = render_chart(
values={
```
Testing on the default should be enough.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]