Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve exception handling for listing Kubernetes resources #837

Merged
merged 4 commits into from
Jun 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions kubespawner/reflector.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import time
from functools import partial

from kubernetes_asyncio import watch
from kubernetes_asyncio import client, watch
from traitlets import Any, Bool, Dict, Int, Unicode
from traitlets.config import LoggingConfigurable
from urllib3.exceptions import ReadTimeoutError
Expand Down Expand Up @@ -228,7 +228,22 @@ async def _list_and_update(self, resource_version=None):
kwargs["namespace"] = self.namespace

list_method = getattr(self.api, self.list_method_name)
initial_resources_raw = await list_method(**kwargs)

try:
initial_resources_raw = await list_method(**kwargs)
if not initial_resources_raw.ok:
raise client.ApiException(
status=initial_resources_raw.status,
reason=initial_resources_raw.reason,
)
except client.ApiException:
self.log.exception(
f'An error occurred when calling Kubernetes API.'
f' Status: {initial_resources_raw.status} {initial_resources_raw.reason}.'
f' Message: {(await initial_resources_raw.json())["message"]}'
)
raise

# This is an atomic operation on the dictionary!
initial_resources = json.loads(await initial_resources_raw.read())
self.resources = {
Expand Down