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/02/16 17:01:43 UTC

[GitHub] [airflow] nuclearpinguin commented on a change in pull request #7431: [AIRFLOW-6808]: Add GCP GKE Operators and Hooks

nuclearpinguin commented on a change in pull request #7431: [AIRFLOW-6808]: Add GCP GKE Operators and Hooks
URL: https://github.com/apache/airflow/pull/7431#discussion_r379917559
 
 

 ##########
 File path: airflow/providers/google/cloud/hooks/container.py
 ##########
 @@ -0,0 +1,191 @@
+#
+# 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 google.api_core.gapic_v1.method import DEFAULT
+from google.cloud import container_v1
+from google.cloud.container_v1.gapic.enums import Operation
+
+from airflow.providers.google.cloud.hooks.base import CloudBaseHook
+
+
+class ContainerHook(CloudBaseHook):
+    def __init__(self, gcp_conn_id='google_cloud_default', delegates_to=None):
+        super().__init__(gcp_conn_id, delegates_to)
+        self._client = None
+        self._operation_completion_status = [
+            Operation.Status.DONE
+        ]
+
+    def _get_client(self):
+        if not self._client:
+            self._client = container_v1.ClusterManagerClient()
+        return self._client
+
+    @CloudBaseHook.fallback_to_default_project_id
+    def _wait_for_operation_complete(
+        self,
+        operation,
+        project_id=None
+    ):
+        client = self._get_client()
+        if operation is not None:
+            operation_id = operation.name
+            operation_zone = operation.zone
+            operation_status = operation.status
+            while operation_status not in self._operation_completion_status:
+                op = client.get_operation(
+                    project_id=project_id,
+                    zone=operation_zone,
+                    operation_id=operation_id,
+                )
+                operation_status = op.status
+
+    @CloudBaseHook.fallback_to_default_project_id
+    def create_gke_cluster(
 
 Review comment:
   I thought that we already have GKE hook:
   https://github.com/apache/airflow/blob/cec9249f904bd91be9cb5a6be7e04979585da12e/airflow/providers/google/cloud/hooks/kubernetes_engine.py#L187-L194
   
   Maybe it's worth to refactor existing code?

----------------------------------------------------------------
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