Skip to content

Commit

Permalink
add nodes_must_be_healthy probe
Browse files Browse the repository at this point in the history
Signed-off-by: Sylvain Hellegouarch <[email protected]>
  • Loading branch information
Lawouach committed Mar 22, 2024
1 parent 5a7f432 commit c57e63b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

* Improved logging of `delete_node` to grasp corner cases
* A new `verify_nodes_condition` probe to check any condition on nodes
* A new `nodes_must_be_healthy` prove to check a set of node conditions against
expected values

### Changed

Expand Down
56 changes: 56 additions & 0 deletions chaosk8s/node/probes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"all_nodes_must_be_ready_to_schedule",
"get_all_node_status_conditions",
"verify_nodes_condition",
"nodes_must_be_healthy",
]
logger = logging.getLogger("chaostoolkit")

Expand Down Expand Up @@ -110,3 +111,58 @@ def verify_nodes_condition(
return False

return True


def nodes_must_be_healthy(
label_selector: str = None,
configuration: Configuration = None,
secrets: Secrets = None,
) -> bool:
"""
Verifies the state of the following node conditions:
* FrequentKubeletRestart must be False
* FrequentDockerRestart must be False
* FrequentContainerdRestart must be False
* ReadonlyFilesystem must be False
* KernelDeadlock must be False
* CorruptDockerOverlay2 must be False
* FrequentUnregisterNetDevice must be False
* NetworkUnavailable must be False
* FrequentKubeletRestart must be False
* MemoryPressure must be False
* DiskPressure must be False
* PIDPressure must be False
* Ready must be True
For all matching nodes, if any is not in the expected state, returns False.
"""
result = get_all_node_status_conditions(
label_selector, configuration, secrets
)

expectations = [
("FrequentKubeletRestart", "False"),
("FrequentDockerRestart", "False"),
("FrequentContainerdRestart", "False"),
("ReadonlyFilesystem", "False"),
("KernelDeadlock", "False"),
("CorruptDockerOverlay2", "False"),
("FrequentUnregisterNetDevice", "False"),
("NetworkUnavailable", "False"),
("MemoryPressure", "False"),
("DiskPressure", "False"),
("PIDPressure", "False"),
("Ready", "True"),
]

for statuses in result:
for ctype, cvalue in expectations:
if (ctype in statuses) and (statuses[ctype] != cvalue):
logger.debug(
f"Node {statuses['name']} does not match '{ctype}' "
"expected state: {cvalue}"
)
return False

return True

0 comments on commit c57e63b

Please sign in to comment.