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

fix: Fixes Unauthorized error when listing K8s nodes #458

Merged
merged 1 commit into from
Jan 10, 2025
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
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 @@ -1112,10 +1113,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
Loading