airflow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bo...@apache.org
Subject incubator-airflow git commit: [AIRFLOW-2358][AIRFLOW-201804] Make the Kubernetes example optional
Date Thu, 10 May 2018 08:33:38 GMT
Repository: incubator-airflow
Updated Branches:
  refs/heads/master 8ed30b1f0 -> f7c33afea


[AIRFLOW-2358][AIRFLOW-201804] Make the Kubernetes example optional

If you havent installed Kubernetes the initdb
operation will fail

Closes #3315 from Fokko/AIRFLOW-2358


Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/f7c33afe
Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/f7c33afe
Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/f7c33afe

Branch: refs/heads/master
Commit: f7c33afea65a65017a2470dc1444f99900ddf6e3
Parents: 8ed30b1
Author: Fokko Driesprong <fokkodriesprong@godatadriven.com>
Authored: Thu May 10 10:33:32 2018 +0200
Committer: Bolke de Bruin <bolke@xs4all.nl>
Committed: Thu May 10 10:33:32 2018 +0200

----------------------------------------------------------------------
 .../example_dags/example_kubernetes_operator.py | 33 +++++++++++++-------
 1 file changed, 21 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/f7c33afe/airflow/example_dags/example_kubernetes_operator.py
----------------------------------------------------------------------
diff --git a/airflow/example_dags/example_kubernetes_operator.py b/airflow/example_dags/example_kubernetes_operator.py
index 9b86321..a7013ec 100644
--- a/airflow/example_dags/example_kubernetes_operator.py
+++ b/airflow/example_dags/example_kubernetes_operator.py
@@ -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)
@@ -29,14 +38,14 @@ dag = DAG(
     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)


Mime
View raw message