-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-pod-operator.py
52 lines (44 loc) · 1.7 KB
/
test-pod-operator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from airflow import DAG
from datetime import datetime, timedelta
from airflow.contrib.operators.kubernetes_pod_operator import KubernetesPodOperator
from airflow.operators.dummy_operator import DummyOperator
from airflow.contrib.kubernetes.volume_mount import VolumeMount
from airflow.contrib.kubernetes.volume import Volume
default_args = {
'owner': 'airflow',
'depends_on_past': False,
'start_date': datetime.utcnow(),
'email': ['[email protected]'],
'email_on_failure': False,
'email_on_retry': False,
'retries': 1,
'retry_delay': timedelta(minutes=5)
}
dag = DAG(
'kubernetes_test_pod', default_args=default_args, schedule_interval=timedelta(minutes=10))
start = DummyOperator(task_id='run_this_first', dag=dag)
volume_mount = VolumeMount('airflow-dags',
mount_path='/dags',
sub_path=None,
read_only=True)
volume_config = {
'persistentVolumeClaim':
{
'claimName': 'airflow-dags2'
}
}
volume = Volume(name='airflow-dags', configs=volume_config)
file_path = "/root/kubeconfig/kubeconfig"
passing = KubernetesPodOperator(namespace='airflow4',
image="python:3.6",
cmds=["python", "dags/test-python.py"],
labels={"foo": "bar"},
name="passing-test",
task_id="passing-task",
volume_mounts=[volume_mount],
config_file=file_path,
volumes=[volume],
get_logs=True,
dag=dag
)
passing.set_upstream(start)