diff --git a/daemon/changes.go b/daemon/changes.go index 70b3f6b943..09f27b2161 100644 --- a/daemon/changes.go +++ b/daemon/changes.go @@ -2,7 +2,6 @@ package daemon // import "github.com/docker/docker/daemon" import ( "errors" - "runtime" "time" "github.com/docker/docker/pkg/archive" @@ -16,7 +15,7 @@ func (daemon *Daemon) ContainerChanges(name string) ([]archive.Change, error) { return nil, err } - if runtime.GOOS == "windows" && container.IsRunning() { + if isWindows && container.IsRunning() { return nil, errors.New("Windows does not support diff of a running container") } diff --git a/daemon/cluster/cluster.go b/daemon/cluster/cluster.go index c5c27a4f51..d3532a8736 100644 --- a/daemon/cluster/cluster.go +++ b/daemon/cluster/cluster.go @@ -45,6 +45,7 @@ import ( "net" "os" "path/filepath" + "runtime" "sync" "time" @@ -61,14 +62,14 @@ import ( "google.golang.org/grpc" ) -const swarmDirName = "swarm" -const controlSocket = "control.sock" -const swarmConnectTimeout = 20 * time.Second -const swarmRequestTimeout = 20 * time.Second -const stateFile = "docker-state.json" -const defaultAddr = "0.0.0.0:2377" - const ( + swarmDirName = "swarm" + controlSocket = "control.sock" + swarmConnectTimeout = 20 * time.Second + swarmRequestTimeout = 20 * time.Second + stateFile = "docker-state.json" + defaultAddr = "0.0.0.0:2377" + isWindows = runtime.GOOS == "windows" initialReconnectDelay = 100 * time.Millisecond maxReconnectDelay = 30 * time.Second contextPrefix = "com.docker.swarm" diff --git a/daemon/cluster/noderunner.go b/daemon/cluster/noderunner.go index 508ade3306..5246b14a1d 100644 --- a/daemon/cluster/noderunner.go +++ b/daemon/cluster/noderunner.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "path/filepath" - "runtime" "strings" "sync" "time" @@ -104,7 +103,7 @@ func (n *nodeRunner) Start(conf nodeStartConfig) error { func (n *nodeRunner) start(conf nodeStartConfig) error { var control string - if runtime.GOOS == "windows" { + if isWindows { control = `\\.\pipe\` + controlSocket } else { control = filepath.Join(n.cluster.runtimeRoot, controlSocket) diff --git a/daemon/commit.go b/daemon/commit.go index f20290f47c..302e9a95d6 100644 --- a/daemon/commit.go +++ b/daemon/commit.go @@ -40,7 +40,7 @@ func merge(userConf, imageConf *containertypes.Config) error { imageEnvKey := strings.Split(imageEnv, "=")[0] for _, userEnv := range userConf.Env { userEnvKey := strings.Split(userEnv, "=")[0] - if runtime.GOOS == "windows" { + if isWindows { // Case insensitive environment variables on Windows imageEnvKey = strings.ToUpper(imageEnvKey) userEnvKey = strings.ToUpper(userEnvKey) @@ -124,7 +124,7 @@ func (daemon *Daemon) CreateImageFromContainer(name string, c *backend.CreateIma } // It is not possible to commit a running container on Windows - if (runtime.GOOS == "windows") && container.IsRunning() { + if isWindows && container.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 f9db0ca834..7310c7cf1d 100644 --- a/daemon/create.go +++ b/daemon/create.go @@ -67,7 +67,7 @@ func (daemon *Daemon) containerCreate(opts createOpts) (containertypes.Container } else { // This mean scratch. On Windows, we can safely assume that this is a linux // container. On other platforms, it's the host OS (which it already is) - if runtime.GOOS == "windows" && system.LCOWSupported() { + if isWindows && system.LCOWSupported() { os = "linux" } } @@ -122,17 +122,17 @@ func (daemon *Daemon) create(opts createOpts) (retC *container.Container, retErr os = img.OS } else { // default to the host OS except on Windows with LCOW - if runtime.GOOS == "windows" && system.LCOWSupported() { + if isWindows && system.LCOWSupported() { os = "linux" } } imgID = img.ID() - if runtime.GOOS == "windows" && img.OS == "linux" && !system.LCOWSupported() { + if isWindows && img.OS == "linux" && !system.LCOWSupported() { return nil, errors.New("operating system on which parent image was created is not Windows") } } else { - if runtime.GOOS == "windows" { + if isWindows { os = "linux" // 'scratch' case. } } @@ -175,7 +175,7 @@ func (daemon *Daemon) create(opts createOpts) (retC *container.Container, retErr // Merge the daemon's storage options if they aren't already present. We only // do this on Windows as there's no effective sandbox size limit other than // physical on Linux. - if runtime.GOOS == "windows" { + if isWindows { if container.HostConfig.StorageOpt == nil { container.HostConfig.StorageOpt = make(map[string]string) } diff --git a/daemon/daemon.go b/daemon/daemon.go index 6b3ab259ce..fa989f830c 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -74,7 +74,9 @@ import ( ) // ContainersNamespace is the name of the namespace used for users containers -const ContainersNamespace = "moby" +const ( + ContainersNamespace = "moby" +) var ( errSystemNotSupported = errors.New("the Docker daemon is not supported on this platform") @@ -775,7 +777,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 runtime.GOOS == "windows" { + if isWindows { if _, err := os.Stat(realTmp); err != nil && os.IsNotExist(err) { if err := system.MkdirAll(realTmp, 0700); err != nil { return nil, fmt.Errorf("Unable to create the TempDir (%s): %s", realTmp, err) @@ -846,7 +848,7 @@ func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.S return nil, err } - if runtime.GOOS == "windows" { + if isWindows { if err := system.MkdirAll(filepath.Join(config.Root, "credentialspecs"), 0); err != nil { return nil, err } @@ -860,7 +862,7 @@ func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.S // initialization of the layerstore through driver priority order for example. d.graphDrivers = make(map[string]string) layerStores := make(map[string]layer.Store) - if runtime.GOOS == "windows" { + if isWindows { d.graphDrivers[runtime.GOOS] = "windowsfilter" if system.LCOWSupported() { d.graphDrivers["linux"] = "lcow" diff --git a/daemon/daemon_unix.go b/daemon/daemon_unix.go index f2d1fc932f..3c1f3e1c0b 100644 --- a/daemon/daemon_unix.go +++ b/daemon/daemon_unix.go @@ -53,6 +53,8 @@ import ( ) const ( + isWindows = false + // DefaultShimBinary is the default shim to be used by containerd if none // is specified DefaultShimBinary = "containerd-shim" diff --git a/daemon/daemon_windows.go b/daemon/daemon_windows.go index b39db59ac0..49d2d3055e 100644 --- a/daemon/daemon_windows.go +++ b/daemon/daemon_windows.go @@ -31,6 +31,7 @@ import ( ) const ( + isWindows = true defaultNetworkSpace = "172.16.0.0/12" platformSupported = true windowsMinCPUShares = 1 diff --git a/daemon/export.go b/daemon/export.go index 01593f4e8a..d29b1de614 100644 --- a/daemon/export.go +++ b/daemon/export.go @@ -3,7 +3,6 @@ package daemon // import "github.com/docker/docker/daemon" import ( "fmt" "io" - "runtime" "github.com/docker/docker/container" "github.com/docker/docker/errdefs" @@ -20,7 +19,7 @@ func (daemon *Daemon) ContainerExport(name string, out io.Writer) error { return err } - if runtime.GOOS == "windows" && container.OS == "windows" { + if isWindows && container.OS == "windows" { return fmt.Errorf("the daemon on this operating system does not support exporting Windows containers") } diff --git a/daemon/monitor.go b/daemon/monitor.go index b8d32c39a9..68c6dbeb8b 100644 --- a/daemon/monitor.go +++ b/daemon/monitor.go @@ -2,7 +2,6 @@ package daemon // import "github.com/docker/docker/daemon" import ( "context" - "runtime" "strconv" "time" @@ -35,7 +34,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 runtime.GOOS == "windows" { + if isWindows { return errors.New("received StateOOM from libcontainerd on Windows. This should never happen") } diff --git a/daemon/stats.go b/daemon/stats.go index 2e770a5b19..006d2223b2 100644 --- a/daemon/stats.go +++ b/daemon/stats.go @@ -21,7 +21,7 @@ func (daemon *Daemon) ContainerStats(ctx context.Context, prefixOrName string, c // Engine API version (used for backwards compatibility) apiVersion := config.Version - if runtime.GOOS == "windows" && versions.LessThan(apiVersion, "1.21") { + if isWindows && versions.LessThan(apiVersion, "1.21") { return errors.New("API versions pre v1.21 do not support stats on Windows") }