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

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


The following commit(s) were added to refs/heads/main by this push:
     new ac53a9aaab Chart: configurable mountPath for DAGs volume (#35083)
ac53a9aaab is described below

commit ac53a9aaaba8d4250c8dfdf5e0b65b38a8a635b7
Author: Aakcht <aak...@gmail.com>
AuthorDate: Wed Oct 25 22:35:01 2023 +0600

    Chart: configurable mountPath for DAGs volume (#35083)
---
 chart/templates/_helpers.yaml                 | 18 ++++++++++---
 chart/values.schema.json                      |  8 ++++++
 chart/values.yaml                             |  3 +++
 helm_tests/airflow_aux/test_airflow_common.py | 16 ++++++++++++
 helm_tests/airflow_aux/test_configmap.py      | 37 +++++++++++++++++++++++++++
 5 files changed, 79 insertions(+), 3 deletions(-)

diff --git a/chart/templates/_helpers.yaml b/chart/templates/_helpers.yaml
index efeace959e..c8b41d8c29 100644
--- a/chart/templates/_helpers.yaml
+++ b/chart/templates/_helpers.yaml
@@ -455,10 +455,18 @@ server_tls_key_file = /etc/pgbouncer/server.key
 {{- end }}
 
 {{- define "airflow_dags" -}}
-  {{- if .Values.dags.gitSync.enabled }}
-    {{- printf "%s/dags/repo/%s" .Values.airflowHome 
.Values.dags.gitSync.subPath }}
+  {{- if .Values.dags.mountPath }}
+    {{- if .Values.dags.gitSync.enabled }}
+      {{- printf "%s/repo/%s" .Values.dags.mountPath 
.Values.dags.gitSync.subPath }}
+    {{- else }}
+      {{- printf "%s" .Values.dags.mountPath }}
+    {{- end }}
   {{- else }}
-    {{- printf "%s/dags" .Values.airflowHome }}
+    {{- if .Values.dags.gitSync.enabled }}
+      {{- printf "%s/dags/repo/%s" .Values.airflowHome 
.Values.dags.gitSync.subPath }}
+    {{- else }}
+      {{- printf "%s/dags" .Values.airflowHome }}
+    {{- end }}
   {{- end }}
 {{- end }}
 
@@ -472,7 +480,11 @@ server_tls_key_file = /etc/pgbouncer/server.key
 
 {{- define "airflow_dags_mount" -}}
 - name: dags
+  {{- if .Values.dags.mountPath }}
+  mountPath: {{ .Values.dags.mountPath }}
+  {{- else }}
   mountPath: {{ printf "%s/dags" .Values.airflowHome }}
+  {{- end }}
   {{- if .Values.dags.persistence.subPath }}
   subPath: {{ .Values.dags.persistence.subPath }}
   {{- end }}
diff --git a/chart/values.schema.json b/chart/values.schema.json
index d2c0288577..a1a93a51b3 100644
--- a/chart/values.schema.json
+++ b/chart/values.schema.json
@@ -6931,6 +6931,14 @@
             "x-docsSection": "Airflow",
             "additionalProperties": false,
             "properties": {
+                "mountPath": {
+                    "description": "Where dags volume will be mounted. Works 
for both `persistence` and `gitSync`. If not specified, dags mount path will be 
set to `$AIRFLOW_HOME/dags`",
+                    "type": [
+                        "string",
+                        "null"
+                    ],
+                    "default": null
+                },
                 "persistence": {
                     "description": "Persistence configuration.",
                     "type": "object",
diff --git a/chart/values.yaml b/chart/values.yaml
index 2e20acaeaa..e735800f9d 100644
--- a/chart/values.yaml
+++ b/chart/values.yaml
@@ -2351,6 +2351,9 @@ podTemplate: ~
 
 # Git sync
 dags:
+  # Where dags volume will be mounted. Works for both persistence and gitSync.
+  # If not specified, dags mount path will be set to $AIRFLOW_HOME/dags
+  mountPath: ~
   persistence:
     # Annotations for dags PVC
     annotations: {}
diff --git a/helm_tests/airflow_aux/test_airflow_common.py 
b/helm_tests/airflow_aux/test_airflow_common.py
index 72b39e031c..e25b96e5a1 100644
--- a/helm_tests/airflow_aux/test_airflow_common.py
+++ b/helm_tests/airflow_aux/test_airflow_common.py
@@ -68,6 +68,22 @@ class TestAirflowCommon:
                     "readOnly": False,
                 },
             ),
+            (
+                {"mountPath": "/opt/airflow/dags/custom", "gitSync": 
{"enabled": True}},
+                {
+                    "mountPath": "/opt/airflow/dags/custom",
+                    "name": "dags",
+                    "readOnly": True,
+                },
+            ),
+            (
+                {"mountPath": "/opt/airflow/dags/custom", "persistence": 
{"enabled": True}},
+                {
+                    "mountPath": "/opt/airflow/dags/custom",
+                    "name": "dags",
+                    "readOnly": False,
+                },
+            ),
         ],
     )
     def test_dags_mount(self, dag_values, expected_mount):
diff --git a/helm_tests/airflow_aux/test_configmap.py 
b/helm_tests/airflow_aux/test_configmap.py
index 369e340bde..623f3f1067 100644
--- a/helm_tests/airflow_aux/test_configmap.py
+++ b/helm_tests/airflow_aux/test_configmap.py
@@ -162,3 +162,40 @@ metadata:
 
         cfg = jmespath.search('data."airflow.cfg"', docs[0])
         assert expected in cfg.splitlines()
+
+    @pytest.mark.parametrize(
+        "dag_values, expected_default_dag_folder",
+        [
+            (
+                {"gitSync": {"enabled": True}},
+                "/opt/airflow/dags/repo/tests/dags",
+            ),
+            (
+                {"persistence": {"enabled": True}},
+                "/opt/airflow/dags",
+            ),
+            (
+                {"mountPath": "/opt/airflow/dags/custom", "gitSync": 
{"enabled": True}},
+                "/opt/airflow/dags/custom/repo/tests/dags",
+            ),
+            (
+                {
+                    "mountPath": "/opt/airflow/dags/custom",
+                    "gitSync": {"enabled": True, "subPath": "mysubPath"},
+                },
+                "/opt/airflow/dags/custom/repo/mysubPath",
+            ),
+            (
+                {"mountPath": "/opt/airflow/dags/custom", "persistence": 
{"enabled": True}},
+                "/opt/airflow/dags/custom",
+            ),
+        ],
+    )
+    def test_expected_default_dag_folder(self, dag_values, 
expected_default_dag_folder):
+        docs = render_chart(
+            values={"dags": dag_values},
+            show_only=["templates/configmaps/configmap.yaml"],
+        )
+        cfg = jmespath.search('data."airflow.cfg"', docs[0])
+        expected_folder_config = f"dags_folder = {expected_default_dag_folder}"
+        assert expected_folder_config in cfg.splitlines()

Reply via email to