diff options
author | Matthew Heon <matthew.heon@pm.me> | 2019-10-04 10:40:20 -0400 |
---|---|---|
committer | Matthew Heon <matthew.heon@pm.me> | 2019-10-04 11:04:43 -0400 |
commit | bb803b8f7a475a3128555899d7ae0600dc0a055e (patch) | |
tree | d84a645e56fc80d1feab84bdfc1472e10b461b5b /libpod/runtime_ctr.go | |
parent | c9e936a40796824422011515f2fe445f93451f31 (diff) | |
download | podman-bb803b8f7a475a3128555899d7ae0600dc0a055e.tar.gz podman-bb803b8f7a475a3128555899d7ae0600dc0a055e.tar.bz2 podman-bb803b8f7a475a3128555899d7ae0600dc0a055e.zip |
When evicting containers, perform a normal remove first
This ensures that containers that didn't require an evict will be
dealt with normally, and we only break out evict for containers
that refuse to be removed by normal means.
Signed-off-by: Matthew Heon <matthew.heon@pm.me>
Diffstat (limited to 'libpod/runtime_ctr.go')
-rw-r--r-- | libpod/runtime_ctr.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go index 1a2987244..78176a400 100644 --- a/libpod/runtime_ctr.go +++ b/libpod/runtime_ctr.go @@ -576,11 +576,33 @@ func (r *Runtime) evictContainer(ctx context.Context, idOrName string, removeVol if !r.valid { return "", define.ErrRuntimeStopped } + id, err := r.state.LookupContainerID(idOrName) if err != nil { return "", errors.Wrapf(err, "Failed to find container %q in state", idOrName) } + // Begin by trying a normal removal. Valid containers will be removed normally. + tmpCtr, err := r.state.Container(id) + if err == nil { + logrus.Infof("Container %s successfully retrieved from state, attempting normal removal", id) + // Assume force = true for the evict case + err = r.removeContainer(ctx, tmpCtr, true, removeVolume, false) + if !tmpCtr.valid { + // If the container is marked invalid, remove succeeded + // in kicking it out of the state - no need to continue. + return id, err + } + + if err == nil { + // Something has gone seriously wrong - no error but + // container was not removed. + logrus.Errorf("Container %s not removed with no error", id) + } else { + logrus.Warnf("Failed to removal container %s normally, proceeding with evict: %v", id, err) + } + } + // Error out if the container does not exist in libpod exists, err := r.state.HasContainer(id) if err != nil { |