Skip to content

Conversation

tamilhce
Copy link
Contributor

fix: handle ContentTypeError in dynamic client discovery

#367

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

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
@tamilhce tamilhce changed the title Master fix: #367 handle ContentTypeError in dynamic client discovery Jul 31, 2025
@tamilhce tamilhce changed the title fix: #367 handle ContentTypeError in dynamic client discovery fix: handle ContentTypeError in dynamic client discovery Jul 31, 2025
@tamilhce
Copy link
Contributor Author

tamilhce commented Aug 4, 2025

Any updates ?

response = await self.client.request('GET', path)
resources_response = response.resources or []
except ServiceUnavailableError:
except (ServiceUnavailableError, ContentTypeError):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for your contribution

@tomplus
Copy link
Owner

tomplus commented Aug 4, 2025

Could you fix order of imports as Flake suggests?

@tamilhce
Copy link
Contributor Author

tamilhce commented Aug 5, 2025

Ack. Fixed the import sorting and verified it locally.

(vpy3.12) v> isort --check --diff discovery.py (vpy3.12) v> 
Copy link

codecov bot commented Aug 5, 2025

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 27.07%. Comparing base (83185db) to head (d55f3a2).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
kubernetes_asyncio/dynamic/discovery.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@ ## master #368 +/- ## ======================================= Coverage 27.07% 27.07% ======================================= Files 805 805 Lines 98735 98736 +1 ======================================= + Hits 26732 26733 +1  Misses 72003 72003 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
@tomplus tomplus merged commit e272e2c into tomplus:master Aug 5, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants