Merge pull request #18956 from vrothberg/fix-18951

compat API container create: handle platform parameter
This commit is contained in:
OpenShift Merge Robot
2023-06-21 16:19:12 +02:00
committed by GitHub
2 changed files with 25 additions and 2 deletions

View File

@ -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"
@ -34,6 +36,7 @@ func CreateContainer(w http.ResponseWriter, r *http.Request) {
decoder := r.Context().Value(api.DecoderKey).(*schema.Decoder)
query := struct {
Name string `schema:"name"`
Platform string `schema:"platform"`
}{
// override any golang type defaults
}
@ -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))

View File

@ -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