Skip to content

Commit

Permalink
fix: Fixes Unauthorized error when listing K8s nodes (#459)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gmerold authored Jan 14, 2025
1 parent 65f1b36 commit e7a8645
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from charms.sdcore_upf_k8s.v0.fiveg_n4 import N4Provides
from jinja2 import Environment, FileSystemLoader
from lightkube.core.client import Client
from lightkube.core.exceptions import ApiError
from lightkube.models.meta_v1 import ObjectMeta
from lightkube.resources.core_v1 import Node, Pod
from ops import (
Expand Down Expand Up @@ -1111,10 +1112,17 @@ def _hugepages_are_available(self) -> bool:
Returns:
bool: Whether HugePages are available in the K8S nodes
"""
client = Client()
nodes = client.list(Node)
if not self._hugepages_is_enabled():
return True
client = Client()
try:
nodes = client.list(Node)
except ApiError as e:
if e.status.reason == "Unauthorized":
logger.debug("kube-apiserver not ready yet")
return False
else:
raise e
if not nodes:
return False
return all(node.status.allocatable.get("hugepages-1Gi", "0") >= "2Gi" for node in nodes) # type: ignore
Expand Down

0 comments on commit e7a8645

Please sign in to comment.