Pārlūkot izejas kodu

some cleaning up of isolation checks, and platform information

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 3 gadi atpakaļ
vecāks
revīzija
705f9b68cc

+ 5 - 5
daemon/daemon_windows.go

@@ -550,13 +550,13 @@ func (daemon *Daemon) stats(c *container.Container) (*types.StatsJSON, error) {
 // setDefaultIsolation determine the default isolation mode for the
 // setDefaultIsolation determine the default isolation mode for the
 // daemon to run in. This is only applicable on Windows
 // daemon to run in. This is only applicable on Windows
 func (daemon *Daemon) setDefaultIsolation() error {
 func (daemon *Daemon) setDefaultIsolation() error {
-	daemon.defaultIsolation = containertypes.Isolation("process")
-
 	// On client SKUs, default to Hyper-V. @engine maintainers. This
 	// On client SKUs, default to Hyper-V. @engine maintainers. This
 	// should not be removed. Ping Microsoft folks is there are PRs to
 	// should not be removed. Ping Microsoft folks is there are PRs to
 	// to change this.
 	// to change this.
 	if system.IsWindowsClient() {
 	if system.IsWindowsClient() {
-		daemon.defaultIsolation = containertypes.Isolation("hyperv")
+		daemon.defaultIsolation = containertypes.IsolationHyperV
+	} else {
+		daemon.defaultIsolation = containertypes.IsolationProcess
 	}
 	}
 	for _, option := range daemon.configStore.ExecOptions {
 	for _, option := range daemon.configStore.ExecOptions {
 		key, val, err := parsers.ParseKeyValueOpt(option)
 		key, val, err := parsers.ParseKeyValueOpt(option)
@@ -571,10 +571,10 @@ func (daemon *Daemon) setDefaultIsolation() error {
 				return fmt.Errorf("Invalid exec-opt value for 'isolation':'%s'", val)
 				return fmt.Errorf("Invalid exec-opt value for 'isolation':'%s'", val)
 			}
 			}
 			if containertypes.Isolation(val).IsHyperV() {
 			if containertypes.Isolation(val).IsHyperV() {
-				daemon.defaultIsolation = containertypes.Isolation("hyperv")
+				daemon.defaultIsolation = containertypes.IsolationHyperV
 			}
 			}
 			if containertypes.Isolation(val).IsProcess() {
 			if containertypes.Isolation(val).IsProcess() {
-				daemon.defaultIsolation = containertypes.Isolation("process")
+				daemon.defaultIsolation = containertypes.IsolationProcess
 			}
 			}
 		default:
 		default:
 			return fmt.Errorf("Unrecognised exec-opt '%s'\n", key)
 			return fmt.Errorf("Unrecognised exec-opt '%s'\n", key)

+ 5 - 8
daemon/info.go

@@ -253,14 +253,11 @@ func operatingSystem() (operatingSystem string) {
 	} else {
 	} else {
 		operatingSystem = s
 		operatingSystem = s
 	}
 	}
-	// Don't do containerized check on Windows
-	if runtime.GOOS != "windows" {
-		if inContainer, err := operatingsystem.IsContainerized(); err != nil {
-			logrus.Errorf("Could not determine if daemon is containerized: %v", err)
-			operatingSystem += " (error determining if containerized)"
-		} else if inContainer {
-			operatingSystem += " (containerized)"
-		}
+	if inContainer, err := operatingsystem.IsContainerized(); err != nil {
+		logrus.Errorf("Could not determine if daemon is containerized: %v", err)
+		operatingSystem += " (error determining if containerized)"
+	} else if inContainer {
+		operatingSystem += " (containerized)"
 	}
 	}
 
 
 	return operatingSystem
 	return operatingSystem

+ 1 - 1
integration-cli/docker_cli_create_test.go

@@ -303,7 +303,7 @@ func (s *DockerSuite) TestCreateWithWorkdir(c *testing.T) {
 	// Windows does not create the workdir until the container is started
 	// Windows does not create the workdir until the container is started
 	if testEnv.OSType == "windows" {
 	if testEnv.OSType == "windows" {
 		dockerCmd(c, "start", name)
 		dockerCmd(c, "start", name)
-		if IsolationIsHyperv() {
+		if testEnv.DaemonInfo.Isolation.IsHyperV() {
 			// Hyper-V isolated containers do not allow file-operations on a
 			// Hyper-V isolated containers do not allow file-operations on a
 			// running container. This test currently uses `docker cp` to verify
 			// running container. This test currently uses `docker cp` to verify
 			// that the WORKDIR was automatically created, which cannot be done
 			// that the WORKDIR was automatically created, which cannot be done

+ 2 - 2
integration-cli/docker_cli_restart_test.go

@@ -171,7 +171,7 @@ func (s *DockerSuite) TestRestartContainerSuccess(c *testing.T) {
 	// such that it assumes there is a host process to kill. In Hyper-V
 	// such that it assumes there is a host process to kill. In Hyper-V
 	// containers, the process is inside the utility VM, not on the host.
 	// containers, the process is inside the utility VM, not on the host.
 	if DaemonIsWindows() {
 	if DaemonIsWindows() {
-		testRequires(c, IsolationIsProcess)
+		testRequires(c, testEnv.DaemonInfo.Isolation.IsProcess)
 	}
 	}
 
 
 	out := runSleepingContainer(c, "-d", "--restart=always")
 	out := runSleepingContainer(c, "-d", "--restart=always")
@@ -247,7 +247,7 @@ func (s *DockerSuite) TestRestartPolicyAfterRestart(c *testing.T) {
 	// such that it assumes there is a host process to kill. In Hyper-V
 	// such that it assumes there is a host process to kill. In Hyper-V
 	// containers, the process is inside the utility VM, not on the host.
 	// containers, the process is inside the utility VM, not on the host.
 	if DaemonIsWindows() {
 	if DaemonIsWindows() {
-		testRequires(c, IsolationIsProcess)
+		testRequires(c, testEnv.DaemonInfo.Isolation.IsProcess)
 	}
 	}
 
 
 	out := runSleepingContainer(c, "-d", "--restart=always")
 	out := runSleepingContainer(c, "-d", "--restart=always")

+ 2 - 2
integration-cli/docker_cli_run_test.go

@@ -4099,7 +4099,7 @@ func (s *DockerSuite) TestRunWindowsWithCPUPercent(c *testing.T) {
 }
 }
 
 
 func (s *DockerSuite) TestRunProcessIsolationWithCPUCountCPUSharesAndCPUPercent(c *testing.T) {
 func (s *DockerSuite) TestRunProcessIsolationWithCPUCountCPUSharesAndCPUPercent(c *testing.T) {
-	testRequires(c, IsolationIsProcess)
+	testRequires(c, DaemonIsWindows, testEnv.DaemonInfo.Isolation.IsProcess)
 
 
 	out, _ := dockerCmd(c, "run", "--cpu-count=1", "--cpu-shares=1000", "--cpu-percent=80", "--name", "test", "busybox", "echo", "testing")
 	out, _ := dockerCmd(c, "run", "--cpu-count=1", "--cpu-shares=1000", "--cpu-percent=80", "--name", "test", "busybox", "echo", "testing")
 	assert.Assert(c, strings.Contains(strings.TrimSpace(out), "WARNING: Conflicting options: CPU count takes priority over CPU shares on Windows Server Containers. CPU shares discarded"))
 	assert.Assert(c, strings.Contains(strings.TrimSpace(out), "WARNING: Conflicting options: CPU count takes priority over CPU shares on Windows Server Containers. CPU shares discarded"))
@@ -4116,7 +4116,7 @@ func (s *DockerSuite) TestRunProcessIsolationWithCPUCountCPUSharesAndCPUPercent(
 }
 }
 
 
 func (s *DockerSuite) TestRunHypervIsolationWithCPUCountCPUSharesAndCPUPercent(c *testing.T) {
 func (s *DockerSuite) TestRunHypervIsolationWithCPUCountCPUSharesAndCPUPercent(c *testing.T) {
-	testRequires(c, IsolationIsHyperv)
+	testRequires(c, DaemonIsWindows, testEnv.DaemonInfo.Isolation.IsHyperV)
 
 
 	out, _ := dockerCmd(c, "run", "--cpu-count=1", "--cpu-shares=1000", "--cpu-percent=80", "--name", "test", "busybox", "echo", "testing")
 	out, _ := dockerCmd(c, "run", "--cpu-count=1", "--cpu-shares=1000", "--cpu-percent=80", "--name", "test", "busybox", "echo", "testing")
 	assert.Assert(c, strings.Contains(strings.TrimSpace(out), "testing"))
 	assert.Assert(c, strings.Contains(strings.TrimSpace(out), "testing"))

+ 1 - 13
integration-cli/requirements_test.go

@@ -142,23 +142,11 @@ func UserNamespaceInKernel() bool {
 
 
 func IsPausable() bool {
 func IsPausable() bool {
 	if testEnv.OSType == "windows" {
 	if testEnv.OSType == "windows" {
-		return testEnv.DaemonInfo.Isolation == "hyperv"
+		return testEnv.DaemonInfo.Isolation.IsHyperV()
 	}
 	}
 	return true
 	return true
 }
 }
 
 
-func IsolationIs(expectedIsolation string) bool {
-	return testEnv.OSType == "windows" && string(testEnv.DaemonInfo.Isolation) == expectedIsolation
-}
-
-func IsolationIsHyperv() bool {
-	return IsolationIs("hyperv")
-}
-
-func IsolationIsProcess() bool {
-	return IsolationIs("process")
-}
-
 // RegistryHosting returns whether the host can host a registry (v2) or not
 // RegistryHosting returns whether the host can host a registry (v2) or not
 func RegistryHosting() bool {
 func RegistryHosting() bool {
 	// for now registry binary is built only if we're running inside
 	// for now registry binary is built only if we're running inside

+ 1 - 2
pkg/parsers/operatingsystem/operatingsystem_windows.go

@@ -52,8 +52,7 @@ func withCurrentVersionRegistryKey(f func(registry.Key) (string, error)) (string
 
 
 // GetOperatingSystemVersion gets the version of the current operating system, as a string.
 // GetOperatingSystemVersion gets the version of the current operating system, as a string.
 func GetOperatingSystemVersion() (string, error) {
 func GetOperatingSystemVersion() (string, error) {
-	version := osversion.Get()
-	return fmt.Sprintf("%d.%d.%d", version.MajorVersion, version.MinorVersion, version.Build), nil
+	return osversion.Get().ToString(), nil
 }
 }
 
 
 // IsContainerized returns true if we are running inside a container.
 // IsContainerized returns true if we are running inside a container.