Merge pull request #4196 from mheon/normal_remove_on_evict

When evicting containers, perform a normal remove first
This commit is contained in:
OpenShift Merge Robot 2019-10-07 02:54:13 -07:00 committed by GitHub
commit 589261f275
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 0 deletions

View File

@ -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 {