jedcunningham commented on code in PR #31187:
URL: https://github.com/apache/airflow/pull/31187#discussion_r1190332690


##########
airflow/providers/cncf/kubernetes/hooks/kubernetes.py:
##########
@@ -141,6 +142,22 @@ def _coalesce_param(*params):
             if param is not None:
                 return param
 
+    @classmethod
+    def get_connection(cls, conn_id: str) -> Connection:
+        """
+        Return requested connection.
+
+        If missing and conn_id is "kubernetes_default", will return empty 
connection so that hook will
+        default to cluster-derived credentials.
+        """
+        try:
+            return super().get_connection(conn_id)
+        except AirflowNotFoundException as e:
+            if conn_id == cls.default_conn_name:
+                return Connection(conn_id=cls.default_conn_name)
+            else:
+                raise e

Review Comment:
   ```suggestion
           except AirflowNotFoundException:
               if conn_id == cls.default_conn_name:
                   return Connection(conn_id=cls.default_conn_name)
               else:
                   raise
   ```
   
   This is better as it doesn't add the raise line in the except block into the 
traceback.



##########
tests/providers/cncf/kubernetes/hooks/test_kubernetes.py:
##########
@@ -391,6 +410,20 @@ def test_prefixed_names_still_work(self, mock_get_client):
             mock_get_client.assert_called_with(cluster_context="test")
             assert kubernetes_hook.get_namespace() == "test"
 
+    def test_missing_default_connection_is_ok(self, remove_default_conn):
+        # prove to ourselves that the default conn no exist

Review Comment:
   ```suggestion
           # prove to ourselves that the default conn doesn't exist
   ```



##########
tests/providers/cncf/kubernetes/hooks/test_kubernetes.py:
##########
@@ -391,6 +410,20 @@ def test_prefixed_names_still_work(self, mock_get_client):
             mock_get_client.assert_called_with(cluster_context="test")
             assert kubernetes_hook.get_namespace() == "test"
 
+    def test_missing_default_connection_is_ok(self, remove_default_conn):
+        # prove to ourselves that the default conn no exist
+        with pytest.raises(AirflowNotFoundException):
+            BaseHook.get_connection(DEFAULT_CONN_ID)
+
+        # verify K8sHook still works
+        hook = KubernetesHook()
+        assert hook.conn_extras == {}
+
+        # meanwhile, asking for non-default should still fail if no exist

Review Comment:
   ```suggestion
           # meanwhile, asking for non-default should still fail if it doesn't 
exist
   ```



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

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to