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 2022/04/20 19:49:22 UTC

[GitHub] [airflow] dstandish commented on a diff in pull request #23126: KubernetesHook should try incluster first when not otherwise configured

dstandish commented on code in PR #23126:
URL: https://github.com/apache/airflow/pull/23126#discussion_r854498399


##########
tests/providers/cncf/kubernetes/hooks/test_kubernetes.py:
##########
@@ -89,15 +92,46 @@ def test_in_cluster_connection(
         Hook param should beat extra.
         """
         kubernetes_hook = KubernetesHook(conn_id=conn_id, in_cluster=in_cluster_param)
+        mock_get_default_client.return_value = kubernetes.client.api_client.ApiClient()
         api_conn = kubernetes_hook.get_conn()
         if in_cluster_called:
             mock_in_cluster_loader.assert_called_once()
             mock_merger.assert_not_called()
             mock_loader.assert_not_called()
         else:
-            mock_in_cluster_loader.assert_not_called()
+            mock_get_default_client.assert_called()
+            # mock_in_cluster_loader.assert_not_called()
+            # mock_merger.assert_called_once_with(KUBE_CONFIG_PATH)
+            # mock_loader.assert_called_once()
+        assert isinstance(api_conn, kubernetes.client.api_client.ApiClient)
+
+    @pytest.mark.parametrize('in_cluster_fails', [True, False])
+    @patch("kubernetes.config.kube_config.KubeConfigLoader")
+    @patch("kubernetes.config.kube_config.KubeConfigMerger")
+    @patch("kubernetes.config.incluster_config.InClusterConfigLoader")
+    def test_get_default_client(
+        self,
+        mock_incluster,
+        mock_merger,
+        mock_loader,
+        in_cluster_fails,
+    ):
+        """
+        Verifies whether in_cluster is called depending on combination of hook param and connection extra.
+        Hook param should beat extra.

Review Comment:
   thanks, fixed



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