This is an automated email from the ASF dual-hosted git repository.

husseinawala 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 adf0cae48a Use kube_client over default CoreV1Api for deleting pods 
(#31477)
adf0cae48a is described below

commit adf0cae48ad4e87612c00fe9facffca9b5728e7d
Author: Louis Mackie <[email protected]>
AuthorDate: Wed May 24 10:45:55 2023 +0100

    Use kube_client over default CoreV1Api for deleting pods (#31477)
---
 airflow/cli/commands/kubernetes_command.py    | 4 ++--
 tests/cli/commands/test_kubernetes_command.py | 4 +++-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/airflow/cli/commands/kubernetes_command.py 
b/airflow/cli/commands/kubernetes_command.py
index efdcd6aec6..25cfecc2b4 100644
--- a/airflow/cli/commands/kubernetes_command.py
+++ b/airflow/cli/commands/kubernetes_command.py
@@ -148,8 +148,8 @@ def cleanup_pods(args):
 
 def _delete_pod(name, namespace):
     """Helper Function for cleanup_pods."""
-    core_v1 = client.CoreV1Api()
+    kube_client = get_kube_client()
     delete_options = client.V1DeleteOptions()
     print(f'Deleting POD "{name}" from "{namespace}" namespace')
-    api_response = core_v1.delete_namespaced_pod(name=name, 
namespace=namespace, body=delete_options)
+    api_response = kube_client.delete_namespaced_pod(name=name, 
namespace=namespace, body=delete_options)
     print(api_response)
diff --git a/tests/cli/commands/test_kubernetes_command.py 
b/tests/cli/commands/test_kubernetes_command.py
index da054ea554..eb75f56533 100644
--- a/tests/cli/commands/test_kubernetes_command.py
+++ b/tests/cli/commands/test_kubernetes_command.py
@@ -64,9 +64,11 @@ class TestCleanUpPodsCommand:
         cls.parser = cli_parser.get_parser()
 
     @mock.patch("kubernetes.client.CoreV1Api.delete_namespaced_pod")
-    def test_delete_pod(self, delete_namespaced_pod):
+    @mock.patch("airflow.kubernetes.kube_client.config.load_incluster_config")
+    def test_delete_pod(self, load_incluster_config, delete_namespaced_pod):
         kubernetes_command._delete_pod("dummy", "awesome-namespace")
         delete_namespaced_pod.assert_called_with(body=mock.ANY, name="dummy", 
namespace="awesome-namespace")
+        load_incluster_config.assert_called_once()
 
     @mock.patch("airflow.cli.commands.kubernetes_command._delete_pod")
     @mock.patch("kubernetes.client.CoreV1Api.list_namespaced_pod")

Reply via email to