diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-09-24 17:04:03 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-24 17:04:03 +0000 |
commit | 684cde87fa8f78a2ba7389e6eecd36dda00cfdff (patch) | |
tree | 081fca1f0b58a0ff0d8f692014cb75e16e4c704f /pkg/api | |
parent | 0839300a712479248788910a083adc843190a0ab (diff) | |
parent | ed930d9d7cde94533c765ee83f9ece56397dc779 (diff) | |
download | podman-684cde87fa8f78a2ba7389e6eecd36dda00cfdff.tar.gz podman-684cde87fa8f78a2ba7389e6eecd36dda00cfdff.tar.bz2 podman-684cde87fa8f78a2ba7389e6eecd36dda00cfdff.zip |
Merge pull request #7662 from jwhonce/issues/7535
Evict containers before removing via V2 API
Diffstat (limited to 'pkg/api')
-rw-r--r-- | pkg/api/handlers/compat/containers.go | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/pkg/api/handlers/compat/containers.go b/pkg/api/handlers/compat/containers.go index 63c44eaef..3a904ba87 100644 --- a/pkg/api/handlers/compat/containers.go +++ b/pkg/api/handlers/compat/containers.go @@ -17,6 +17,7 @@ import ( "github.com/docker/go-connections/nat" "github.com/gorilla/schema" "github.com/pkg/errors" + "github.com/sirupsen/logrus" ) func RemoveContainer(w http.ResponseWriter, r *http.Request) { @@ -44,8 +45,25 @@ func RemoveContainer(w http.ResponseWriter, r *http.Request) { runtime := r.Context().Value("runtime").(*libpod.Runtime) name := utils.GetName(r) con, err := runtime.LookupContainer(name) - if err != nil { - utils.ContainerNotFound(w, name, err) + if err != nil && errors.Cause(err) == define.ErrNoSuchCtr { + // Failed to get container. If force is specified, get the container's ID + // and evict it + if !query.Force { + utils.ContainerNotFound(w, name, err) + return + } + + if _, err := runtime.EvictContainer(r.Context(), name, query.Vols); err != nil { + if errors.Cause(err) == define.ErrNoSuchCtr { + logrus.Debugf("Ignoring error (--allow-missing): %q", err) + w.WriteHeader(http.StatusNoContent) + return + } + logrus.Warn(errors.Wrapf(err, "Failed to evict container: %q", name)) + utils.InternalServerError(w, err) + return + } + w.WriteHeader(http.StatusNoContent) return } |