Skip to content

Commit

Permalink
[AIRFLOW-2358][AIRFLOW-201804] Make the Kubernetes example optional
Browse files Browse the repository at this point in the history
If you havent installed Kubernetes the initdb
operation will fail

Closes apache#3315 from Fokko/AIRFLOW-2358
  • Loading branch information
Fokko Driesprong authored and bolkedebruin committed May 10, 2018
1 parent 8ed30b1 commit f7c33af
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions airflow/example_dags/example_kubernetes_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,18 @@
# under the License.

import airflow
from airflow.contrib.operators.kubernetes_pod_operator import KubernetesPodOperator
import logging
from airflow.models import DAG

try:
# Kubernetes is optional, so not available in vanilla Airflow
# pip install airflow[gcp]
from airflow.contrib.operators.kubernetes_pod_operator import KubernetesPodOperator
except ImportError:
# Just import the BaseOperator as the KubernetesPodOperator
logging.warn("Could not import KubernetesPodOperator")
from airflow.models import BaseOperator as KubernetesPodOperator

args = {
'owner': 'airflow',
'start_date': airflow.utils.dates.days_ago(2)
Expand All @@ -29,14 +38,14 @@
default_args=args,
schedule_interval=None)

k = KubernetesPodOperator(namespace='default',
image="ubuntu:16.04",
cmds=["bash", "-cx"],
arguments=["echo", "10"],
labels={"foo": "bar"},
name="airflow-test-pod",
in_cluster=False,
task_id="task",
get_logs=True,
dag=dag
)
k = KubernetesPodOperator(
namespace='default',
image="ubuntu:16.04",
cmds=["bash", "-cx"],
arguments=["echo", "10"],
labels={"foo": "bar"},
name="airflow-test-pod",
in_cluster=False,
task_id="task",
get_logs=True,
dag=dag)

0 comments on commit f7c33af

Please sign in to comment.