daemon: address some minor linting issues and nits

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2019-08-09 12:30:18 +02:00
parent e6d949b9e7
commit eeef12f469
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
2 changed files with 12 additions and 8 deletions

View file

@ -290,7 +290,7 @@ func WithNamespaces(daemon *Daemon, c *container.Container) coci.SpecOpts {
setNamespace(s, nsUser) setNamespace(s, nsUser)
} }
case ipcMode.IsHost(): case ipcMode.IsHost():
oci.RemoveNamespace(s, specs.LinuxNamespaceType("ipc")) oci.RemoveNamespace(s, "ipc")
case ipcMode.IsEmpty(): case ipcMode.IsEmpty():
// A container was created by an older version of the daemon. // A container was created by an older version of the daemon.
// The default behavior used to be what is now called "shareable". // The default behavior used to be what is now called "shareable".
@ -304,28 +304,32 @@ func WithNamespaces(daemon *Daemon, c *container.Container) coci.SpecOpts {
// pid // pid
if c.HostConfig.PidMode.IsContainer() { if c.HostConfig.PidMode.IsContainer() {
ns := specs.LinuxNamespace{Type: "pid"}
pc, err := daemon.getPidContainer(c) pc, err := daemon.getPidContainer(c)
if err != nil { if err != nil {
return err return err
} }
ns.Path = fmt.Sprintf("/proc/%d/ns/pid", pc.State.GetPID()) ns := specs.LinuxNamespace{
Type: "pid",
Path: fmt.Sprintf("/proc/%d/ns/pid", pc.State.GetPID()),
}
setNamespace(s, ns) setNamespace(s, ns)
if userNS { if userNS {
// to share a PID namespace, they must also share a user namespace // to share a PID namespace, they must also share a user namespace
nsUser := specs.LinuxNamespace{Type: "user"} nsUser := specs.LinuxNamespace{
nsUser.Path = fmt.Sprintf("/proc/%d/ns/user", pc.State.GetPID()) Type: "user",
Path: fmt.Sprintf("/proc/%d/ns/user", pc.State.GetPID()),
}
setNamespace(s, nsUser) setNamespace(s, nsUser)
} }
} else if c.HostConfig.PidMode.IsHost() { } else if c.HostConfig.PidMode.IsHost() {
oci.RemoveNamespace(s, specs.LinuxNamespaceType("pid")) oci.RemoveNamespace(s, "pid")
} else { } else {
ns := specs.LinuxNamespace{Type: "pid"} ns := specs.LinuxNamespace{Type: "pid"}
setNamespace(s, ns) setNamespace(s, ns)
} }
// uts // uts
if c.HostConfig.UTSMode.IsHost() { if c.HostConfig.UTSMode.IsHost() {
oci.RemoveNamespace(s, specs.LinuxNamespaceType("uts")) oci.RemoveNamespace(s, "uts")
s.Hostname = "" s.Hostname = ""
} }

View file

@ -54,7 +54,7 @@ func setupFakeDaemon(t *testing.T, c *container.Container) *Daemon {
} }
func cleanupFakeContainer(c *container.Container) { func cleanupFakeContainer(c *container.Container) {
os.RemoveAll(c.Root) _ = os.RemoveAll(c.Root)
} }
// TestTmpfsDevShmNoDupMount checks that a user-specified /dev/shm tmpfs // TestTmpfsDevShmNoDupMount checks that a user-specified /dev/shm tmpfs