You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/01/14 18:54:09 UTC

[GitHub] [airflow] roitvt commented on a change in pull request #7163: [AIRFLOW-6542] add spark-on-k8s operator/hook/sensor

roitvt commented on a change in pull request #7163: [AIRFLOW-6542] add spark-on-k8s operator/hook/sensor
URL: https://github.com/apache/airflow/pull/7163#discussion_r366513445
 
 

 ##########
 File path: airflow/contrib/operators/spark_kubernetes_operator.py
 ##########
 @@ -0,0 +1,77 @@
+# -*- coding: utf-8 -*-
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from typing import Optional
+
+from kubernetes import client
+
+from airflow.contrib.hooks.kubernetes_hook import Kuberneteshook
+from airflow.exceptions import AirflowException
+from airflow.models import BaseOperator
+from airflow.utils.decorators import apply_defaults
+
+
+class SparkKubernetesOperator(BaseOperator):
+    """
+    creates sparkapplication object in kubernetes cluster
+
+    :param sparkapplication_object: kubernetes custom_resource_definition of sparkApplication
+    :param namespace: kubernetes namespace to put sparkApplication
+    :param kube_config: kubernetes kube_config path
+    :param in_cluster: if airflow runs inside kubernetes pod take configuration from inside the cluster.
+    """
+
+    template_fields = ['sparkapplication_object', 'namespace', 'kube_config']
+    template_ext = ()
+    ui_color = '#f4a460'
+
+    @apply_defaults
+    def __init__(self,
+                 sparkapplication_object: dict,
+                 namespace: str = 'default',
+                 kube_config: Optional[str] = None,
+                 in_cluster: bool = False,
+                 *args, **kwargs) -> None:
+        super().__init__(*args, **kwargs)
+        self.sparkapplication_object = sparkapplication_object
+        self.namespace = namespace
+        self.kube_config = kube_config
+        self.in_cluster = in_cluster
+        if kwargs.get('xcom_push') is not None:
+            raise AirflowException("'xcom_push' was deprecated, use 'BaseOperator.do_xcom_push' instead")
+
+    def execute(self, context):
+        self.log.info("creating sparkApplication")
+        hook = Kuberneteshook(
+            kube_config=self.kube_config,
+            in_cluster=self.in_cluster
+        )
+        api_client = hook.get_conn()
+        api = client.CustomObjectsApi(api_client)
 
 Review comment:
   the hook is creating the connection, the operator asks for the customObjectsApi if I need to do it in the hook I need to write code for each Kubernetes API object. I tried to make the Kubernetes hook general for various uses not just custom object api

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services