From 5d76ea158b5db1c81cd589b49721ad20b1b7f669 Mon Sep 17 00:00:00 2001 From: Max Falk Date: Wed, 26 Jul 2023 18:21:14 +0200 Subject: [PATCH 1/6] CLUSTERMAN-812: upgrade k8s client library Signed-off-by: Max Falk --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 8e4359b62..e0308153d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,7 +16,7 @@ idna==2.8 jmespath==0.9.4 jsonpickle==1.4.2 kiwisolver==1.1.0 -kubernetes==10.0.1 +kubernetes==24.2.0 matplotlib==3.4.2 mypy-extensions==0.4.3 numpy==1.21.6 From 086b29d5bbd1222421b741db9ac06a7abecaa05f Mon Sep 17 00:00:00 2001 From: Max Falk Date: Thu, 27 Jul 2023 09:33:12 +0200 Subject: [PATCH 2/6] use 23 instead of 24 because of v1beta1 policy removal Signed-off-by: Max Falk --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index e0308153d..dbac8f8df 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,7 +16,7 @@ idna==2.8 jmespath==0.9.4 jsonpickle==1.4.2 kiwisolver==1.1.0 -kubernetes==24.2.0 +kubernetes==23.6.0 matplotlib==3.4.2 mypy-extensions==0.4.3 numpy==1.21.6 From a7243c234e9795685337005529866ec8c131ac65 Mon Sep 17 00:00:00 2001 From: Max Falk Date: Thu, 27 Jul 2023 09:55:39 +0200 Subject: [PATCH 3/6] use v1 eviction available in k8s 1.22 Signed-off-by: Max Falk --- clusterman/kubernetes/kubernetes_cluster_connector.py | 4 ++-- requirements.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clusterman/kubernetes/kubernetes_cluster_connector.py b/clusterman/kubernetes/kubernetes_cluster_connector.py index b03fc948d..8393d86fe 100644 --- a/clusterman/kubernetes/kubernetes_cluster_connector.py +++ b/clusterman/kubernetes/kubernetes_cluster_connector.py @@ -24,7 +24,7 @@ import colorlog import kubernetes import staticconf -from kubernetes.client import V1beta1Eviction +from kubernetes.client import V1Eviction from kubernetes.client import V1DeleteOptions from kubernetes.client import V1ObjectMeta from kubernetes.client.models.v1_node import V1Node as KubernetesNode @@ -356,7 +356,7 @@ def _evict_pod(self, pod: KubernetesPod): self._core_api.create_namespaced_pod_eviction( name=pod.metadata.name, namespace=pod.metadata.namespace, - body=V1beta1Eviction( + body=V1Eviction( metadata=V1ObjectMeta( name=pod.metadata.name, namespace=pod.metadata.namespace, diff --git a/requirements.txt b/requirements.txt index dbac8f8df..e0308153d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,7 +16,7 @@ idna==2.8 jmespath==0.9.4 jsonpickle==1.4.2 kiwisolver==1.1.0 -kubernetes==23.6.0 +kubernetes==24.2.0 matplotlib==3.4.2 mypy-extensions==0.4.3 numpy==1.21.6 From 8b28315a3aa3c0768f6b743a40efaddd4593a431 Mon Sep 17 00:00:00 2001 From: Max Falk Date: Thu, 27 Jul 2023 11:42:11 +0200 Subject: [PATCH 4/6] reorder imports Signed-off-by: Max Falk --- clusterman/kubernetes/kubernetes_cluster_connector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clusterman/kubernetes/kubernetes_cluster_connector.py b/clusterman/kubernetes/kubernetes_cluster_connector.py index 8393d86fe..4a4c3dfd1 100644 --- a/clusterman/kubernetes/kubernetes_cluster_connector.py +++ b/clusterman/kubernetes/kubernetes_cluster_connector.py @@ -24,8 +24,8 @@ import colorlog import kubernetes import staticconf -from kubernetes.client import V1Eviction from kubernetes.client import V1DeleteOptions +from kubernetes.client import V1Eviction from kubernetes.client import V1ObjectMeta from kubernetes.client.models.v1_node import V1Node as KubernetesNode from kubernetes.client.models.v1_pod import V1Pod as KubernetesPod From 998f67db3b5aaf33fc3ae7df7f0792f1b514eb3e Mon Sep 17 00:00:00 2001 From: Max Falk Date: Thu, 17 Aug 2023 10:48:43 +0200 Subject: [PATCH 5/6] catch ConfigException Signed-off-by: Max Falk --- clusterman/kubernetes/util.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clusterman/kubernetes/util.py b/clusterman/kubernetes/util.py index 0e9253a5f..4fed406b7 100644 --- a/clusterman/kubernetes/util.py +++ b/clusterman/kubernetes/util.py @@ -30,6 +30,7 @@ from kubernetes.client.models.v1_node_selector_requirement import V1NodeSelectorRequirement from kubernetes.client.models.v1_node_selector_term import V1NodeSelectorTerm from kubernetes.client.models.v1_pod import V1Pod as KubernetesPod +from kubernetes.config.config_exception import ConfigException from clusterman.util import ClustermanResources @@ -72,7 +73,7 @@ def __init__(self, kubeconfig_path: str, client_class: Type) -> None: kubernetes.config.load_incluster_config() else: kubernetes.config.load_kube_config(kubeconfig_path, context=os.getenv("KUBECONTEXT")) - except TypeError: + except (TypeError, ConfigException): error_msg = "Could not load KUBECONFIG; is this running on Kubernetes master?" if "yelpcorp" in socket.getfqdn(): error_msg += "\nHint: try using the clusterman-k8s- wrapper script!" From b451d740b82c48c3b9d996e45c71725f18e17a4e Mon Sep 17 00:00:00 2001 From: Max Falk Date: Thu, 17 Aug 2023 11:19:30 +0200 Subject: [PATCH 6/6] raise ConfigException Signed-off-by: Max Falk --- tests/kubernetes/util_test.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/kubernetes/util_test.py b/tests/kubernetes/util_test.py index 3316a4660..92942f9ac 100644 --- a/tests/kubernetes/util_test.py +++ b/tests/kubernetes/util_test.py @@ -5,6 +5,7 @@ import pytest from kubernetes.client.models.v1_node_selector_requirement import V1NodeSelectorRequirement from kubernetes.client.models.v1_node_selector_term import V1NodeSelectorTerm +from kubernetes.config import ConfigException from clusterman.kubernetes.util import CachedCoreV1Api from clusterman.kubernetes.util import ConciseCRDApi @@ -21,7 +22,7 @@ def mock_cached_core_v1_api(): def test_cached_corev1_api_no_kubeconfig(caplog): - with pytest.raises(TypeError): + with pytest.raises(ConfigException): CachedCoreV1Api("/foo/bar/admin.conf") assert "Could not load KUBECONFIG" in caplog.text