Skip to content

Commit 7cb9f2f

Browse files
feat(airflow): support driver_ephemeral_configmaps_volumes (#75)
1 parent 954b579 commit 7cb9f2f

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

spark_on_k8s/airflow/operators.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from airflow.utils.context import Context
2020
from spark_on_k8s.client import ExecutorInstances, PodResources
2121
from spark_on_k8s.utils.app_manager import SparkAppManager
22+
from spark_on_k8s.utils.types import ConfigMap
2223

2324

2425
class _AirflowKubernetesClientManager(KubernetesClientManager):
@@ -73,6 +74,7 @@ class SparkOnK8SOperator(BaseOperator):
7374
driver_node_selector: Node selector for the driver pod.
7475
executor_node_selector: Node selector for the executor pods.
7576
driver_tolerations: Tolerations for the driver pod.
77+
driver_ephemeral_configmaps_volumes: List of ConfigMaps to mount as ephemeral volumes to the driver.
7678
spark_on_k8s_service_url: URL of the Spark On K8S service. Defaults to None.
7779
kubernetes_conn_id (str, optional): Kubernetes connection ID. Defaults to
7880
"kubernetes_default".
@@ -141,6 +143,7 @@ def __init__(
141143
executor_annotations: dict[str, str] | None = None,
142144
driver_tolerations: list[k8s.V1Toleration] | None = None,
143145
executor_pod_template_path: str | None = None,
146+
driver_ephemeral_configmaps_volumes: list[ConfigMap] | None = None,
144147
spark_on_k8s_service_url: str | None = None,
145148
kubernetes_conn_id: str = "kubernetes_default",
146149
poll_interval: int = 10,
@@ -176,6 +179,7 @@ def __init__(
176179
self.executor_annotations = executor_annotations
177180
self.driver_tolerations = driver_tolerations
178181
self.executor_pod_template_path = executor_pod_template_path
182+
self.driver_ephemeral_configmaps_volumes = driver_ephemeral_configmaps_volumes
179183
self.spark_on_k8s_service_url = spark_on_k8s_service_url
180184
self.kubernetes_conn_id = kubernetes_conn_id
181185
self.poll_interval = poll_interval
@@ -316,6 +320,7 @@ def _submit_new_job(self, context: Context):
316320
driver_annotations=self.driver_annotations,
317321
executor_annotations=self.executor_annotations,
318322
driver_tolerations=self.driver_tolerations,
323+
driver_ephemeral_configmaps_volumes=self.driver_ephemeral_configmaps_volumes,
319324
executor_pod_template_path=self.executor_pod_template_path,
320325
**submit_app_kwargs,
321326
)

tests/airflow/test_operators.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ def test_execute(self, mock_submit_app):
4444
driver_annotations={"annotation1": "value1"},
4545
executor_annotations={"annotation2": "value2"},
4646
driver_tolerations=test_tolerations,
47+
driver_ephemeral_configmaps_volumes=[
48+
{
49+
"name": "configmap-volume",
50+
"mount_path": "/etc/config",
51+
"sources": [
52+
{"name": "file1.txt", "text": "config1"},
53+
{"name": "file2.txt", "text_path": "/path/to/some/file.txt"},
54+
],
55+
},
56+
],
4757
executor_pod_template_path="s3a://bucket/executor.yml",
4858
spark_on_k8s_service_url="http://localhost:8000",
4959
)
@@ -77,6 +87,16 @@ def test_execute(self, mock_submit_app):
7787
driver_annotations={"annotation1": "value1"},
7888
executor_annotations={"annotation2": "value2"},
7989
driver_tolerations=test_tolerations,
90+
driver_ephemeral_configmaps_volumes=[
91+
{
92+
"name": "configmap-volume",
93+
"mount_path": "/etc/config",
94+
"sources": [
95+
{"name": "file1.txt", "text": "config1"},
96+
{"name": "file2.txt", "text_path": "/path/to/some/file.txt"},
97+
],
98+
},
99+
],
80100
executor_pod_template_path="s3a://bucket/executor.yml",
81101
)
82102
assert ti_mock.xcom_push.call_count == 3
@@ -193,6 +213,7 @@ def test_rendering_templates(self, mock_submit_app):
193213
executor_annotations=None,
194214
driver_tolerations=None,
195215
executor_pod_template_path=None,
216+
driver_ephemeral_configmaps_volumes=None,
196217
)
197218
assert app_id_suffix_kwarg() == "-suffix"
198219

0 commit comments

Comments
 (0)