diff --git a/daemon/changes.go b/daemon/changes.go index 3a6d81107d..a2127066c9 100644 --- a/daemon/changes.go +++ b/daemon/changes.go @@ -3,6 +3,7 @@ package daemon import ( "context" "errors" + "runtime" "time" "github.com/moby/go-archive" @@ -18,7 +19,7 @@ func (daemon *Daemon) ContainerChanges(ctx context.Context, name string) ([]arch return nil, err } - if isWindows && container.State.IsRunning() { + if runtime.GOOS == "windows" && container.State.IsRunning() { return nil, errors.New("Windows does not support diff of a running container") } diff --git a/daemon/commit.go b/daemon/commit.go index 852b335ef1..237cf21933 100644 --- a/daemon/commit.go +++ b/daemon/commit.go @@ -45,7 +45,7 @@ func merge(userConf, imageConf *containertypes.Config) error { imageEnvKey, _, _ := strings.Cut(imageEnv, "=") for _, userEnv := range userConf.Env { userEnvKey, _, _ := strings.Cut(userEnv, "=") - if isWindows { + if runtime.GOOS == "windows" { // Case insensitive environment variables on Windows found = strings.EqualFold(imageEnvKey, userEnvKey) } else { @@ -131,7 +131,7 @@ func (daemon *Daemon) CreateImageFromContainer(ctx context.Context, name string, } // It is not possible to commit a running container on Windows - if isWindows && container.State.IsRunning() { + if runtime.GOOS == "windows" && container.State.IsRunning() { return "", errors.Errorf("%+v does not support commit of a running container", runtime.GOOS) } diff --git a/daemon/create.go b/daemon/create.go index 56b769b7f9..a14a28d5f2 100644 --- a/daemon/create.go +++ b/daemon/create.go @@ -188,7 +188,7 @@ func (daemon *Daemon) create(ctx context.Context, daemonCfg *config.Config, opts } platform = img.Platform() imgID = img.ID() - } else if isWindows { + } else if runtime.GOOS == "windows" { platform.OS = "linux" // 'scratch' case. } diff --git a/daemon/daemon.go b/daemon/daemon.go index a5843b39fb..8f3f3b73b2 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -886,7 +886,7 @@ func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.S if err != nil { return nil, fmt.Errorf("Unable to get the full path to the TempDir (%s): %s", tmp, err) } - if isWindows { + if runtime.GOOS == "windows" { if err := os.MkdirAll(realTmp, 0); err != nil { return nil, fmt.Errorf("Unable to create the TempDir (%s): %s", realTmp, err) } @@ -999,7 +999,7 @@ func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.S return nil, err } - if isWindows { + if runtime.GOOS == "windows" { // Note that permissions (0o700) are ignored on Windows; passing them to // show intent only. We could consider using idtools.MkdirAndChown here // to apply an ACL. @@ -1064,7 +1064,7 @@ func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.S shim string shimOpts any ) - if !isWindows { + if runtime.GOOS != "windows" { shim, shimOpts, err = rts.Get("") if err != nil { return nil, err @@ -1631,7 +1631,7 @@ func (daemon *Daemon) Mount(container *container.Container) error { // The mount path reported by the graph driver should always be trusted on Windows, since the // volume path for a given mounted layer may change over time. This should only be an error // on non-Windows operating systems. - if !isWindows { + if runtime.GOOS != "windows" { daemon.Unmount(container) driver := daemon.ImageService().StorageDriver() return fmt.Errorf("driver %s is returning inconsistent paths for container %s ('%s' then '%s')", diff --git a/daemon/daemon_unix.go b/daemon/daemon_unix.go index e7a5c445e8..f9775020c6 100644 --- a/daemon/daemon_unix.go +++ b/daemon/daemon_unix.go @@ -52,8 +52,6 @@ import ( ) const ( - isWindows = false - // These values were used to adjust the CPU-shares for older API versions, // but were not used for validation. // diff --git a/daemon/daemon_windows.go b/daemon/daemon_windows.go index 1b13a083aa..a0b77472e6 100644 --- a/daemon/daemon_windows.go +++ b/daemon/daemon_windows.go @@ -33,7 +33,6 @@ import ( ) const ( - isWindows = true windowsMinCPUShares = 1 windowsMaxCPUShares = 10000 windowsMinCPUPercent = 1 diff --git a/daemon/export.go b/daemon/export.go index 7cd4f3246f..c49f225ff5 100644 --- a/daemon/export.go +++ b/daemon/export.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "io" + "runtime" "github.com/containerd/log" "github.com/moby/go-archive" @@ -23,7 +24,7 @@ func (daemon *Daemon) ContainerExport(ctx context.Context, name string, out io.W return err } - if isWindows && ctr.ImagePlatform.OS == "windows" { + if runtime.GOOS == "windows" && ctr.ImagePlatform.OS == "windows" { return errors.New("the daemon on this operating system does not support exporting Windows containers") } diff --git a/daemon/monitor.go b/daemon/monitor.go index b2631c5796..c92665605f 100644 --- a/daemon/monitor.go +++ b/daemon/monitor.go @@ -2,6 +2,7 @@ package daemon import ( "context" + "runtime" "strconv" "strings" "time" @@ -189,7 +190,7 @@ func (daemon *Daemon) ProcessEvent(id string, e libcontainerdtypes.EventType, ei switch e { case libcontainerdtypes.EventOOM: // StateOOM is Linux specific and should never be hit on Windows - if isWindows { + if runtime.GOOS == "windows" { return errors.New("received StateOOM from libcontainerd on Windows. This should never happen") }