Skip to content

Commit

Permalink
Merge pull request #20232 from umohnani8/ctr-create
Browse files Browse the repository at this point in the history
Check for image with /libpod/containers/create
  • Loading branch information
openshift-ci[bot] authored Oct 9, 2023
2 parents 8615b16 + d18369e commit 040a4e4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/api/handlers/libpod/containers_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package libpod

import (
"encoding/json"
"errors"
"fmt"
"net/http"
"strconv"
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions test/apiv2/20-containers.at
Original file line number Diff line number Diff line change
Expand Up @@ -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\\}
Expand Down

0 comments on commit 040a4e4

Please sign in to comment.