Explorar o código

daemon: add "isWindows" const

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn %!s(int64=5) %!d(string=hai) anos
pai
achega
05469b5fa2

+ 1 - 2
daemon/changes.go

@@ -2,7 +2,6 @@ package daemon // import "github.com/docker/docker/daemon"
 
 
 import (
 import (
 	"errors"
 	"errors"
-	"runtime"
 	"time"
 	"time"
 
 
 	"github.com/docker/docker/pkg/archive"
 	"github.com/docker/docker/pkg/archive"
@@ -16,7 +15,7 @@ func (daemon *Daemon) ContainerChanges(name string) ([]archive.Change, error) {
 		return nil, err
 		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")
 		return nil, errors.New("Windows does not support diff of a running container")
 	}
 	}
 
 

+ 8 - 7
daemon/cluster/cluster.go

@@ -45,6 +45,7 @@ import (
 	"net"
 	"net"
 	"os"
 	"os"
 	"path/filepath"
 	"path/filepath"
+	"runtime"
 	"sync"
 	"sync"
 	"time"
 	"time"
 
 
@@ -61,14 +62,14 @@ import (
 	"google.golang.org/grpc"
 	"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 (
 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
 	initialReconnectDelay          = 100 * time.Millisecond
 	maxReconnectDelay              = 30 * time.Second
 	maxReconnectDelay              = 30 * time.Second
 	contextPrefix                  = "com.docker.swarm"
 	contextPrefix                  = "com.docker.swarm"

+ 1 - 2
daemon/cluster/noderunner.go

@@ -4,7 +4,6 @@ import (
 	"context"
 	"context"
 	"fmt"
 	"fmt"
 	"path/filepath"
 	"path/filepath"
-	"runtime"
 	"strings"
 	"strings"
 	"sync"
 	"sync"
 	"time"
 	"time"
@@ -104,7 +103,7 @@ func (n *nodeRunner) Start(conf nodeStartConfig) error {
 
 
 func (n *nodeRunner) start(conf nodeStartConfig) error {
 func (n *nodeRunner) start(conf nodeStartConfig) error {
 	var control string
 	var control string
-	if runtime.GOOS == "windows" {
+	if isWindows {
 		control = `\\.\pipe\` + controlSocket
 		control = `\\.\pipe\` + controlSocket
 	} else {
 	} else {
 		control = filepath.Join(n.cluster.runtimeRoot, controlSocket)
 		control = filepath.Join(n.cluster.runtimeRoot, controlSocket)

+ 2 - 2
daemon/commit.go

@@ -40,7 +40,7 @@ func merge(userConf, imageConf *containertypes.Config) error {
 			imageEnvKey := strings.Split(imageEnv, "=")[0]
 			imageEnvKey := strings.Split(imageEnv, "=")[0]
 			for _, userEnv := range userConf.Env {
 			for _, userEnv := range userConf.Env {
 				userEnvKey := strings.Split(userEnv, "=")[0]
 				userEnvKey := strings.Split(userEnv, "=")[0]
-				if runtime.GOOS == "windows" {
+				if isWindows {
 					// Case insensitive environment variables on Windows
 					// Case insensitive environment variables on Windows
 					imageEnvKey = strings.ToUpper(imageEnvKey)
 					imageEnvKey = strings.ToUpper(imageEnvKey)
 					userEnvKey = strings.ToUpper(userEnvKey)
 					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
 	// 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)
 		return "", errors.Errorf("%+v does not support commit of a running container", runtime.GOOS)
 	}
 	}
 
 

+ 5 - 5
daemon/create.go

@@ -67,7 +67,7 @@ func (daemon *Daemon) containerCreate(opts createOpts) (containertypes.Container
 	} else {
 	} else {
 		// This mean scratch. On Windows, we can safely assume that this is a linux
 		// 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)
 		// 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"
 			os = "linux"
 		}
 		}
 	}
 	}
@@ -122,17 +122,17 @@ func (daemon *Daemon) create(opts createOpts) (retC *container.Container, retErr
 			os = img.OS
 			os = img.OS
 		} else {
 		} else {
 			// default to the host OS except on Windows with LCOW
 			// default to the host OS except on Windows with LCOW
-			if runtime.GOOS == "windows" && system.LCOWSupported() {
+			if isWindows && system.LCOWSupported() {
 				os = "linux"
 				os = "linux"
 			}
 			}
 		}
 		}
 		imgID = img.ID()
 		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")
 			return nil, errors.New("operating system on which parent image was created is not Windows")
 		}
 		}
 	} else {
 	} else {
-		if runtime.GOOS == "windows" {
+		if isWindows {
 			os = "linux" // 'scratch' case.
 			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
 	// 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
 	// do this on Windows as there's no effective sandbox size limit other than
 	// physical on Linux.
 	// physical on Linux.
-	if runtime.GOOS == "windows" {
+	if isWindows {
 		if container.HostConfig.StorageOpt == nil {
 		if container.HostConfig.StorageOpt == nil {
 			container.HostConfig.StorageOpt = make(map[string]string)
 			container.HostConfig.StorageOpt = make(map[string]string)
 		}
 		}

+ 6 - 4
daemon/daemon.go

@@ -74,7 +74,9 @@ import (
 )
 )
 
 
 // ContainersNamespace is the name of the namespace used for users containers
 // ContainersNamespace is the name of the namespace used for users containers
-const ContainersNamespace = "moby"
+const (
+	ContainersNamespace = "moby"
+)
 
 
 var (
 var (
 	errSystemNotSupported = errors.New("the Docker daemon is not supported on this platform")
 	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 {
 	if err != nil {
 		return nil, fmt.Errorf("Unable to get the full path to the TempDir (%s): %s", tmp, err)
 		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 := os.Stat(realTmp); err != nil && os.IsNotExist(err) {
 			if err := system.MkdirAll(realTmp, 0700); err != nil {
 			if err := system.MkdirAll(realTmp, 0700); err != nil {
 				return nil, fmt.Errorf("Unable to create the TempDir (%s): %s", realTmp, err)
 				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
 		return nil, err
 	}
 	}
 
 
-	if runtime.GOOS == "windows" {
+	if isWindows {
 		if err := system.MkdirAll(filepath.Join(config.Root, "credentialspecs"), 0); err != nil {
 		if err := system.MkdirAll(filepath.Join(config.Root, "credentialspecs"), 0); err != nil {
 			return nil, err
 			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.
 	// initialization of the layerstore through driver priority order for example.
 	d.graphDrivers = make(map[string]string)
 	d.graphDrivers = make(map[string]string)
 	layerStores := make(map[string]layer.Store)
 	layerStores := make(map[string]layer.Store)
-	if runtime.GOOS == "windows" {
+	if isWindows {
 		d.graphDrivers[runtime.GOOS] = "windowsfilter"
 		d.graphDrivers[runtime.GOOS] = "windowsfilter"
 		if system.LCOWSupported() {
 		if system.LCOWSupported() {
 			d.graphDrivers["linux"] = "lcow"
 			d.graphDrivers["linux"] = "lcow"

+ 2 - 0
daemon/daemon_unix.go

@@ -53,6 +53,8 @@ import (
 )
 )
 
 
 const (
 const (
+	isWindows = false
+
 	// DefaultShimBinary is the default shim to be used by containerd if none
 	// DefaultShimBinary is the default shim to be used by containerd if none
 	// is specified
 	// is specified
 	DefaultShimBinary = "containerd-shim"
 	DefaultShimBinary = "containerd-shim"

+ 1 - 0
daemon/daemon_windows.go

@@ -31,6 +31,7 @@ import (
 )
 )
 
 
 const (
 const (
+	isWindows            = true
 	defaultNetworkSpace  = "172.16.0.0/12"
 	defaultNetworkSpace  = "172.16.0.0/12"
 	platformSupported    = true
 	platformSupported    = true
 	windowsMinCPUShares  = 1
 	windowsMinCPUShares  = 1

+ 1 - 2
daemon/export.go

@@ -3,7 +3,6 @@ package daemon // import "github.com/docker/docker/daemon"
 import (
 import (
 	"fmt"
 	"fmt"
 	"io"
 	"io"
-	"runtime"
 
 
 	"github.com/docker/docker/container"
 	"github.com/docker/docker/container"
 	"github.com/docker/docker/errdefs"
 	"github.com/docker/docker/errdefs"
@@ -20,7 +19,7 @@ func (daemon *Daemon) ContainerExport(name string, out io.Writer) error {
 		return err
 		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")
 		return fmt.Errorf("the daemon on this operating system does not support exporting Windows containers")
 	}
 	}
 
 

+ 1 - 2
daemon/monitor.go

@@ -2,7 +2,6 @@ package daemon // import "github.com/docker/docker/daemon"
 
 
 import (
 import (
 	"context"
 	"context"
-	"runtime"
 	"strconv"
 	"strconv"
 	"time"
 	"time"
 
 
@@ -35,7 +34,7 @@ func (daemon *Daemon) ProcessEvent(id string, e libcontainerdtypes.EventType, ei
 	switch e {
 	switch e {
 	case libcontainerdtypes.EventOOM:
 	case libcontainerdtypes.EventOOM:
 		// StateOOM is Linux specific and should never be hit on Windows
 		// 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")
 			return errors.New("received StateOOM from libcontainerd on Windows. This should never happen")
 		}
 		}
 
 

+ 1 - 1
daemon/stats.go

@@ -21,7 +21,7 @@ func (daemon *Daemon) ContainerStats(ctx context.Context, prefixOrName string, c
 	// Engine API version (used for backwards compatibility)
 	// Engine API version (used for backwards compatibility)
 	apiVersion := config.Version
 	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")
 		return errors.New("API versions pre v1.21 do not support stats on Windows")
 	}
 	}