summaryrefslogtreecommitdiff
path: root/pkg/api/handlers
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2021-01-18 14:49:53 -0500
committerMatthew Heon <matthew.heon@pm.me>2021-02-08 13:57:45 -0500
commitefcffde620f74316492fe08f71f022e1cfab2351 (patch)
treed1fecefea54642b7b3b3342f94776d98f5cbdb2f /pkg/api/handlers
parentbcf7d4383d532477ea97511e6565ed00480ad8b8 (diff)
downloadpodman-efcffde620f74316492fe08f71f022e1cfab2351.tar.gz
podman-efcffde620f74316492fe08f71f022e1cfab2351.tar.bz2
podman-efcffde620f74316492fe08f71f022e1cfab2351.zip
Fix handling of container remove
I found several problems with container remove podman-remote rm --all Was not handled podman-remote rm --ignore Was not handled Return better errors when attempting to remove an --external container. Currently we return the container does not exists, as opposed to container is an external container that is being used. This patch also consolidates the tunnel code to use the same code for removing the container, as the local API, removing duplication of code and potential problems. Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'pkg/api/handlers')
-rw-r--r--pkg/api/handlers/compat/containers.go45
1 files changed, 23 insertions, 22 deletions
diff --git a/pkg/api/handlers/compat/containers.go b/pkg/api/handlers/compat/containers.go
index a8f850823..de8366587 100644
--- a/pkg/api/handlers/compat/containers.go
+++ b/pkg/api/handlers/compat/containers.go
@@ -14,7 +14,9 @@ import (
"github.com/containers/podman/v2/libpod/define"
"github.com/containers/podman/v2/pkg/api/handlers"
"github.com/containers/podman/v2/pkg/api/handlers/utils"
+ "github.com/containers/podman/v2/pkg/domain/entities"
"github.com/containers/podman/v2/pkg/domain/filters"
+ "github.com/containers/podman/v2/pkg/domain/infra/abi"
"github.com/containers/podman/v2/pkg/ps"
"github.com/containers/podman/v2/pkg/signal"
"github.com/docker/docker/api/types"
@@ -30,9 +32,11 @@ import (
func RemoveContainer(w http.ResponseWriter, r *http.Request) {
decoder := r.Context().Value("decoder").(*schema.Decoder)
query := struct {
- Force bool `schema:"force"`
- Vols bool `schema:"v"`
- Link bool `schema:"link"`
+ All bool `schema:"all"`
+ Force bool `schema:"force"`
+ Ignore bool `schema:"ignore"`
+ Link bool `schema:"link"`
+ Volumes bool `schema:"v"`
}{
// override any golang type defaults
}
@@ -50,34 +54,31 @@ func RemoveContainer(w http.ResponseWriter, r *http.Request) {
}
runtime := r.Context().Value("runtime").(*libpod.Runtime)
+ // Now use the ABI implementation to prevent us from having duplicate
+ // code.
+ containerEngine := abi.ContainerEngine{Libpod: runtime}
name := utils.GetName(r)
- con, err := runtime.LookupContainer(name)
- 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 {
+ options := entities.RmOptions{
+ All: query.All,
+ Force: query.Force,
+ Volumes: query.Volumes,
+ Ignore: query.Ignore,
+ }
+ report, err := containerEngine.ContainerRm(r.Context(), []string{name}, options)
+ if err != nil {
+ if errors.Cause(err) == define.ErrNoSuchCtr {
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)
+ utils.InternalServerError(w, err)
return
}
-
- if err := runtime.RemoveContainer(r.Context(), con, query.Force, query.Vols); err != nil {
- utils.InternalServerError(w, err)
+ if report[0].Err != nil {
+ utils.InternalServerError(w, report[0].Err)
return
}
+
utils.WriteResponse(w, http.StatusNoContent, nil)
}