diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-10-19 02:49:27 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-19 02:49:27 -0400 |
commit | 7ffcab0854342844a44b2668bd9d98849bf935c8 (patch) | |
tree | c7c8b60c8d389314309c7e2e73e3b41f06988fbc /pkg/api | |
parent | 6ec96dc009d73cc2b0a3fa81149ca599b04252e4 (diff) | |
parent | 571ae9db7241ffbe1be4f254328cfd2e43369103 (diff) | |
download | podman-7ffcab0854342844a44b2668bd9d98849bf935c8.tar.gz podman-7ffcab0854342844a44b2668bd9d98849bf935c8.tar.bz2 podman-7ffcab0854342844a44b2668bd9d98849bf935c8.zip |
Merge pull request #7908 from rhatdan/diff
fix podman container exists and diff for storage containers
Diffstat (limited to 'pkg/api')
-rw-r--r-- | pkg/api/handlers/libpod/containers.go | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/pkg/api/handlers/libpod/containers.go b/pkg/api/handlers/libpod/containers.go index 7dde51102..7e6481321 100644 --- a/pkg/api/handlers/libpod/containers.go +++ b/pkg/api/handlers/libpod/containers.go @@ -11,6 +11,7 @@ import ( "github.com/containers/podman/v2/pkg/api/handlers/compat" "github.com/containers/podman/v2/pkg/api/handlers/utils" "github.com/containers/podman/v2/pkg/domain/entities" + "github.com/containers/podman/v2/pkg/domain/infra/abi" "github.com/containers/podman/v2/pkg/ps" "github.com/gorilla/schema" "github.com/pkg/errors" @@ -18,9 +19,30 @@ import ( ) func ContainerExists(w http.ResponseWriter, r *http.Request) { + decoder := r.Context().Value("decoder").(*schema.Decoder) 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) - _, err := runtime.LookupContainer(name) + query := struct { + External bool `schema:"external"` + }{ + // override any golang type defaults + } + + if err := decoder.Decode(&query, r.URL.Query()); err != nil { + utils.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest, + errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String())) + return + } + + options := entities.ContainerExistsOptions{ + External: query.External, + } + + report, err := containerEngine.ContainerExists(r.Context(), name, options) if err != nil { if errors.Cause(err) == define.ErrNoSuchCtr { utils.ContainerNotFound(w, name, err) @@ -30,7 +52,11 @@ func ContainerExists(w http.ResponseWriter, r *http.Request) { return } - utils.WriteResponse(w, http.StatusNoContent, "") + if report.Value { + utils.WriteResponse(w, http.StatusNoContent, "") + } else { + utils.ContainerNotFound(w, name, define.ErrNoSuchCtr) + } } func ListContainers(w http.ResponseWriter, r *http.Request) { |