mirror of
https://github.com/containers/podman.git
synced 2025-10-20 12:43:58 +08:00
Add a new function for converting a CreateConfig
Right now, there are two major API calls necessary to turn a filled-in CreateConfig into the options and OCI spec necessary to make a libpod Container. I'm intending on refactoring both of these extensively to unify a few things, so make a common frontend to both that will prevent API changes from leaking out of the package. Signed-off-by: Matthew Heon <matthew.heon@pm.me>
This commit is contained in:
@ -732,12 +732,7 @@ type namespace interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func CreateContainerFromCreateConfig(r *libpod.Runtime, createConfig *cc.CreateConfig, ctx context.Context, pod *libpod.Pod) (*libpod.Container, error) {
|
func CreateContainerFromCreateConfig(r *libpod.Runtime, createConfig *cc.CreateConfig, ctx context.Context, pod *libpod.Pod) (*libpod.Container, error) {
|
||||||
runtimeSpec, err := cc.CreateConfigToOCISpec(createConfig)
|
runtimeSpec, options, err := createConfig.MakeContainerConfig(r, pod)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
options, err := createConfig.GetContainerCreateOptions(r, pod)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
22
pkg/spec/containerconfig.go
Normal file
22
pkg/spec/containerconfig.go
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package createconfig
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/containers/libpod/libpod"
|
||||||
|
spec "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MakeContainerConfig generates all configuration necessary to start a
|
||||||
|
// container with libpod from a completed CreateConfig struct.
|
||||||
|
func (config *CreateConfig) MakeContainerConfig(runtime *libpod.Runtime, pod *libpod.Pod) (*spec.Spec, []libpod.CtrCreateOption, error) {
|
||||||
|
runtimeSpec, err := config.createConfigToOCISpec()
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
options, err := config.getContainerCreateOptions(runtime, pod)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return runtimeSpec, options, nil
|
||||||
|
}
|
@ -397,7 +397,7 @@ func (c *CreateConfig) createExitCommand() ([]string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetContainerCreateOptions takes a CreateConfig and returns a slice of CtrCreateOptions
|
// GetContainerCreateOptions takes a CreateConfig and returns a slice of CtrCreateOptions
|
||||||
func (c *CreateConfig) GetContainerCreateOptions(runtime *libpod.Runtime, pod *libpod.Pod) ([]libpod.CtrCreateOption, error) {
|
func (c *CreateConfig) getContainerCreateOptions(runtime *libpod.Runtime, pod *libpod.Pod) ([]libpod.CtrCreateOption, error) {
|
||||||
var options []libpod.CtrCreateOption
|
var options []libpod.CtrCreateOption
|
||||||
var portBindings []ocicni.PortMapping
|
var portBindings []ocicni.PortMapping
|
||||||
var err error
|
var err error
|
||||||
|
@ -89,7 +89,7 @@ func getAvailableGids() (int64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CreateConfigToOCISpec parses information needed to create a container into an OCI runtime spec
|
// CreateConfigToOCISpec parses information needed to create a container into an OCI runtime spec
|
||||||
func CreateConfigToOCISpec(config *CreateConfig) (*spec.Spec, error) { //nolint
|
func (config *CreateConfig) createConfigToOCISpec() (*spec.Spec, error) { //nolint
|
||||||
cgroupPerm := "ro"
|
cgroupPerm := "ro"
|
||||||
g, err := generate.New("linux")
|
g, err := generate.New("linux")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Reference in New Issue
Block a user