podman play kube: add containers to pod

when defining containers, we missed the conditional logic to allow
the container to be defined with "WithPod" and so forth.  I had to
slightly modify the createcontainer process to pass a libpod.Pod
that could override things; use nil as no pod.

Signed-off-by: baude <bbaude@redhat.com>
This commit is contained in:
baude 2019-01-11 13:59:16 -06:00
parent 28c35cab87
commit e10baba326
5 changed files with 16 additions and 14 deletions

View File

@ -1,6 +1,6 @@
GO ?= go GO ?= go
DESTDIR ?= / DESTDIR ?= /
EPOCH_TEST_COMMIT ?= e1732a5213147e3c0b7bf60b55a332c3720ecb4b EPOCH_TEST_COMMIT ?= bd40dcfc2bc7c9014ea1f33482fb63aacbcdfe87
HEAD ?= HEAD HEAD ?= HEAD
CHANGELOG_BASE ?= HEAD~ CHANGELOG_BASE ?= HEAD~
CHANGELOG_TARGET ?= HEAD CHANGELOG_TARGET ?= HEAD

View File

@ -144,7 +144,7 @@ func createContainer(c *cli.Context, runtime *libpod.Runtime) (*libpod.Container
return nil, nil, err return nil, nil, err
} }
ctr, err := createContainerFromCreateConfig(runtime, createConfig, ctx) ctr, err := createContainerFromCreateConfig(runtime, createConfig, ctx, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -817,17 +817,16 @@ func joinOrCreateRootlessUserNamespace(createConfig *cc.CreateConfig, runtime *l
return rootless.BecomeRootInUserNS() return rootless.BecomeRootInUserNS()
} }
func createContainerFromCreateConfig(r *libpod.Runtime, createConfig *cc.CreateConfig, ctx context.Context) (*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, err := cc.CreateConfigToOCISpec(createConfig)
if err != nil { if err != nil {
return nil, err return nil, err
} }
options, err := createConfig.GetContainerCreateOptions(r) options, err := createConfig.GetContainerCreateOptions(r, pod)
if err != nil { if err != nil {
return nil, err return nil, err
} }
became, ret, err := joinOrCreateRootlessUserNamespace(createConfig, r) became, ret, err := joinOrCreateRootlessUserNamespace(createConfig, r)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -154,7 +154,7 @@ func playKubeYAMLCmd(c *cli.Context) error {
if err != nil { if err != nil {
return err return err
} }
ctr, err := createContainerFromCreateConfig(runtime, createConfig, ctx) ctr, err := createContainerFromCreateConfig(runtime, createConfig, ctx, pod)
if err != nil { if err != nil {
return err return err
} }

View File

@ -341,10 +341,9 @@ func (c *CreateConfig) createExitCommand() []string {
} }
// 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) ([]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 pod *libpod.Pod
var err error var err error
if c.Interactive { if c.Interactive {
@ -358,12 +357,14 @@ func (c *CreateConfig) GetContainerCreateOptions(runtime *libpod.Runtime) ([]lib
logrus.Debugf("appending name %s", c.Name) logrus.Debugf("appending name %s", c.Name)
options = append(options, libpod.WithName(c.Name)) options = append(options, libpod.WithName(c.Name))
} }
if c.Pod != "" { if c.Pod != "" || pod != nil {
logrus.Debugf("adding container to pod %s", c.Pod) if pod == nil {
pod, err = runtime.LookupPod(c.Pod) pod, err = runtime.LookupPod(c.Pod)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "unable to add container to pod %s", c.Pod) return nil, errors.Wrapf(err, "unable to add container to pod %s", c.Pod)
}
} }
logrus.Debugf("adding container to pod %s", c.Pod)
options = append(options, runtime.WithPod(pod)) options = append(options, runtime.WithPod(pod))
} }
if len(c.PortBindings) > 0 { if len(c.PortBindings) > 0 {

View File

@ -41,7 +41,9 @@ func (i *LibpodAPI) CreateContainer(call iopodman.VarlinkCall, config iopodman.C
return call.ReplyErrorOccurred(err.Error()) return call.ReplyErrorOccurred(err.Error())
} }
options, err := createConfig.GetContainerCreateOptions(i.Runtime) // TODO fix when doing remote client and dealing with the ability to create a container
// within a non-existing pod (i.e. --pod new:foobar)
options, err := createConfig.GetContainerCreateOptions(i.Runtime, nil)
if err != nil { if err != nil {
return call.ReplyErrorOccurred(err.Error()) return call.ReplyErrorOccurred(err.Error())
} }