Merge pull request #20232 from umohnani8/ctr-create

Check for image with /libpod/containers/create
This commit is contained in:
openshift-ci[bot]
2023-10-09 20:17:19 +00:00
committed by GitHub
2 changed files with 14 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package libpod
import (
"encoding/json"
"errors"
"fmt"
"net/http"
"strconv"
@ -13,6 +14,7 @@ import (
"github.com/containers/podman/v4/pkg/specgen"
"github.com/containers/podman/v4/pkg/specgen/generate"
"github.com/containers/podman/v4/pkg/specgenutil"
"github.com/containers/storage"
)
// CreateContainer takes a specgenerator and makes a container. It returns
@ -60,12 +62,20 @@ func CreateContainer(w http.ResponseWriter, r *http.Request) {
warn, err := generate.CompleteSpec(r.Context(), runtime, &sg)
if err != nil {
if errors.Is(err, storage.ErrImageUnknown) {
utils.Error(w, http.StatusNotFound, fmt.Errorf("no such image: %w", err))
return
}
utils.InternalServerError(w, err)
return
}
rtSpec, spec, opts, err := generate.MakeContainer(r.Context(), runtime, &sg, false, nil)
if err != nil {
if errors.Is(err, storage.ErrImageUnknown) {
utils.Error(w, http.StatusNotFound, fmt.Errorf("no such image: %w", err))
return
}
utils.InternalServerError(w, err)
return
}

View File

@ -174,6 +174,10 @@ if root; then
podman rm -f $CTRNAME
fi
# Container create without existing image should return 404
t POST libpod/containers/create Image="foo" 404 \
.cause="image not known"
# Issue #6799: it should be possible to start a container, even w/o args.
t POST libpod/containers/create?name=test_noargs Image=${IMAGE} 201 \
.Id~[0-9a-f]\\{64\\}