Skip to content

Commit

Permalink
fix: don't error if pod has no containerStatuses (canonical#4471)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
ianroberts committed Mar 29, 2024
1 parent f9eb294 commit 4366e96
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion scripts/kill-host-pods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 4366e96

Please sign in to comment.