Преглед на файлове

daemon: WithNamespaces(): remove redundant "if"

This check was originally used to only validate the mode if it was set to
a non-empty value (see commit 072400fc4b8d6a38a2007d41072b765666a4c288), but
validation was made unconditional in c3d7a0c6033a2764dd85c3863809ac498ef129f2.

Given that a `CgroupnsMode` can't be both [`CgroupnsMode.IsEmpty()`][1]
and [`CgroupnsMode.IsPrivate`][2], we can remove the extra check.

[1]: https://github.com/moby/moby/blob/e0da5cb9291982a4c7b3c6b0642eeced4ba9f8ac/api/types/container/hostconfig.go#L33-L36
[2]: https://github.com/moby/moby/blob/e0da5cb9291982a4c7b3c6b0642eeced4ba9f8ac/api/types/container/hostconfig.go#L23-L26

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn преди 1 година
родител
ревизия
bd5d6480e7
променени са 1 файла, в които са добавени 4 реда и са изтрити 6 реда
  1. 4 6
      daemon/oci_linux.go

+ 4 - 6
daemon/oci_linux.go

@@ -362,12 +362,10 @@ func WithNamespaces(daemon *Daemon, c *container.Container) coci.SpecOpts {
 		if !c.HostConfig.CgroupnsMode.Valid() {
 			return errdefs.InvalidParameter(errors.Errorf("invalid cgroup namespace mode: %v", c.HostConfig.CgroupnsMode))
 		}
-		if !c.HostConfig.CgroupnsMode.IsEmpty() {
-			if c.HostConfig.CgroupnsMode.IsPrivate() {
-				setNamespace(s, specs.LinuxNamespace{
-					Type: specs.CgroupNamespace,
-				})
-			}
+		if c.HostConfig.CgroupnsMode.IsPrivate() {
+			setNamespace(s, specs.LinuxNamespace{
+				Type: specs.CgroupNamespace,
+			})
 		}
 
 		return nil