Skip to content

Commit

Permalink
Makes Multus lib return False on error 401 instead of raising an exce…
Browse files Browse the repository at this point in the history
…ption
  • Loading branch information
Gmerold committed Dec 9, 2024
1 parent 3d91245 commit 32425e6
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/charms/kubernetes_charm_libraries/v0/multus.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def network_attachment_definition_is_created(
)
return False
except httpx.HTTPStatusError as e:
if e.response.status_code in [401, 404]:
if e.response.status_code == 404:
raise KubernetesMultusError(
"NetworkAttachmentDefinition resource not found. "
"You may need to install Multus CNI."
Expand Down Expand Up @@ -573,8 +573,18 @@ def multus_is_available(self) -> bool:
res=NetworkAttachmentDefinition, namespace=self.namespace
)
)
except ApiError as e:
if e.status.reason == "NotFound":
logger.debug("NetworkAttachmentDefinition resource not found")
elif e.status.reason == "Unauthorized":
logger.debug("kube-apiserver not ready yet")
else:
raise KubernetesMultusError(
"Unexpected outcome when checking for Multus availability"
)
return False
except httpx.HTTPStatusError as e:
if e.response.status_code in [401, 404]:
if e.response.status_code == 404:
return False
else:
raise KubernetesMultusError(
Expand Down

0 comments on commit 32425e6

Please sign in to comment.