mirror of
https://github.com/containers/podman.git
synced 2025-06-03 03:07:56 +08:00
Refactor compat container create endpoint
* Make endpoint compatibile with docker-py network expectations * Update specgen helper when called from compat endpoint * Update godoc on types * Add test for network/container create using docker-py method * Add syslog logging when DEBUG=1 for tests Fixes #8361 Signed-off-by: Jhon Honce <jhonce@redhat.com>
This commit is contained in:
@ -19,7 +19,6 @@ import (
|
||||
func CreateContainer(w http.ResponseWriter, r *http.Request) {
|
||||
runtime := r.Context().Value("runtime").(*libpod.Runtime)
|
||||
decoder := r.Context().Value("decoder").(*schema.Decoder)
|
||||
input := handlers.CreateContainerConfig{}
|
||||
query := struct {
|
||||
Name string `schema:"name"`
|
||||
}{
|
||||
@ -30,11 +29,15 @@ func CreateContainer(w http.ResponseWriter, r *http.Request) {
|
||||
errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
|
||||
return
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&input); err != nil {
|
||||
|
||||
// compatible configuration
|
||||
body := handlers.CreateContainerConfig{}
|
||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
||||
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "Decode()"))
|
||||
return
|
||||
}
|
||||
if len(input.HostConfig.Links) > 0 {
|
||||
|
||||
if len(body.HostConfig.Links) > 0 {
|
||||
utils.Error(w, utils.ErrLinkNotSupport.Error(), http.StatusBadRequest, errors.Wrapf(utils.ErrLinkNotSupport, "bad parameter"))
|
||||
return
|
||||
}
|
||||
@ -43,7 +46,7 @@ func CreateContainer(w http.ResponseWriter, r *http.Request) {
|
||||
utils.Error(w, "unable to obtain runtime config", http.StatusInternalServerError, errors.Wrap(err, "unable to get runtime config"))
|
||||
}
|
||||
|
||||
newImage, err := runtime.ImageRuntime().NewFromLocal(input.Image)
|
||||
newImage, err := runtime.ImageRuntime().NewFromLocal(body.Config.Image)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == define.ErrNoSuchImage {
|
||||
utils.Error(w, "No such image", http.StatusNotFound, err)
|
||||
@ -54,11 +57,8 @@ func CreateContainer(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// Add the container name to the input struct
|
||||
input.Name = query.Name
|
||||
|
||||
// Take input structure and convert to cliopts
|
||||
cliOpts, args, err := common.ContainerCreateToContainerCLIOpts(input, rtc.Engine.CgroupManager)
|
||||
// Take body structure and convert to cliopts
|
||||
cliOpts, args, err := common.ContainerCreateToContainerCLIOpts(body, rtc.Engine.CgroupManager)
|
||||
if err != nil {
|
||||
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "make cli opts()"))
|
||||
return
|
||||
@ -69,6 +69,9 @@ func CreateContainer(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// Override the container name in the body struct
|
||||
body.Name = query.Name
|
||||
|
||||
ic := abi.ContainerEngine{Libpod: runtime}
|
||||
report, err := ic.ContainerCreate(r.Context(), sg)
|
||||
if err != nil {
|
||||
|
@ -110,11 +110,12 @@ type ContainerWaitOKBody struct {
|
||||
}
|
||||
}
|
||||
|
||||
// CreateContainerConfig used when compatible endpoint creates a container
|
||||
type CreateContainerConfig struct {
|
||||
Name string
|
||||
dockerContainer.Config
|
||||
HostConfig dockerContainer.HostConfig
|
||||
NetworkingConfig dockerNetwork.NetworkingConfig
|
||||
Name string // container name
|
||||
dockerContainer.Config // desired container configuration
|
||||
HostConfig dockerContainer.HostConfig // host dependent configuration for container
|
||||
NetworkingConfig dockerNetwork.NetworkingConfig // network configuration for container
|
||||
}
|
||||
|
||||
// swagger:model IDResponse
|
||||
@ -253,7 +254,7 @@ func ImageDataToImageInspect(ctx context.Context, l *libpodImage.Image) (*ImageI
|
||||
// StdinOnce: false,
|
||||
Env: info.Config.Env,
|
||||
Cmd: info.Config.Cmd,
|
||||
//Healthcheck: l.ImageData.HealthCheck,
|
||||
// Healthcheck: l.ImageData.HealthCheck,
|
||||
// ArgsEscaped: false,
|
||||
// Image: "",
|
||||
Volumes: info.Config.Volumes,
|
||||
@ -261,7 +262,7 @@ func ImageDataToImageInspect(ctx context.Context, l *libpodImage.Image) (*ImageI
|
||||
Entrypoint: info.Config.Entrypoint,
|
||||
// NetworkDisabled: false,
|
||||
// MacAddress: "",
|
||||
//OnBuild: info.Config.OnBuild,
|
||||
// OnBuild: info.Config.OnBuild,
|
||||
Labels: info.Labels,
|
||||
StopSignal: info.Config.StopSignal,
|
||||
// StopTimeout: nil,
|
||||
|
Reference in New Issue
Block a user