From 4366e96e1c4de4b0b2acae1f62ded72f3561cafe Mon Sep 17 00:00:00 2001 From: Ian Roberts <ian@roberts.gb.net> Date: Fri, 29 Mar 2024 10:09:23 +0000 Subject: [PATCH] fix: don't error if pod has no containerStatuses (#4471) In certain circumstances pod["status"] may not have a containerStatuses child property at all (e.g. if the pod is Pending and not yet scheduled to any node). Guard against this by using .get (returns None) instead of [] (raises KeyError). --- scripts/kill-host-pods.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/kill-host-pods.py b/scripts/kill-host-pods.py index 0416a5fc3d..35b0722f9b 100755 --- a/scripts/kill-host-pods.py +++ b/scripts/kill-host-pods.py @@ -21,7 +21,7 @@ def post_filter_has_known_containers(pod, containers: list) -> bool: Return true if any of the container IDs on the pod match the list of containers passed on the second argument. """ - for container in pod["status"]["containerStatuses"] or []: + for container in pod["status"].get("containerStatuses") or []: try: _, container_id = container["containerID"].split("containerd://", 2) if container_id in containers: