passfail.py 1.87 KB
Newer Older
one_jh's avatar
one_jh committed
1
2
3
4
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
one_jh's avatar
one_jh committed
5
from airflow.operators.bash import BashOperator
one_jh's avatar
one_jh committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19


default_args = {
    'owner': 'airflow',
    'depends_on_past': False,
    'start_date': datetime.utcnow(),
    'email': ['airflow@example.com'],
    'email_on_failure': False,
    'email_on_retry': False,
    'retries': 1,
    'retry_delay': timedelta(minutes=5)
}

dag = DAG(
one_jh's avatar
one_jh committed
20
    'kubernetes_sample', default_args=default_args, schedule_interval=timedelta(minutes=1))
one_jh's avatar
one_jh committed
21
22
23
24


start = DummyOperator(task_id='run_this_first', dag=dag)

one_jh's avatar
one_jh committed
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# passing = KubernetesPodOperator(namespace='default',
#                           image="Python:3.6",
#                           cmds=["Python","-c"],
#                           arguments=["print('hello world')"],
#                           labels={"foo": "bar"},
#                           name="passing-test",
#                           task_id="passing-task",
#                           get_logs=True,
#                           dag=dag
#                           )

# failing = KubernetesPodOperator(namespace='default',
#                           image="ubuntu:1604",
#                           cmds=["Python","-c"],
#                           arguments=["print('hello world')"],
#                           labels={"foo": "bar"},
#                           name="fail",
#                           task_id="failing-task",
#                           get_logs=True,
#                           dag=dag
#                           )
one_jh's avatar
one_jh committed
46

one_jh's avatar
one_jh committed
47
48
49
50
51
52
53
54
55
templated_command = """
kubectl get pods
"""

run_this = BashOperator(
    task_id='bash_test',
    bash_command=templated_command,
    dag=dag,
)
one_jh's avatar
one_jh committed
56
57
58
start >> run_this
# start >> passing >> run_this
# start >> failing
one_jh's avatar
one_jh committed
59
60
# passing.set_upstream(start)
# failing.set_upstream(start)