diff --git a/providers/src/airflow/providers/cncf/kubernetes/hooks/kubernetes.py b/providers/src/airflow/providers/cncf/kubernetes/hooks/kubernetes.py index 6a377be3eb27c..1e9f881dd1d70 100644 --- a/providers/src/airflow/providers/cncf/kubernetes/hooks/kubernetes.py +++ b/providers/src/airflow/providers/cncf/kubernetes/hooks/kubernetes.py @@ -754,7 +754,7 @@ async def _load_config(self): if self.config_dict: self.log.debug(LOADING_KUBE_CONFIG_FILE_RESOURCE.format("config dictionary")) self._is_in_cluster = False - await async_config.load_kube_config_from_dict(self.config_dict) + await async_config.load_kube_config_from_dict(self.config_dict, context=cluster_context) return async_client.ApiClient() if kubeconfig is not None: diff --git a/providers/tests/cncf/kubernetes/hooks/test_kubernetes.py b/providers/tests/cncf/kubernetes/hooks/test_kubernetes.py index f55e759acd9ef..f88cba72bef23 100644 --- a/providers/tests/cncf/kubernetes/hooks/test_kubernetes.py +++ b/providers/tests/cncf/kubernetes/hooks/test_kubernetes.py @@ -875,7 +875,29 @@ async def test_load_config_with_config_dict( await hook._load_config() assert not incluster_config.called assert hook._is_in_cluster is False - kube_config_loader.assert_called_once() + kube_config_loader.assert_called_once_with( + config_dict={"a": "b"}, config_base_path=None, active_context=None, temp_file_path=None + ) + + @pytest.mark.asyncio + @mock.patch(INCLUSTER_CONFIG_LOADER) + @mock.patch(KUBE_CONFIG_MERGER) + async def test_load_config_with_config_dict_and_cluster_context( + self, kube_config_merger, incluster_config, kube_config_loader + ): + cluster_context = "some_kubernetes_cluster" + hook = AsyncKubernetesHook( + conn_id=None, + in_cluster=False, + config_dict={"a": "b"}, + cluster_context=cluster_context, + ) + await hook._load_config() + assert not incluster_config.called + assert hook._is_in_cluster is False + kube_config_loader.assert_called_once_with( + config_dict={"a": "b"}, config_base_path=None, active_context=cluster_context, temp_file_path=None + ) @pytest.mark.asyncio @mock.patch(INCLUSTER_CONFIG_LOADER)