From 2699689f4656eef71fd741c0e0f0302080a8fe8b Mon Sep 17 00:00:00 2001 From: Fred L Sharp Date: Mon, 29 Nov 2021 14:23:19 -0600 Subject: [PATCH] Set kubernetes_asyncio back to official package - Update pyproject.toml and poetry.lock - Add k8s connector missing explicit imports, alphabetize - Update KubernetesModel.api_client context manager with default_headers argument - Set default_header content-type = application/merge-patch+json for rollout patch method --- poetry.lock | 10 +++++----- pyproject.toml | 2 +- servo/connectors/kubernetes.py | 9 ++++++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/poetry.lock b/poetry.lock index 9e98dca05..dbfc19475 100644 --- a/poetry.lock +++ b/poetry.lock @@ -750,9 +750,9 @@ websocket-client = ">=0.32.0,<0.40.0 || >0.40.0,<0.41.0 || >=0.43.0" adal = ["adal (>=1.0.2)"] [[package]] -name = "kubernetes-asyncio-cr-patch" +name = "kubernetes-asyncio" version = "12.1.2" -description = "Kubernetes asynchronous python client with patched custom resource API client" +description = "Kubernetes asynchronous python client" category = "main" optional = false python-versions = "*" @@ -1792,7 +1792,7 @@ testing = ["pytest (>=4.6)", "pytest-checkdocs (>=1.2.3)", "pytest-flake8", "pyt [metadata] lock-version = "1.1" python-versions = "^3.8" -content-hash = "9435c07cbd26681bee09e852e566b27c781a9e1b3ff2cfa958342a825104b347" +content-hash = "278f879f7077ccb9bb7ed62655502dd2e010e3ee10c91391043cbc00b418ed9f" [metadata.files] aiohttp = [ @@ -2191,8 +2191,8 @@ kubernetes = [ {file = "kubernetes-17.17.0-py3-none-any.whl", hash = "sha256:225a95a0aadbd5b645ab389d941a7980db8cdad2a776fde64d1b43fc3299bde9"}, {file = "kubernetes-17.17.0.tar.gz", hash = "sha256:c69b318696ba797dcf63eb928a8d4370c52319f4140023c502d7dfdf2080eb79"}, ] -kubernetes-asyncio-cr-patch = [ - {file = "kubernetes_asyncio_cr_patch-12.1.2.tar.gz", hash = "sha256:2e90c73b6cb3678eba397368c001bec27162f90e848aac71b3cfad9a476f938b"}, +kubernetes-asyncio = [ + {file = "kubernetes_asyncio-12.1.2.tar.gz", hash = "sha256:dfff92cbeed37e81b0c94156162841a7a4ef3e95b00d521d50fe86a14f05fbf9"}, ] kubetest = [] loguru = [ diff --git a/pyproject.toml b/pyproject.toml index 6f3789462..764e2802a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,7 +36,7 @@ toml = "^0.10.2" colorama = "^0.4.4" pyfiglet = "^0.8.post1" curlify2 = "^1.0.0" -kubernetes-asyncio-cr-patch = "^12.1.2" +kubernetes_asyncio = "^12.1.2" [tool.poetry.dev-dependencies] pytest = "^6.2.4" diff --git a/servo/connectors/kubernetes.py b/servo/connectors/kubernetes.py index 9a6df3a9c..81e701b81 100644 --- a/servo/connectors/kubernetes.py +++ b/servo/connectors/kubernetes.py @@ -41,9 +41,10 @@ import backoff import kubernetes_asyncio -import kubernetes_asyncio.client.models import kubernetes_asyncio.client +import kubernetes_asyncio.client.api_client import kubernetes_asyncio.client.exceptions +import kubernetes_asyncio.client.models import kubernetes_asyncio.watch import pydantic @@ -304,7 +305,7 @@ def namespace(self, namespace: str): self.obj.metadata.namespace = namespace @contextlib.asynccontextmanager - async def api_client(self) -> Generator[Any, None, None]: + async def api_client(self, default_headers: Dict[str, str] = {}) -> Generator[Any, None, None]: """The API client for the Kubernetes object. This is determined by the ``apiVersion`` of the object configuration. @@ -326,6 +327,8 @@ async def api_client(self) -> Generator[Any, None, None]: ) # If we did find it, initialize that client version. async with kubernetes_asyncio.client.api_client.ApiClient() as api: + for k, v in default_headers.items(): + api.set_default_header(k, v) yield c(api) @classmethod @@ -2384,7 +2387,7 @@ async def read_workfload_ref(self, namespace: str) -> None: async def patch(self) -> None: """Update the changed attributes of the Rollout.""" - async with self.api_client() as api_client: + async with self.api_client({'content-type': 'application/merge-patch+json'}) as api_client: self.obj = RolloutObj.parse_obj(await api_client.patch_namespaced_custom_object( namespace=self.namespace, name=self.name,