You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by fo...@apache.org on 2018/06/03 13:29:44 UTC
incubator-airflow git commit: [AIRFLOW-2545] Eliminate
DeprecationWarning
Repository: incubator-airflow
Updated Branches:
refs/heads/master b7dc31510 -> 91dd36866
[AIRFLOW-2545] Eliminate DeprecationWarning
Do not import BaseOperator as KubernetesOperator.
This eliminates confusing DeprecationWarnings when
setting up a default airflow install where
additional
kubernetes modules are not installed.
Also, use LoggingMixin instead of logger module.
Closes #3442 from rodrigc/AIRFLOW-2545
Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/91dd3686
Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/91dd3686
Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/91dd3686
Branch: refs/heads/master
Commit: 91dd3686688dc42372ec5ae7b6efb08e35125b1f
Parents: b7dc315
Author: Craig Rodrigues <ro...@FreeBSD.org>
Authored: Sun Jun 3 15:29:31 2018 +0200
Committer: Fokko Driesprong <fo...@godatadriven.com>
Committed: Sun Jun 3 15:29:31 2018 +0200
----------------------------------------------------------------------
.../example_dags/example_kubernetes_operator.py | 55 +++++++++++---------
1 file changed, 29 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/91dd3686/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 8f5ab39..92d73c5 100644
--- a/airflow/example_dags/example_kubernetes_operator.py
+++ b/airflow/example_dags/example_kubernetes_operator.py
@@ -17,37 +17,40 @@
# specific language governing permissions and limitations
# under the License.
-import airflow
-import logging
+from airflow.utils.dates import days_ago
+from airflow.utils.log.logging_mixin import LoggingMixin
from airflow.models import DAG
+log = LoggingMixin().log
+
try:
# Kubernetes is optional, so not available in vanilla Airflow
- # pip install airflow[gcp]
+ # pip install airflow[kubernetes]
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)
-}
+ args = {
+ 'owner': 'airflow',
+ 'start_date': days_ago(2)
+ }
+
+ dag = DAG(
+ dag_id='example_kubernetes_operator',
+ default_args=args,
+ schedule_interval=None)
-dag = DAG(
- dag_id='example_kubernetes_operator',
- 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)
+except ImportError as e:
+ log.warn("Could not import KubernetesPodOperator: " + str(e))
+ log.warn("Install kubernetes dependencies with: "
+ " pip install airflow['kubernetes']")