This is an automated email from the ASF dual-hosted git repository.
dstandish pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 6808619ec5 KubernetesHook kube_config extra can take dict (#41413)
6808619ec5 is described below
commit 6808619ec5cfe286f9e19cf4d8d21fd2feafbb8a
Author: Daniel Standish <[email protected]>
AuthorDate: Mon Sep 30 08:58:36 2024 -0700
KubernetesHook kube_config extra can take dict (#41413)
Previously had to be json-encoded string which is less convenient when
defining the conn in json.
---------
Co-authored-by: Jed Cunningham
<[email protected]>
---
airflow/providers/cncf/kubernetes/hooks/kubernetes.py | 2 ++
tests/providers/cncf/kubernetes/hooks/test_kubernetes.py | 2 ++
2 files changed, 4 insertions(+)
diff --git a/airflow/providers/cncf/kubernetes/hooks/kubernetes.py
b/airflow/providers/cncf/kubernetes/hooks/kubernetes.py
index 9f7e33696e..a810e8f9ed 100644
--- a/airflow/providers/cncf/kubernetes/hooks/kubernetes.py
+++ b/airflow/providers/cncf/kubernetes/hooks/kubernetes.py
@@ -250,6 +250,8 @@ class KubernetesHook(BaseHook, PodOperatorHookProtocol):
if kubeconfig is not None:
with tempfile.NamedTemporaryFile() as temp_config:
self.log.debug("loading kube_config from: connection
kube_config")
+ if isinstance(kubeconfig, dict):
+ kubeconfig = json.dumps(kubeconfig)
temp_config.write(kubeconfig.encode())
temp_config.flush()
self._is_in_cluster = False
diff --git a/tests/providers/cncf/kubernetes/hooks/test_kubernetes.py
b/tests/providers/cncf/kubernetes/hooks/test_kubernetes.py
index 348974eacd..065768def2 100644
--- a/tests/providers/cncf/kubernetes/hooks/test_kubernetes.py
+++ b/tests/providers/cncf/kubernetes/hooks/test_kubernetes.py
@@ -79,6 +79,7 @@ class TestKubernetesHook:
("in_cluster", {"in_cluster": True}),
("in_cluster_empty", {"in_cluster": ""}),
("kube_config", {"kube_config": '{"test": "kube"}'}),
+ ("kube_config_dict", {"kube_config": {"test": "kube"}}),
("kube_config_path", {"kube_config_path": "path/to/file"}),
("kube_config_empty", {"kube_config": ""}),
("kube_config_path_empty", {"kube_config_path": ""}),
@@ -285,6 +286,7 @@ class TestKubernetesHook:
(
(None, False),
("kube_config", True),
+ ("kube_config_dict", True),
("kube_config_empty", False),
),
)