From e1d844f0fcf397853493e6dbc635b7592a67cd4d Mon Sep 17 00:00:00 2001 From: Tyler Gu Date: Sun, 28 Jan 2024 23:53:11 -0600 Subject: [PATCH] Fix system state test Signed-off-by: Tyler Gu --- acto/system_state/daemon_set.py | 19 +++++++------ acto/system_state/deployment.py | 27 +++++++++++------- acto/system_state/pod.py | 28 ++++++++++--------- acto/system_state/replica_set.py | 10 +++++-- .../test_kubernetes_system_state.py | 1 - 5 files changed, 49 insertions(+), 36 deletions(-) diff --git a/acto/system_state/daemon_set.py b/acto/system_state/daemon_set.py index 615558685e..0f2fef6477 100644 --- a/acto/system_state/daemon_set.py +++ b/acto/system_state/daemon_set.py @@ -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, "" diff --git a/acto/system_state/deployment.py b/acto/system_state/deployment.py index f2ecd6c7d2..76189ae9f1 100644 --- a/acto/system_state/deployment.py +++ b/acto/system_state/deployment.py @@ -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, "" diff --git a/acto/system_state/pod.py b/acto/system_state/pod.py index 7925635403..0b47babef5 100644 --- a/acto/system_state/pod.py +++ b/acto/system_state/pod.py @@ -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: diff --git a/acto/system_state/replica_set.py b/acto/system_state/replica_set.py index eca0381926..7cf40816ef 100644 --- a/acto/system_state/replica_set.py +++ b/acto/system_state/replica_set.py @@ -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, "" diff --git a/test/integration_tests/test_kubernetes_system_state.py b/test/integration_tests/test_kubernetes_system_state.py index d1c5f13460..6cbd9e9391 100644 --- a/test/integration_tests/test_kubernetes_system_state.py +++ b/test/integration_tests/test_kubernetes_system_state.py @@ -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: