mik-laj 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_r371031062
 
 

 ##########
 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:
   I think that it is worth giving the option to configure namespace both via 
the operator and via the connection. Look here: 
https://github.com/apache/airflow/blob/43dcc13/airflow/gcp/hooks/base.py#L332-L358
   
   Namespace is not something that is created by the individual Airflow user. 
Namespace should be defined at the organization-level. The organization 
determines which servers it wants to connect to. The operator should specify 
only operational parameters. Sometimes using a different namespace can also be 
an operational activity if DAG performs organization-level activities. But the 
most common cases are the namespace allocation by a specific cluster 
administrator. 

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to