summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJhon Honce <jhonce@redhat.com>2020-09-16 14:30:41 -0700
committerJhon Honce <jhonce@redhat.com>2020-09-18 10:05:07 -0700
commited930d9d7cde94533c765ee83f9ece56397dc779 (patch)
treec852f9fd0ea53c7a1d16d831a0dcd8a250ca2d56
parent031ddf9c8476202c6b0c810c6c0f6a7a0040c035 (diff)
downloadpodman-ed930d9d7cde94533c765ee83f9ece56397dc779.tar.gz
podman-ed930d9d7cde94533c765ee83f9ece56397dc779.tar.bz2
podman-ed930d9d7cde94533c765ee83f9ece56397dc779.zip
Evict containers before removing via V2 API
Fixes #7535 Signed-off-by: Jhon Honce <jhonce@redhat.com>
-rw-r--r--pkg/api/handlers/compat/containers.go22
1 files changed, 20 insertions, 2 deletions
diff --git a/pkg/api/handlers/compat/containers.go b/pkg/api/handlers/compat/containers.go
index b1ef08cda..f9e200ff3 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
}