diff --git a/pkg/runtime/containerd/client.go b/pkg/runtime/containerd/client.go index 3e2f7da88..159cf26b7 100644 --- a/pkg/runtime/containerd/client.go +++ b/pkg/runtime/containerd/client.go @@ -574,6 +574,11 @@ func withDevices(devices []*runtime.Bind) oci.SpecOpts { func (cc *ctdClient) StopContainer(container string, timeout *time.Duration) (err error) { cont, err := cc.client.LoadContainer(cc.ctx, container) if err != nil { + // If the container is not found, return nil, no-op. + if errdefs.IsNotFound(err) { + log.Warn(err) + err = nil + } return } @@ -596,6 +601,11 @@ func (cc *ctdClient) StopContainer(container string, timeout *time.Duration) (er task, err := cont.Task(cc.ctx, cio.Load) if err != nil { + // If the task is not found, return nil, no-op. + if errdefs.IsNotFound(err) { + log.Warn(err) + err = nil + } return } @@ -639,11 +649,21 @@ func (cc *ctdClient) StopContainer(container string, timeout *time.Duration) (er func (cc *ctdClient) KillContainer(container, signal string) (err error) { cont, err := cc.client.LoadContainer(cc.ctx, container) if err != nil { + // If the container is not found, return nil, no-op. + if errdefs.IsNotFound(err) { + log.Warn(err) + err = nil + } return } task, err := cont.Task(cc.ctx, cio.Load) if err != nil { + // If the task is not found, return nil, no-op. + if errdefs.IsNotFound(err) { + log.Warn(err) + err = nil + } return } diff --git a/pkg/runtime/docker/client.go b/pkg/runtime/docker/client.go index ced109fe8..4f7ae2edf 100644 --- a/pkg/runtime/docker/client.go +++ b/pkg/runtime/docker/client.go @@ -12,6 +12,8 @@ import ( "github.com/docker/docker/api/types/container" cont "github.com/docker/docker/api/types/container" "github.com/docker/docker/client" + "github.com/docker/docker/errdefs" + log "github.com/sirupsen/logrus" meta "github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1" "github.com/weaveworks/ignite/pkg/preflight" "github.com/weaveworks/ignite/pkg/preflight/checkers" @@ -183,6 +185,11 @@ func (dc *dockerClient) StopContainer(container string, timeout *time.Duration) <-readyC // wait until removal detection has started if err := dc.client.ContainerStop(context.Background(), container, timeout); err != nil { + // If the container is not found, return nil, no-op. + if errdefs.IsNotFound(err) { + log.Warn(err) + return nil + } return err } @@ -199,6 +206,11 @@ func (dc *dockerClient) KillContainer(container, signal string) error { <-readyC // wait until removal detection has started if err := dc.client.ContainerKill(context.Background(), container, signal); err != nil { + // If the container is not found, return nil, no-op. + if errdefs.IsNotFound(err) { + log.Warn(err) + return nil + } return err } @@ -218,6 +230,11 @@ func (dc *dockerClient) RemoveContainer(container string) error { <-readyC // The ready channel is used to wait until removal detection has started if err := dc.client.ContainerRemove(context.Background(), container, types.ContainerRemoveOptions{}); err != nil { + // If the container is not found, return nil, no-op. + if errdefs.IsNotFound(err) { + log.Warn(err) + return nil + } return err }