aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2018-09-01 12:51:00 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2018-09-07 18:18:54 +0000
commit87f90ce14abf36fbf85f6128b3024ea89a44d670 (patch)
tree7090c0a491c2f4199f8172e1d30b525fa938ed86 /cmd
parentccc4a339cd124abc668b7542a9eb838cd7d1b214 (diff)
downloadpodman-87f90ce14abf36fbf85f6128b3024ea89a44d670.tar.gz
podman-87f90ce14abf36fbf85f6128b3024ea89a44d670.tar.bz2
podman-87f90ce14abf36fbf85f6128b3024ea89a44d670.zip
Fix pod sharing for utsmode
We should be sharing cgroups namespace by default in pods uts namespace sharing was broken in pods. Create a new libpod/pkg/namespaces for handling of namespace fields in containers Signed-off-by: Daniel J Walsh <dwalsh@redhat.com> Closes: #1418 Approved by: mheon
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/create.go12
-rw-r--r--cmd/podman/parse.go138
-rw-r--r--cmd/podman/pod_create.go2
-rw-r--r--cmd/podman/shared/pod.go2
4 files changed, 9 insertions, 145 deletions
diff --git a/cmd/podman/create.go b/cmd/podman/create.go
index 20d976c0b..7a3b26c85 100644
--- a/cmd/podman/create.go
+++ b/cmd/podman/create.go
@@ -16,11 +16,11 @@ import (
ann "github.com/containers/libpod/pkg/annotations"
"github.com/containers/libpod/pkg/apparmor"
"github.com/containers/libpod/pkg/inspect"
+ "github.com/containers/libpod/pkg/namespaces"
"github.com/containers/libpod/pkg/rootless"
cc "github.com/containers/libpod/pkg/spec"
"github.com/containers/libpod/pkg/util"
libpodVersion "github.com/containers/libpod/version"
- "github.com/docker/docker/api/types/container"
"github.com/docker/docker/pkg/signal"
"github.com/docker/go-connections/nat"
"github.com/docker/go-units"
@@ -456,7 +456,7 @@ func parseCreateOpts(ctx context.Context, c *cli.Context, runtime *libpod.Runtim
if !c.IsSet("pid") && pod != nil && pod.SharesPID() {
pidModeStr = cc.POD
}
- pidMode := container.PidMode(pidModeStr)
+ pidMode := namespaces.PidMode(pidModeStr)
if !cc.Valid(string(pidMode), pidMode) {
return nil, errors.Errorf("--pid %q is not valid", c.String("pid"))
}
@@ -465,7 +465,7 @@ func parseCreateOpts(ctx context.Context, c *cli.Context, runtime *libpod.Runtim
if !c.IsSet("userns") && pod != nil && pod.SharesUser() {
usernsModeStr = cc.POD
}
- usernsMode := container.UsernsMode(usernsModeStr)
+ usernsMode := namespaces.UsernsMode(usernsModeStr)
if !cc.Valid(string(usernsMode), usernsMode) {
return nil, errors.Errorf("--userns %q is not valid", c.String("userns"))
}
@@ -474,7 +474,7 @@ func parseCreateOpts(ctx context.Context, c *cli.Context, runtime *libpod.Runtim
if !c.IsSet("uts") && pod != nil && pod.SharesUTS() {
utsModeStr = cc.POD
}
- utsMode := container.UTSMode(utsModeStr)
+ utsMode := namespaces.UTSMode(utsModeStr)
if !cc.Valid(string(utsMode), utsMode) {
return nil, errors.Errorf("--uts %q is not valid", c.String("uts"))
}
@@ -483,7 +483,7 @@ func parseCreateOpts(ctx context.Context, c *cli.Context, runtime *libpod.Runtim
if !c.IsSet("ipc") && pod != nil && pod.SharesIPC() {
ipcModeStr = cc.POD
}
- ipcMode := container.IpcMode(ipcModeStr)
+ ipcMode := namespaces.IpcMode(ipcModeStr)
if !cc.Valid(string(ipcMode), ipcMode) {
return nil, errors.Errorf("--ipc %q is not valid", ipcMode)
}
@@ -492,7 +492,7 @@ func parseCreateOpts(ctx context.Context, c *cli.Context, runtime *libpod.Runtim
netModeStr = cc.POD
}
// Make sure if network is set to container namespace, port binding is not also being asked for
- netMode := container.NetworkMode(netModeStr)
+ netMode := namespaces.NetworkMode(netModeStr)
if netMode.IsContainer() || cc.IsPod(netModeStr) {
if len(c.StringSlice("publish")) > 0 || c.Bool("publish-all") {
return nil, errors.Errorf("cannot set port bindings on an existing container network namespace")
diff --git a/cmd/podman/parse.go b/cmd/podman/parse.go
index 158a006fb..ade592ddf 100644
--- a/cmd/podman/parse.go
+++ b/cmd/podman/parse.go
@@ -239,50 +239,6 @@ func parseEnvFile(env map[string]string, filename string) error {
return scanner.Err()
}
-// NsIpc represents the container ipc stack.
-// for ipc flag
-type NsIpc string
-
-// IsPrivate indicates whether the container uses its private ipc stack.
-func (n NsIpc) IsPrivate() bool {
- return !(n.IsHost() || n.IsContainer())
-}
-
-// IsHost indicates whether the container uses the host's ipc stack.
-func (n NsIpc) IsHost() bool {
- return n == "host"
-}
-
-// IsContainer indicates whether the container uses a container's ipc stack.
-func (n NsIpc) IsContainer() bool {
- parts := strings.SplitN(string(n), ":", 2)
- return len(parts) > 1 && parts[0] == "container"
-}
-
-// Valid indicates whether the ipc stack is valid.
-func (n NsIpc) Valid() bool {
- parts := strings.Split(string(n), ":")
- switch mode := parts[0]; mode {
- case "", "host":
- case "container":
- if len(parts) != 2 || parts[1] == "" {
- return false
- }
- default:
- return false
- }
- return true
-}
-
-// Container returns the name of the container ipc stack is going to be used.
-func (n NsIpc) Container() string {
- parts := strings.SplitN(string(n), ":", 2)
- if len(parts) > 1 {
- return parts[1]
- }
- return ""
-}
-
// validateLabel validates that the specified string is a valid label, and returns it.
// Labels are in the form on key=value.
// for label flag
@@ -313,50 +269,6 @@ func parseLoggingOpts(logDriver string, logDriverOpt []string) (map[string]strin
return logOptsMap, nil
}
-// NsPid represents the pid namespace of the container.
-//for pid flag
-type NsPid string
-
-// IsPrivate indicates whether the container uses its own new pid namespace.
-func (n NsPid) IsPrivate() bool {
- return !(n.IsHost() || n.IsContainer())
-}
-
-// IsHost indicates whether the container uses the host's pid namespace.
-func (n NsPid) IsHost() bool {
- return n == "host"
-}
-
-// IsContainer indicates whether the container uses a container's pid namespace.
-func (n NsPid) IsContainer() bool {
- parts := strings.SplitN(string(n), ":", 2)
- return len(parts) > 1 && parts[0] == "container"
-}
-
-// Valid indicates whether the pid namespace is valid.
-func (n NsPid) Valid() bool {
- parts := strings.Split(string(n), ":")
- switch mode := parts[0]; mode {
- case "", "host":
- case "container":
- if len(parts) != 2 || parts[1] == "" {
- return false
- }
- default:
- return false
- }
- return true
-}
-
-// Container returns the name of the container whose pid namespace is going to be used.
-func (n NsPid) Container() string {
- parts := strings.SplitN(string(n), ":", 2)
- if len(parts) > 1 {
- return parts[1]
- }
- return ""
-}
-
// parsePortSpecs receives port specs in the format of ip:public:private/proto and parses
// these in to the internal types
// for publish, publish-all, and expose flags
@@ -567,56 +479,6 @@ func convertKVStringsToMap(values []string) map[string]string {
return result
}
-// NsUser represents userns mode in the container.
-// for userns flag
-type NsUser string
-
-// IsHost indicates whether the container uses the host's userns.
-func (n NsUser) IsHost() bool {
- return n == "host"
-}
-
-// IsPrivate indicates whether the container uses the a private userns.
-func (n NsUser) IsPrivate() bool {
- return !(n.IsHost())
-}
-
-// Valid indicates whether the userns is valid.
-func (n NsUser) Valid() bool {
- parts := strings.Split(string(n), ":")
- switch mode := parts[0]; mode {
- case "", "host":
- default:
- return false
- }
- return true
-}
-
-// NsUts represents the UTS namespace of the container.
-// for uts flag
-type NsUts string
-
-// IsPrivate indicates whether the container uses its private UTS namespace.
-func (n NsUts) IsPrivate() bool {
- return !(n.IsHost())
-}
-
-// IsHost indicates whether the container uses the host's UTS namespace.
-func (n NsUts) IsHost() bool {
- return n == "host"
-}
-
-// Valid indicates whether the UTS namespace is valid.
-func (n NsUts) Valid() bool {
- parts := strings.Split(string(n), ":")
- switch mode := parts[0]; mode {
- case "", "host":
- default:
- return false
- }
- return true
-}
-
// Takes a stringslice and converts to a uint32slice
func stringSlicetoUint32Slice(inputSlice []string) ([]uint32, error) {
var outputSlice []uint32
diff --git a/cmd/podman/pod_create.go b/cmd/podman/pod_create.go
index 488fef869..61086f890 100644
--- a/cmd/podman/pod_create.go
+++ b/cmd/podman/pod_create.go
@@ -15,7 +15,7 @@ import (
var (
// Kernel namespaces shared by default within a pod
- DefaultKernelNamespaces = "ipc,net,uts"
+ DefaultKernelNamespaces = "cgroup,ipc,net,uts"
)
var podCreateDescription = "Creates a new empty pod. The pod ID is then" +
diff --git a/cmd/podman/shared/pod.go b/cmd/podman/shared/pod.go
index 1a14b3777..badc7a837 100644
--- a/cmd/podman/shared/pod.go
+++ b/cmd/podman/shared/pod.go
@@ -70,6 +70,8 @@ func GetNamespaceOptions(ns []string) ([]libpod.PodCreateOption, error) {
var erroredOptions []libpod.PodCreateOption
for _, toShare := range ns {
switch toShare {
+ case "cgroup":
+ options = append(options, libpod.WithPodCgroups())
case "net":
options = append(options, libpod.WithPodNet())
case "mnt":