diff options
Diffstat (limited to 'pkg/api')
-rw-r--r-- | pkg/api/handlers/compat/containers_create.go | 2 | ||||
-rw-r--r-- | pkg/api/handlers/compat/events.go | 15 | ||||
-rw-r--r-- | pkg/api/handlers/compat/images.go | 5 | ||||
-rw-r--r-- | pkg/api/handlers/libpod/containers.go | 30 |
4 files changed, 42 insertions, 10 deletions
diff --git a/pkg/api/handlers/compat/containers_create.go b/pkg/api/handlers/compat/containers_create.go index 4ce31cc83..8a0b3c922 100644 --- a/pkg/api/handlers/compat/containers_create.go +++ b/pkg/api/handlers/compat/containers_create.go @@ -238,7 +238,7 @@ func makeCreateConfig(ctx context.Context, containerConfig *config.Config, input Pod: "", // podman PodmanPath: "", // podman Quiet: false, // front-end only - Resources: createconfig.CreateResourceConfig{}, + Resources: createconfig.CreateResourceConfig{MemorySwappiness: -1}, RestartPolicy: input.HostConfig.RestartPolicy.Name, Rm: input.HostConfig.AutoRemove, StopSignal: stopSignal, diff --git a/pkg/api/handlers/compat/events.go b/pkg/api/handlers/compat/events.go index a729b84d4..f74491a8f 100644 --- a/pkg/api/handlers/compat/events.go +++ b/pkg/api/handlers/compat/events.go @@ -112,11 +112,15 @@ func GetEvents(w http.ResponseWriter, r *http.Request) { errorChannel <- runtime.Events(r.Context(), readOpts) }() - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusOK) + var flush = func() {} if flusher, ok := w.(http.Flusher); ok { - flusher.Flush() + flush = flusher.Flush } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + flush() + coder := json.NewEncoder(w) coder.SetEscapeHTML(true) @@ -124,6 +128,7 @@ func GetEvents(w http.ResponseWriter, r *http.Request) { select { case err := <-errorChannel: if err != nil { + // FIXME StatusOK already sent above cannot send 500 here utils.InternalServerError(w, err) return } @@ -136,9 +141,7 @@ func GetEvents(w http.ResponseWriter, r *http.Request) { if err := coder.Encode(e); err != nil { logrus.Errorf("unable to write json: %q", err) } - if flusher, ok := w.(http.Flusher); ok { - flusher.Flush() - } + flush() case <-r.Context().Done(): return } diff --git a/pkg/api/handlers/compat/images.go b/pkg/api/handlers/compat/images.go index f49ce59da..3431823bd 100644 --- a/pkg/api/handlers/compat/images.go +++ b/pkg/api/handlers/compat/images.go @@ -327,7 +327,10 @@ func GetImage(w http.ResponseWriter, r *http.Request) { name := utils.GetName(r) newImage, err := utils.GetImage(r, name) if err != nil { - utils.Error(w, "Something went wrong.", http.StatusNotFound, errors.Wrapf(err, "failed to find image %s", name)) + // Here we need to fiddle with the error message because docker-py is looking for "No + // such image" to determine on how to raise the correct exception. + errMsg := strings.ReplaceAll(err.Error(), "no such image", "No such image") + utils.Error(w, "Something went wrong.", http.StatusNotFound, errors.Errorf("failed to find image %s: %s", name, errMsg)) return } inspect, err := handlers.ImageDataToImageInspect(r.Context(), newImage) 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) { |