Skip to content

Commit

Permalink
Fix system state test
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Gu <[email protected]>
  • Loading branch information
tylergu committed Jan 29, 2024
1 parent 2f3c6a2 commit e1d844f
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 36 deletions.
19 changes: 10 additions & 9 deletions acto/system_state/daemon_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,16 @@ def check_health(self) -> tuple[bool, str]:
+ f"!= ready[{daemon_set.status.number_ready}]",
)

for condition in daemon_set.status.conditions:
if (
condition.type == "Progressing"
and condition.status != "True"
):
return (
False,
f"DaemonSet[{name}] is not progressing: {condition.message}",
)
if daemon_set.status.conditions is not None:
for condition in daemon_set.status.conditions:
if (
condition.type == "Progressing"
and condition.status != "True"
):
return (
False,
f"DaemonSet[{name}] is not progressing: {condition.message}",
)

return True, ""

Expand Down
27 changes: 17 additions & 10 deletions acto/system_state/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,30 @@ def check_health(self) -> tuple[bool, str]:
if deployment.spec.replicas != deployment.status.ready_replicas:
return False, f"Deployment[{name}] replicas mismatch"

for condition in deployment.status.conditions:
if condition.type == "Available" and condition.status != "True":
return False, f"Deployment[{name}] is not available"
if (
condition.type == "Progressing"
and condition.status != "True"
):
return False, f"Deployment[{name}] is not progressing"
if deployment.status.conditions is not None:
for condition in deployment.status.conditions:
if (
condition.type == "Available"
and condition.status != "True"
):
return False, f"Deployment[{name}] is not available"
if (
condition.type == "Progressing"
and condition.status != "True"
):
return False, f"Deployment[{name}] is not progressing"

if deployment.status.replicas != deployment.status.ready_replicas:
return False, f"Deployment[{name}] replicas mismatch"

if (
deployment.status.unavailable_replicas != 0
and deployment.status.updated_replicas is not None
and deployment.status.unavailable_replicas is not None
):
return False, "Some pods are unavailable"
return (
False,
f"[{name}] [{deployment.status.unavailable_replicas}] pods are unavailable",
)

return True, ""

Expand Down
28 changes: 15 additions & 13 deletions acto/system_state/pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,21 @@ def check_health(self) -> tuple[bool, str]:
"""

for name, pod in self.root.items():
for condition in pod.status.conditions:
if condition.type == "Ready" and condition.status != "True":
return (
False,
f"Pod[{name}] is not ready: {condition.message}",
)

for container_status in pod.status.container_statuses:
if container_status.ready is not True:
return (
False,
f"Container {container_status.name} is not ready",
)
if pod.status.conditions is not None:
for condition in pod.status.conditions:
if condition.type == "Ready" and condition.status != "True":
return (
False,
f"Pod[{name}] is not ready: {condition.message}",
)

if pod.status.container_statuses is not None:
for container_status in pod.status.container_statuses:
if container_status.ready is not True:
return (
False,
f"Container {container_status.name} is not ready",
)

if pod.status.init_container_statuses is not None:
for container_status in pod.status.init_container_statuses:
Expand Down
10 changes: 7 additions & 3 deletions acto/system_state/replica_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ def check_health(self) -> tuple[bool, str]:
if replica_set.spec.replicas != replica_set.status.ready_replicas:
return False, f"ReplicaSet[{name}] replicas mismatch"

for condition in replica_set.status.conditions:
if condition.type == "Available" and condition.status != "True":
return False, f"ReplicaSet[{name}] is not available"
if replica_set.status.conditions is not None:
for condition in replica_set.status.conditions:
if (
condition.type == "Available"
and condition.status != "True"
):
return False, f"ReplicaSet[{name}] is not available"

return True, ""

Expand Down
1 change: 0 additions & 1 deletion test/integration_tests/test_kubernetes_system_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def test_collect_and_serialization(self):
assert "coredns" in state.config_map
assert "admin" in state.cluster_role
assert "cluster-admin" in state.cluster_role_binding
assert "kube-dns" in state.endpoint

# check serialization works
with tempfile.TemporaryFile("w") as file:
Expand Down

0 comments on commit e1d844f

Please sign in to comment.