From dacbc5beb2a8841e52cf8ea7f544b4d302469c1d Mon Sep 17 00:00:00 2001 From: Marco Vedovati Date: Fri, 5 Jul 2019 12:54:07 +0200 Subject: rm: add containers eviction with `rm --force` Add ability to evict a container when it becomes unusable. This may happen when the host setup changes after a container creation, making it impossible for that container to be used or removed. Evicting a container is done using the `rm --force` command. Signed-off-by: Marco Vedovati --- pkg/adapter/containers.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'pkg/adapter/containers.go') diff --git a/pkg/adapter/containers.go b/pkg/adapter/containers.go index 47db5c0dc..afca4c948 100644 --- a/pkg/adapter/containers.go +++ b/pkg/adapter/containers.go @@ -205,7 +205,22 @@ func (r *LocalRuntime) RemoveContainers(ctx context.Context, cli *cliconfig.RmVa ctrs, err := shortcuts.GetContainersByContext(cli.All, cli.Latest, cli.InputArgs, r.Runtime) if err != nil { - return ok, failures, err + // Failed to get containers. If force is specified, get the containers ID + // and evict them + if !cli.Force { + return ok, failures, err + } + + for _, ctr := range cli.InputArgs { + logrus.Debugf("Evicting container %q", ctr) + id, err := r.EvictContainer(ctx, ctr, cli.Volumes) + if err != nil { + failures[ctr] = errors.Wrapf(err, "Failed to evict container: %q", id) + continue + } + ok = append(ok, id) + } + return ok, failures, nil } pool := shared.NewPool("rm", maxWorkers, len(ctrs)) -- cgit v1.2.3-54-g00ecf