Skip to content

Commit

Permalink
Merge pull request #18956 from vrothberg/fix-18951
Browse files Browse the repository at this point in the history
compat API container create: handle platform parameter
  • Loading branch information
openshift-merge-robot authored Jun 21, 2023
2 parents b71f74c + f4c514b commit 2c8b679
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
16 changes: 14 additions & 2 deletions pkg/api/handlers/compat/containers_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"strconv"
"strings"

"github.com/containers/buildah/pkg/parse"
"github.com/containers/common/libimage"
"github.com/containers/common/libnetwork/types"
"github.com/containers/common/pkg/cgroups"
"github.com/containers/common/pkg/config"
Expand All @@ -33,7 +35,8 @@ func CreateContainer(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
decoder := r.Context().Value(api.DecoderKey).(*schema.Decoder)
query := struct {
Name string `schema:"name"`
Name string `schema:"name"`
Platform string `schema:"platform"`
}{
// override any golang type defaults
}
Expand Down Expand Up @@ -69,7 +72,16 @@ func CreateContainer(w http.ResponseWriter, r *http.Request) {
}
body.Config.Image = imageName

newImage, resolvedName, err := runtime.LibimageRuntime().LookupImage(body.Config.Image, nil)
lookupImageOptions := libimage.LookupImageOptions{}
if query.Platform != "" {
var err error
lookupImageOptions.OS, lookupImageOptions.Architecture, lookupImageOptions.Variant, err = parse.Platform(query.Platform)
if err != nil {
utils.Error(w, http.StatusBadRequest, fmt.Errorf("parsing platform: %w", err))
return
}
}
newImage, resolvedName, err := runtime.LibimageRuntime().LookupImage(body.Config.Image, &lookupImageOptions)
if err != nil {
if errors.Is(err, storage.ErrImageUnknown) {
utils.Error(w, http.StatusNotFound, fmt.Errorf("no such image: %w", err))
Expand Down
11 changes: 11 additions & 0 deletions test/apiv2/20-containers.at
Original file line number Diff line number Diff line change
Expand Up @@ -624,3 +624,14 @@ fi
rm -rf $TMPD

podman container rm -fa

# 18951: Make sure container create supports the platform parameter. Force an
# initial architecture to make sure the test runs on all platforms.
podman pull --platform=linux/amd64 $IMAGE
t POST containers/create?platform=linux/amd64 \
Image=$IMAGE \
201
t POST containers/create?platform=linux/aarch64 \
Image=$IMAGE \
404
podman rmi -f $IMAGE

0 comments on commit 2c8b679

Please sign in to comment.