Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Commit

Permalink
Merge pull request #809 from darkowlzz/force-remove
Browse files Browse the repository at this point in the history
  • Loading branch information
stealthybox committed Mar 15, 2021
2 parents 0dd629d + 6de3da1 commit 2c2e4b0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pkg/runtime/containerd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down
17 changes: 17 additions & 0 deletions pkg/runtime/docker/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand Down

0 comments on commit 2c2e4b0

Please sign in to comment.