microk8s
microk8s copied to clipboard
KeyError in kill-host-pods.py
https://github.com/canonical/microk8s/blob/f9eb294558bf1103a3109504452077af059af384/scripts/kill-host-pods.py#L24
It is possible for a pod not to have a containerStatus
field, e.g. when it is in "Pending" state because no compatible node is available for it to be scheduled onto. If kill-host-pods.py
runs when there are one or more pods in this condition, it fails with the following traceback:
Traceback (most recent call last):
File "/snap/microk8s/6364/scripts/kill-host-pods.py", line 104, in <module>
main()
File "/snap/microk8s/6364/usr/lib/python3/dist-packages/click/core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "/snap/microk8s/6364/usr/lib/python3/dist-packages/click/core.py", line 717, in main
rv = self.invoke(ctx)
File "/snap/microk8s/6364/usr/lib/python3/dist-packages/click/core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/snap/microk8s/6364/usr/lib/python3/dist-packages/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "/snap/microk8s/6364/scripts/kill-host-pods.py", line 88, in main
if not post_filter_has_known_containers(pod, containers):
File "/snap/microk8s/6364/scripts/kill-host-pods.py", line 24, in post_filter_has_known_containers
for container in pod["status"]["containerStatuses"] or []:
KeyError: 'containerStatuses'
Two possible fixes:
- use
.get
instead of[]
- add another layer of try/except around the whole
for
loop