From 8b9b493b539ee2985b0f4470d62d456e2288d161 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Wed, 19 Sep 2018 10:12:04 +0200 Subject: spec: refactor ns modes to a common interface Signed-off-by: Giuseppe Scrivano Closes: #1507 Approved by: rhatdan --- pkg/namespaces/namespaces.go | 14 ++++++++++++-- pkg/spec/createconfig.go | 4 ++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/pkg/namespaces/namespaces.go b/pkg/namespaces/namespaces.go index 1bdb2b00d..bee833fa9 100644 --- a/pkg/namespaces/namespaces.go +++ b/pkg/namespaces/namespaces.go @@ -28,6 +28,16 @@ func (n UsernsMode) Valid() bool { return true } +// IsContainer indicates whether container uses a container userns. +func (n UsernsMode) IsContainer() bool { + return false +} + +// Container is the id of the container which network this container is connected to. +func (n UsernsMode) Container() string { + return "" +} + // UTSMode represents the UTS namespace of the container. type UTSMode string @@ -191,8 +201,8 @@ func (n NetworkMode) IsContainer() bool { return len(parts) > 1 && parts[0] == "container" } -// ConnectedContainer is the id of the container which network this container is connected to. -func (n NetworkMode) ConnectedContainer() string { +// Container is the id of the container which network this container is connected to. +func (n NetworkMode) Container() string { parts := strings.SplitN(string(n), ":", 2) if len(parts) > 1 { return parts[1] diff --git a/pkg/spec/createconfig.go b/pkg/spec/createconfig.go index 328e3763c..518ea5731 100644 --- a/pkg/spec/createconfig.go +++ b/pkg/spec/createconfig.go @@ -374,9 +374,9 @@ func (c *CreateConfig) GetContainerCreateOptions(runtime *libpod.Runtime) ([]lib if IsNS(string(c.NetMode)) { // pass } else if c.NetMode.IsContainer() { - connectedCtr, err := c.Runtime.LookupContainer(c.NetMode.ConnectedContainer()) + connectedCtr, err := c.Runtime.LookupContainer(c.NetMode.Container()) if err != nil { - return nil, errors.Wrapf(err, "container %q not found", c.NetMode.ConnectedContainer()) + return nil, errors.Wrapf(err, "container %q not found", c.NetMode.Container()) } options = append(options, libpod.WithNetNSFrom(connectedCtr)) } else if !c.NetMode.IsHost() && !c.NetMode.IsNone() { -- cgit v1.2.3-54-g00ecf