diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2019-01-12 07:20:36 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-12 07:20:36 -0800 |
commit | a08da3768255c1155aa14b73bf17d34e5214c568 (patch) | |
tree | 3f4f1272973d5cf8b45cbc04873d1a3d3a5952d6 | |
parent | 5c86efb28976938ad77fcc0f677e0842d06b65b5 (diff) | |
parent | e10baba32673d4b6d9ada129941428fc8f8304eb (diff) | |
download | podman-a08da3768255c1155aa14b73bf17d34e5214c568.tar.gz podman-a08da3768255c1155aa14b73bf17d34e5214c568.tar.bz2 podman-a08da3768255c1155aa14b73bf17d34e5214c568.zip |
Merge pull request #2145 from baude/playcontainerintopod
podman play kube: add containers to pod
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | cmd/podman/create.go | 7 | ||||
-rw-r--r-- | cmd/podman/play_kube.go | 2 | ||||
-rw-r--r-- | pkg/spec/createconfig.go | 15 | ||||
-rw-r--r-- | pkg/varlinkapi/containers_create.go | 4 |
5 files changed, 16 insertions, 14 deletions
@@ -1,6 +1,6 @@ GO ?= go DESTDIR ?= / -EPOCH_TEST_COMMIT ?= e1732a5213147e3c0b7bf60b55a332c3720ecb4b +EPOCH_TEST_COMMIT ?= bd40dcfc2bc7c9014ea1f33482fb63aacbcdfe87 HEAD ?= HEAD CHANGELOG_BASE ?= HEAD~ CHANGELOG_TARGET ?= HEAD diff --git a/cmd/podman/create.go b/cmd/podman/create.go index 87fa18e47..1aa3425a5 100644 --- a/cmd/podman/create.go +++ b/cmd/podman/create.go @@ -145,7 +145,7 @@ func createContainer(c *cli.Context, runtime *libpod.Runtime) (*libpod.Container return nil, nil, err } - ctr, err := createContainerFromCreateConfig(runtime, createConfig, ctx) + ctr, err := createContainerFromCreateConfig(runtime, createConfig, ctx, nil) if err != nil { return nil, nil, err } @@ -832,17 +832,16 @@ func joinOrCreateRootlessUserNamespace(createConfig *cc.CreateConfig, runtime *l 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) if err != nil { return nil, err } - options, err := createConfig.GetContainerCreateOptions(r) + options, err := createConfig.GetContainerCreateOptions(r, pod) if err != nil { return nil, err } - became, ret, err := joinOrCreateRootlessUserNamespace(createConfig, r) if err != nil { return nil, err diff --git a/cmd/podman/play_kube.go b/cmd/podman/play_kube.go index f165c5f0f..2ce2e21bb 100644 --- a/cmd/podman/play_kube.go +++ b/cmd/podman/play_kube.go @@ -154,7 +154,7 @@ func playKubeYAMLCmd(c *cli.Context) error { if err != nil { return err } - ctr, err := createContainerFromCreateConfig(runtime, createConfig, ctx) + ctr, err := createContainerFromCreateConfig(runtime, createConfig, ctx, pod) if err != nil { return err } diff --git a/pkg/spec/createconfig.go b/pkg/spec/createconfig.go index 87fce7e2e..632d60b55 100644 --- a/pkg/spec/createconfig.go +++ b/pkg/spec/createconfig.go @@ -341,10 +341,9 @@ func (c *CreateConfig) createExitCommand() []string { } // 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 portBindings []ocicni.PortMapping - var pod *libpod.Pod var err error if c.Interactive { @@ -358,12 +357,14 @@ func (c *CreateConfig) GetContainerCreateOptions(runtime *libpod.Runtime) ([]lib logrus.Debugf("appending name %s", c.Name) options = append(options, libpod.WithName(c.Name)) } - if c.Pod != "" { - logrus.Debugf("adding container to pod %s", c.Pod) - pod, err = runtime.LookupPod(c.Pod) - if err != nil { - return nil, errors.Wrapf(err, "unable to add container to pod %s", c.Pod) + if c.Pod != "" || pod != nil { + if pod == nil { + pod, err = runtime.LookupPod(c.Pod) + if err != nil { + 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)) } if len(c.PortBindings) > 0 { diff --git a/pkg/varlinkapi/containers_create.go b/pkg/varlinkapi/containers_create.go index 63bc93686..d72eaeb18 100644 --- a/pkg/varlinkapi/containers_create.go +++ b/pkg/varlinkapi/containers_create.go @@ -41,7 +41,9 @@ func (i *LibpodAPI) CreateContainer(call iopodman.VarlinkCall, config iopodman.C 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 { return call.ReplyErrorOccurred(err.Error()) } |