Skip to content

Commit

Permalink
Merge pull request #837 from josefhandl/kubeapi_exception_handling
Browse files Browse the repository at this point in the history
Improve exception handling for listing Kubernetes resources
  • Loading branch information
yuvipanda authored Jun 10, 2024
2 parents b9368d2 + 4fcd345 commit 25928f8
Showing 1 changed file with 17 additions and 2 deletions.
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

0 comments on commit 25928f8

Please sign in to comment.