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 2021/12/01 20:36:48 UTC

[GitHub] [airflow] jedcunningham commented on a change in pull request #19695: Add config and context params to KubernetesHook

jedcunningham commented on a change in pull request #19695:
URL: https://github.com/apache/airflow/pull/19695#discussion_r760550800



##########
File path: airflow/providers/cncf/kubernetes/hooks/kubernetes.py
##########
@@ -96,25 +99,49 @@ def get_ui_field_behaviour() -> Dict:
         }
 
     def __init__(
-        self, conn_id: str = default_conn_name, client_configuration: Optional[client.Configuration] = None
+        self,
+        conn_id: Optional[str] = default_conn_name,
+        client_configuration: Optional[client.Configuration] = None,
+        cluster_context: Optional[str] = None,
+        config_file: Optional[str] = None,
+        in_cluster: Optional[bool] = None,
     ) -> None:
         super().__init__()
         self.conn_id = conn_id
         self.client_configuration = client_configuration
+        self.cluster_context = cluster_context
+        self.config_file = config_file
+        self.in_cluster = in_cluster
+
+    @staticmethod
+    def _coalesce_param(*params):
+        for param in params:
+            if param is not None:
+                return param
 
     def get_conn(self) -> Any:
         """Returns kubernetes api session for use with requests"""
-        connection = self.get_connection(self.conn_id)
-        extras = connection.extra_dejson
-        in_cluster = extras.get("extra__kubernetes__in_cluster") or None
-        kubeconfig_path = extras.get("extra__kubernetes__kube_config_path") or None
+        if self.conn_id:
+            connection = self.get_connection(self.conn_id)
+            extras = connection.extra_dejson
+        else:
+            extras = {}
+        in_cluster = self._coalesce_param(
+            self.in_cluster, extras.get("extra__kubernetes__in_cluster") or None
+        )

Review comment:
       ```suggestion
           in_cluster = self.in_cluster or extras.get("extra__kubernetes__in_cluster")
   ```
   
   Is checking against an explicit None required, or can we just be truthy? Wanting to use a falsy value seems pretty unlikely, no?

##########
File path: airflow/providers/cncf/kubernetes/hooks/kubernetes.py
##########
@@ -209,10 +247,11 @@ def get_custom_object(
 
     def get_namespace(self) -> str:

Review comment:
       ```suggestion
       def get_namespace(self) -> Optional[str]:
   ```
   
   Or, should this just return `default` if a connection isn't set?




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

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org