Skip to content

Commit

Permalink
Check for allocatable resources instead of capacity
Browse files Browse the repository at this point in the history
  • Loading branch information
dariofaccin committed Dec 12, 2023
1 parent 43067f5 commit 32492f0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,11 +807,16 @@ def _cpu_is_compatible_for_hugepages(self) -> bool:

@staticmethod
def _hugepages_are_available() -> bool:
"""Checks whether HugePages are available in the K8S nodes.
Returns:
bool: Whether HugePages are available in the K8S nodes
"""
client = Client()
nodes = client.list(Node)
if not nodes:
return False
return all([node.status.capacity.get("hugepages-1Gi", "0") >= "2Gi" for node in nodes])
return all([node.status.allocatable.get("hugepages-1Gi", "0") >= "2Gi" for node in nodes])

def _get_access_nad_config(self) -> Dict[Any, Any]:
"""Get access interface NAD config.
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ def test_given_cpu_supporting_required_hugepages_instructions_when_hugepages_ena
):
patch_hugepages_is_patched.return_value = False
patched_check_output.return_value = b"Flags: avx2 ssse3 fma cx16 rdrand pdpe1gb"
patch_list.return_value = [Node(status=NodeStatus(capacity={"hugepages-1Gi": "3Gi"}))]
patch_list.return_value = [Node(status=NodeStatus(allocatable={"hugepages-1Gi": "3Gi"}))]

self.harness.update_config(key_values={"enable-hugepages": True})

Expand All @@ -806,7 +806,7 @@ def test_given_cpu_supporting_required_hugepages_instructions_and_not_available_
):
patch_hugepages_is_patched.return_value = False
patched_check_output.return_value = b"Flags: avx2 ssse3 fma cx16 rdrand pdpe1gb"
patch_list.return_value = [Node(status=NodeStatus(capacity={"hugepages-1Gi": "1Gi"}))]
patch_list.return_value = [Node(status=NodeStatus(allocatable={"hugepages-1Gi": "1Gi"}))]

self.harness.update_config(key_values={"enable-hugepages": True})

Expand Down

0 comments on commit 32492f0

Please sign in to comment.