some cleaning up of isolation checks, and platform information

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-02-17 18:25:38 +01:00
parent 1b3fef5333
commit 705f9b68cc
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
7 changed files with 17 additions and 33 deletions

View file

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

View file

@ -253,14 +253,11 @@ func operatingSystem() (operatingSystem string) {
} else {
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

View file

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

View file

@ -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
// containers, the process is inside the utility VM, not on the host.
if DaemonIsWindows() {
testRequires(c, IsolationIsProcess)
testRequires(c, testEnv.DaemonInfo.Isolation.IsProcess)
}
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
// containers, the process is inside the utility VM, not on the host.
if DaemonIsWindows() {
testRequires(c, IsolationIsProcess)
testRequires(c, testEnv.DaemonInfo.Isolation.IsProcess)
}
out := runSleepingContainer(c, "-d", "--restart=always")

View file

@ -4099,7 +4099,7 @@ func (s *DockerSuite) TestRunWindowsWithCPUPercent(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")
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) {
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")
assert.Assert(c, strings.Contains(strings.TrimSpace(out), "testing"))

View file

@ -142,23 +142,11 @@ func UserNamespaceInKernel() bool {
func IsPausable() bool {
if testEnv.OSType == "windows" {
return testEnv.DaemonInfo.Isolation == "hyperv"
return testEnv.DaemonInfo.Isolation.IsHyperV()
}
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
func RegistryHosting() bool {
// for now registry binary is built only if we're running inside

View file

@ -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.
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.