From 869466eb25a41ab0e6daf9bc6ab951d7300d3f9d Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Mon, 15 Apr 2019 13:39:22 -0400 Subject: 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 --- pkg/spec/containerconfig.go | 22 ++++++++++++++++++++++ pkg/spec/createconfig.go | 2 +- pkg/spec/spec.go | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 pkg/spec/containerconfig.go (limited to 'pkg') diff --git a/pkg/spec/containerconfig.go b/pkg/spec/containerconfig.go new file mode 100644 index 000000000..62108c012 --- /dev/null +++ b/pkg/spec/containerconfig.go @@ -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 +} diff --git a/pkg/spec/createconfig.go b/pkg/spec/createconfig.go index 9c674d9f1..76ce8032c 100644 --- a/pkg/spec/createconfig.go +++ b/pkg/spec/createconfig.go @@ -397,7 +397,7 @@ func (c *CreateConfig) createExitCommand() ([]string, error) { } // 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 portBindings []ocicni.PortMapping var err error diff --git a/pkg/spec/spec.go b/pkg/spec/spec.go index 383eeadf3..4c839921c 100644 --- a/pkg/spec/spec.go +++ b/pkg/spec/spec.go @@ -89,7 +89,7 @@ func getAvailableGids() (int64, error) { } // 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" g, err := generate.New("linux") if err != nil { -- cgit v1.2.3-54-g00ecf