mirror of
https://github.com/podman-container-tools/podman.git
synced 2026-08-27 02:37:53 +00:00
Merge pull request #7662 from jwhonce/issues/7535
Evict containers before removing via V2 API
This commit is contained in:
commit
684cde87fa
1 changed files with 20 additions and 2 deletions
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue