Skip to content

Commit e272e2c

Browse files
authored
fix: handle ContentTypeError in dynamic client discovery (#368)
* 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 * #368 - handle ContentTypeError in dynamic client discovery Fix import sorting * #368 - handle ContentTypeError in dynamic client discovery Fix import sorting
1 parent 83185db commit e272e2c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

kubernetes_asyncio/dynamic/discovery.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from functools import partial
2323
from typing import Dict
2424

25+
from aiohttp.client_exceptions import ContentTypeError
2526
from urllib3.exceptions import MaxRetryError, ProtocolError
2627

2728
from kubernetes_asyncio import __version__
@@ -183,7 +184,9 @@ async def get_resources_for_api_version(self, prefix, group, version, preferred)
183184
try:
184185
response = await self.client.request('GET', path)
185186
resources_response = response.resources or []
186-
except ServiceUnavailableError:
187+
except (ServiceUnavailableError, ContentTypeError):
188+
# Handle both service unavailable errors and content type errors
189+
# (e.g., when server returns 503 with text/plain)
187190
resources_response = []
188191

189192
resources_raw = list(filter(lambda r: '/' not in r['name'], resources_response))

0 commit comments

Comments
 (0)