From e4ff815fb4449b6fae030bbd3ce7916dd4fa912c Mon Sep 17 00:00:00 2001 From: tamil vanan Date: Thu, 31 Jul 2025 16:47:05 +0000 Subject: [PATCH 1/3] fix: handle ContentTypeError in dynamic client discovery When the Kubernetes API server returns a 503 Service Unavailable with text/plain content type instead of JSON, the dynamic client was failing with a ContentTypeError while trying to parse the response. This fix catches ContentTypeError in the get_resources_for_api_version method and handles it the same way as ServiceUnavailableError, allowing the client to gracefully continue with an empty resources list. This resolves issues when accessing certain API endpoints that may temporarily return non-JSON responses during service unavailability --- kubernetes_asyncio/dynamic/discovery.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kubernetes_asyncio/dynamic/discovery.py b/kubernetes_asyncio/dynamic/discovery.py index ae616270..8fdb2b41 100644 --- a/kubernetes_asyncio/dynamic/discovery.py +++ b/kubernetes_asyncio/dynamic/discovery.py @@ -23,6 +23,7 @@ from typing import Dict from urllib3.exceptions import MaxRetryError, ProtocolError +from aiohttp.client_exceptions import ContentTypeError from kubernetes_asyncio import __version__ @@ -183,7 +184,9 @@ async def get_resources_for_api_version(self, prefix, group, version, preferred) try: response = await self.client.request('GET', path) resources_response = response.resources or [] - except ServiceUnavailableError: + except (ServiceUnavailableError, ContentTypeError): + # Handle both service unavailable errors and content type errors + # (e.g., when server returns 503 with text/plain) resources_response = [] resources_raw = list(filter(lambda r: '/' not in r['name'], resources_response)) From 54221a5481240564710698a6bc495e578b8f0d53 Mon Sep 17 00:00:00 2001 From: tamil vanan Date: Tue, 5 Aug 2025 11:20:03 +0530 Subject: [PATCH 2/3] #368 - handle ContentTypeError in dynamic client discovery Fix import sorting --- kubernetes_asyncio/dynamic/discovery.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kubernetes_asyncio/dynamic/discovery.py b/kubernetes_asyncio/dynamic/discovery.py index 8fdb2b41..ec8ac6aa 100644 --- a/kubernetes_asyncio/dynamic/discovery.py +++ b/kubernetes_asyncio/dynamic/discovery.py @@ -22,8 +22,9 @@ from functools import partial from typing import Dict -from urllib3.exceptions import MaxRetryError, ProtocolError from aiohttp.client_exceptions import ContentTypeError +from urllib3.exceptions import MaxRetryError, ProtocolError + from kubernetes_asyncio import __version__ From d55f3a205b624287fe2d305a75db992351ee5a6f Mon Sep 17 00:00:00 2001 From: tamil vanan Date: Tue, 5 Aug 2025 11:32:28 +0530 Subject: [PATCH 3/3] #368 - handle ContentTypeError in dynamic client discovery Fix import sorting --- kubernetes_asyncio/dynamic/discovery.py | 1 - 1 file changed, 1 deletion(-) diff --git a/kubernetes_asyncio/dynamic/discovery.py b/kubernetes_asyncio/dynamic/discovery.py index ec8ac6aa..3f22aba9 100644 --- a/kubernetes_asyncio/dynamic/discovery.py +++ b/kubernetes_asyncio/dynamic/discovery.py @@ -25,7 +25,6 @@ from aiohttp.client_exceptions import ContentTypeError from urllib3.exceptions import MaxRetryError, ProtocolError - from kubernetes_asyncio import __version__ from .exceptions import (