weaveworks / ignite

Ignite a Firecracker microVM
https://ignite.readthedocs.org
Apache License 2.0
3.49k stars 226 forks source link

runtime: Handle error when container not found #809

Closed darkowlzz closed 3 years ago

darkowlzz commented 3 years ago

When removing or stopping a VM, if the container runtime returns error because it can't find the associated VM container, the remove fails. With this change, ignite will checks if the container runtime error is about container not found and return without any error, no-op, letting the operation succeed.

Before:

$ sudo ./bin/ignite rm -f my-vm2
INFO[0000] Removing the container with ID "ignite-7e6c9464555b2513" from the "cni" network
INFO[0000] CNI failed to retrieve network namespace path: container "ignite-7e6c9464555b2513" in namespace "firecracker": not found
FATA[0000] failed to kill container for VM "7e6c9464555b2513": container "ignite-7e6c9464555b2513" in namespace "firecracker": not found

After(containerd):

$ sudo ./bin/ignite rm -f my-vm2
INFO[0000] Removing the container with ID "ignite-7e6c9464555b2513" from the "cni" network
INFO[0000] CNI failed to retrieve network namespace path: container "ignite-7e6c9464555b2513" in namespace "firecracker": not found
WARN[0000] container "ignite-7e6c9464555b2513" in namespace "firecracker": not found
INFO[0000] Removed VM with name "my-vm2" and ID "7e6c9464555b2513"

Docker:

$ sudo ./bin/ignite rm -f my-vm2
INFO[0000] Removing the container with ID "ignite-7e6c9464555b2513" from the "docker-bridge" network
WARN[0000] Error response from daemon: Cannot kill container: ignite-7e6c9464555b2513: No such container: ignite-7e6c9464555b2513
INFO[0000] Removed VM with name "my-vm2" and ID "7e6c9464555b2513"

NOTE: This change avoids the usage of ifFound() in containred/client.go to keep the changes minimal for now. Using ifFound() results in a lot of code restructuring due to named error return, easily resulting in shadowed error related issues. A proper refactoring could be done separately.

Fixes #751