Skip to content

Commit 40fbaea

Browse files
Add debug logging to troubleshoot auth issues (#542)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent dc7a159 commit 40fbaea

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

kr8s/_api.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ async def call_api(
171171
# If we get a 401 or 403 our credentials may have expired so we
172172
# reauthenticate and try again a few times before giving up.
173173
if e.response.status_code in (401, 403) and auth_attempts < 3:
174+
logger.debug(
175+
f"Unauthorized {e.response.status_code} error, reauthenticating attempt {auth_attempts}"
176+
)
174177
auth_attempts += 1
175178
await self.auth.reauthenticate()
176179
await self._create_session()

kr8s/_auth.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import base64
44
import ipaddress
55
import json
6+
import logging
67
import os
78
import pathlib
89
import ssl
@@ -14,6 +15,8 @@
1415
from ._config import KubeConfigSet
1516
from ._types import PathType
1617

18+
logger = logging.getLogger(__name__)
19+
1720

1821
class KubeAuth:
1922
"""Load kubernetes auth from kubeconfig, service account, or url."""
@@ -69,6 +72,7 @@ async def reauthenticate(self) -> None:
6972
"""Reauthenticate with the server."""
7073
async with self.__auth_lock:
7174
if self._url:
75+
logger.debug("URL specified manually")
7276
self.server = self._url
7377
else:
7478
if self._kubeconfig_path_or_dict is not False:
@@ -110,6 +114,7 @@ def namespace(self, value: str):
110114

111115
async def _load_kubeconfig(self) -> None:
112116
"""Load kubernetes auth from kubeconfig."""
117+
logger.debug("Loading kubeconfig")
113118
if isinstance(self._kubeconfig_path_or_dict, str) or isinstance(
114119
self._kubeconfig_path_or_dict, pathlib.Path
115120
):
@@ -254,6 +259,7 @@ async def _load_kubeconfig(self) -> None:
254259

255260
async def _load_service_account(self) -> None:
256261
"""Load credentials from service account."""
262+
logger.debug("Loading service account")
257263
self._serviceaccount = os.path.expanduser(self._serviceaccount)
258264
if not os.path.isdir(self._serviceaccount):
259265
return

0 commit comments

Comments
 (0)