Skip to content

Commit 8edbf34

Browse files
authored
fix: Helm execution_api_server_url when base_url has a subpath (#51454)
1 parent 72892d2 commit 8edbf34

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

chart/templates/configmaps/configmap.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,13 @@ metadata:
4040
data:
4141
{{/*- Set a default for core.execution_api_server_url pointing to the api-server service if it's not set -*/}}
4242
{{- if semverCompare ">=3.0.0" .Values.airflowVersion -}}
43+
{{- $basePath := "" -}}
4344
{{- $config := merge .Values.config ( dict "core" dict )}}
4445
{{- if not (hasKey $config.core "execution_api_server_url") -}}
45-
{{- $_ := set $config.core "execution_api_server_url" (printf "http://%s-api-server:%d/execution/" (include "airflow.fullname" .) (int .Values.ports.apiServer)) -}}
46+
{{- if (and $config.api $config.api.base_url) -}}
47+
{{- with urlParse $config.api.base_url }}{{ $basePath = (trimSuffix "/" .path) }}{{ end }}
48+
{{- end -}}
49+
{{- $_ := set $config.core "execution_api_server_url" (printf "http://%s-api-server:%d%s/execution/" (include "airflow.fullname" .) (int .Values.ports.apiServer) $basePath) -}}
4650
{{- end -}}
4751
{{- end -}}
4852
# These are system-specified config overrides.

helm-tests/tests/helm_tests/airflow_aux/test_configmap.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,65 @@ def test_standalone_dag_processor_explicit(self, airflow_version, enabled):
240240
cfg = jmespath.search('data."airflow.cfg"', docs[0])
241241
expected_line = f"standalone_dag_processor = {str(enabled).lower()}"
242242
assert expected_line in cfg.splitlines()
243+
244+
@pytest.mark.parametrize(
245+
"airflow_version, base_url, execution_api_server_url, expected_execution_url",
246+
[
247+
(
248+
"3.0.0",
249+
None,
250+
None,
251+
"http://release-name-api-server:8080/execution",
252+
),
253+
(
254+
"2.9.0",
255+
None,
256+
None,
257+
None,
258+
),
259+
(
260+
"3.0.0",
261+
"http://example.com",
262+
None,
263+
"http://release-name-api-server:8080/execution",
264+
),
265+
(
266+
"3.0.0",
267+
"http://example.com/airflow",
268+
None,
269+
"http://release-name-api-server:8080/airflow/execution",
270+
),
271+
(
272+
"3.0.0",
273+
"http://example.com/airflow",
274+
"http://service:9090/execution/",
275+
"http://service:9090/execution/",
276+
),
277+
],
278+
)
279+
def test_execution_api_server_url(
280+
self, airflow_version, base_url, execution_api_server_url, expected_execution_url
281+
):
282+
config_overrides = {}
283+
if base_url:
284+
config_overrides["api"] = {"base_url": base_url}
285+
286+
if execution_api_server_url:
287+
config_overrides["core"] = {"execution_api_server_url": execution_api_server_url}
288+
289+
configmap = render_chart(
290+
values={"airflowVersion": airflow_version, "config": config_overrides},
291+
show_only=["templates/configmaps/configmap.yaml"],
292+
)
293+
294+
# config is the jmespath search for the data["airflow.cfg"] in the configmap
295+
config = jmespath.search('data.["airflow.cfg"]', configmap[0])
296+
assert config is not None, "Configmap data for airflow.cfg should not be None"
297+
assert len(config) > 0, "Configmap data for airflow.cfg should not be empty"
298+
299+
if expected_execution_url is not None:
300+
assert f"\nexecution_api_server_url = {expected_execution_url}" in config[0]
301+
else:
302+
assert "execution_api_server_url" not in config[0], (
303+
"execution_api_server_url should not be set for Airflow 2.x versions"
304+
)

0 commit comments

Comments
 (0)