Skip to content

Commit

Permalink
[backport] Fix bug with executor_config and Volumes
Browse files Browse the repository at this point in the history
Without this fix the following DAG will not create Volumes & Volume Mounts and fais:

```python
dag1 = DAG(
    dag_id='example_k8s-dags',
    schedule_interval='@once',
    start_date=datetime(2020, 1, 1)
)
p = PythonOperator(
    task_id='test',
    dag=dag1,
    python_callable=lambda: 1,
    executor_config={
        "KubernetesExecutor": {
            'resources': {
                'limits': {'memory': '200Mi', 'cpu': '100m'},
                'requests': {'memory': '100Mi', 'cpu': '100m'}
            },
            "volumes": [
                {
                    "name": "tmp-volume",
                    "hostPath": {"path": "/tmp/"},
                },
            ],
            "volume_mounts": [
                {
                    "mountPath": "/tmp/",
                    "name": "tmp-volume",
                },
            ],
        }
    }
)
```

(cherry picked from commit 7813076)
  • Loading branch information
kaxil committed Jul 20, 2021
1 parent 815dcd5 commit e268afd
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions airflow/kubernetes/pod_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import yaml
from dateutil import parser
from kubernetes.client.api_client import ApiClient
from airflow.contrib.kubernetes.pod import _extract_volume_mounts
from airflow.contrib.kubernetes.pod import _extract_volume_mounts, _extract_volumes

from airflow.exceptions import AirflowConfigException
from airflow.version import version as airflow_version
Expand Down Expand Up @@ -281,7 +281,7 @@ def __init__(
self.spec.affinity = affinity
self.spec.service_account_name = service_account_name
self.spec.init_containers = init_containers
self.spec.volumes = volumes or []
self.spec.volumes = [v.to_k8s_client_obj() for v in _extract_volumes(volumes)] or []
self.spec.node_selector = node_selectors
self.spec.restart_policy = restart_policy
self.spec.priority_class_name = priority_class_name
Expand Down

0 comments on commit e268afd

Please sign in to comment.