From 2c5b1c3903aa02abadc0eb457ace15a0d410d153 Mon Sep 17 00:00:00 2001 From: David Ivey Date: Thu, 9 Jan 2025 16:19:18 -0500 Subject: [PATCH] found another issue that ExtensionsV1Api was deprecated and removed in favor of AppsV1Api for deployment operations --- .../kubernetes/modules/kubernetesmod.py | 20 +++++++++---------- tests/unit/modules/test_kubernetesmod.py | 18 ++++++----------- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/saltext/kubernetes/modules/kubernetesmod.py b/src/saltext/kubernetes/modules/kubernetesmod.py index cc4b165..3d28fbe 100644 --- a/src/saltext/kubernetes/modules/kubernetesmod.py +++ b/src/saltext/kubernetes/modules/kubernetesmod.py @@ -444,7 +444,7 @@ def deployments(namespace="default", **kwargs): """ cfg = _setup_conn(**kwargs) try: - api_instance = kubernetes.client.ExtensionsV1Api() + api_instance = kubernetes.client.AppsV1Api() api_response = api_instance.list_namespaced_deployment(namespace) return [dep["metadata"]["name"] for dep in api_response.to_dict().get("items")] @@ -452,7 +452,7 @@ def deployments(namespace="default", **kwargs): if isinstance(exc, ApiException) and exc.status == 404: return None else: - log.exception("Exception when calling ExtensionsV1Api->list_namespaced_deployment") + log.exception("Exception when calling AppsV1Api->list_namespaced_deployment") raise CommandExecutionError(exc) finally: _cleanup(**cfg) @@ -579,7 +579,7 @@ def show_deployment(name, namespace="default", **kwargs): """ cfg = _setup_conn(**kwargs) try: - api_instance = kubernetes.client.ExtensionsV1Api() + api_instance = kubernetes.client.AppsV1Api() api_response = api_instance.read_namespaced_deployment(name, namespace) return api_response.to_dict() @@ -587,7 +587,7 @@ def show_deployment(name, namespace="default", **kwargs): if isinstance(exc, ApiException) and exc.status == 404: return None else: - log.exception("Exception when calling ExtensionsV1Api->read_namespaced_deployment") + log.exception("Exception when calling AppsV1Api->read_namespaced_deployment") raise CommandExecutionError(exc) finally: _cleanup(**cfg) @@ -750,7 +750,7 @@ def delete_deployment(name, namespace="default", **kwargs): body = kubernetes.client.V1DeleteOptions(orphan_dependents=True) try: - api_instance = kubernetes.client.ExtensionsV1Api() + api_instance = kubernetes.client.AppsV1Api() api_response = api_instance.delete_namespaced_deployment( name=name, namespace=namespace, body=body ) @@ -783,7 +783,7 @@ def delete_deployment(name, namespace="default", **kwargs): if isinstance(exc, ApiException) and exc.status == 404: return None else: - log.exception("Exception when calling ExtensionsV1Api->delete_namespaced_deployment") + log.exception("Exception when calling AppsV1Api->delete_namespaced_deployment") raise CommandExecutionError(exc) finally: _cleanup(**cfg) @@ -962,7 +962,7 @@ def create_deployment(name, namespace, metadata, spec, source, template, saltenv cfg = _setup_conn(**kwargs) try: - api_instance = kubernetes.client.ExtensionsV1Api() + api_instance = kubernetes.client.AppsV1Api() api_response = api_instance.create_namespaced_deployment(namespace, body) return api_response.to_dict() @@ -970,7 +970,7 @@ def create_deployment(name, namespace, metadata, spec, source, template, saltenv if isinstance(exc, ApiException) and exc.status == 404: return None else: - log.exception("Exception when calling ExtensionsV1Api->create_namespaced_deployment") + log.exception("Exception when calling AppsV1Api->create_namespaced_deployment") raise CommandExecutionError(exc) finally: _cleanup(**cfg) @@ -1208,7 +1208,7 @@ def replace_deployment( cfg = _setup_conn(**kwargs) try: - api_instance = kubernetes.client.ExtensionsV1Api() + api_instance = kubernetes.client.AppsV1Api() api_response = api_instance.replace_namespaced_deployment(name, namespace, body) return api_response.to_dict() @@ -1216,7 +1216,7 @@ def replace_deployment( if isinstance(exc, ApiException) and exc.status == 404: return None else: - log.exception("Exception when calling ExtensionsV1Api->replace_namespaced_deployment") + log.exception("Exception when calling AppsV1Api->replace_namespaced_deployment") raise CommandExecutionError(exc) finally: _cleanup(**cfg) diff --git a/tests/unit/modules/test_kubernetesmod.py b/tests/unit/modules/test_kubernetesmod.py index 4364305..280f903 100644 --- a/tests/unit/modules/test_kubernetesmod.py +++ b/tests/unit/modules/test_kubernetesmod.py @@ -74,7 +74,7 @@ def test_deployments(): :return: """ with mock_kubernetes_library() as mock_kubernetes_lib: - mock_kubernetes_lib.client.ExtensionsV1Api.return_value = Mock( + mock_kubernetes_lib.client.AppsV1Api.return_value = Mock( **{ "list_namespaced_deployment.return_value.to_dict.return_value": { "items": [{"metadata": {"name": "mock_deployment_name"}}] @@ -83,11 +83,7 @@ def test_deployments(): ) assert kubernetes.deployments() == ["mock_deployment_name"] # py#int: disable=E1120 - assert ( - kubernetes.kubernetes.client.ExtensionsV1Api() - .list_namespaced_deployment() - .to_dict.called - ) + assert kubernetes.kubernetes.client.AppsV1Api().list_namespaced_deployment().to_dict.called def test_services(): @@ -134,12 +130,12 @@ def test_delete_deployments(): "saltext.kubernetes.modules.kubernetesmod.show_deployment", Mock(return_value=None) ): mock_kubernetes_lib.client.V1DeleteOptions = Mock(return_value="") - mock_kubernetes_lib.client.ExtensionsV1Api.return_value = Mock( + mock_kubernetes_lib.client.AppsV1Api.return_value = Mock( **{"delete_namespaced_deployment.return_value.to_dict.return_value": {"code": ""}} ) assert kubernetes.delete_deployment("test") == {"code": 200} assert ( - kubernetes.kubernetes.client.ExtensionsV1Api() + kubernetes.kubernetes.client.AppsV1Api() .delete_namespaced_deployment() .to_dict.called ) @@ -151,14 +147,12 @@ def test_create_deployments(): :return: """ with mock_kubernetes_library() as mock_kubernetes_lib: - mock_kubernetes_lib.client.ExtensionsV1Api.return_value = Mock( + mock_kubernetes_lib.client.AppsV1Api.return_value = Mock( **{"create_namespaced_deployment.return_value.to_dict.return_value": {}} ) assert kubernetes.create_deployment("test", "default", {}, {}, None, None, None) == {} assert ( - kubernetes.kubernetes.client.ExtensionsV1Api() - .create_namespaced_deployment() - .to_dict.called + kubernetes.kubernetes.client.AppsV1Api().create_namespaced_deployment().to_dict.called )