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_r371029020
 
 

 ##########
 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:
   now that I added Kubernetes connection type the namespace can be inside the 
connection but that means that I'll need connection for each namespace. my 
point of view is connection per Kubernetes cluster and namespace definition in 
the operator. even if the connection has namespace included I think that the 
operator needs to have the ability to override.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to