Browse code

daemon: add "isWindows" const

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2019/10/13 09:29:21
Showing 11 changed files
... ...
@@ -2,7 +2,6 @@ package daemon // import "github.com/docker/docker/daemon"
2 2
 
3 3
 import (
4 4
 	"errors"
5
-	"runtime"
6 5
 	"time"
7 6
 
8 7
 	"github.com/docker/docker/pkg/archive"
... ...
@@ -16,7 +15,7 @@ func (daemon *Daemon) ContainerChanges(name string) ([]archive.Change, error) {
16 16
 		return nil, err
17 17
 	}
18 18
 
19
-	if runtime.GOOS == "windows" && container.IsRunning() {
19
+	if isWindows && container.IsRunning() {
20 20
 		return nil, errors.New("Windows does not support diff of a running container")
21 21
 	}
22 22
 
... ...
@@ -45,6 +45,7 @@ import (
45 45
 	"net"
46 46
 	"os"
47 47
 	"path/filepath"
48
+	"runtime"
48 49
 	"sync"
49 50
 	"time"
50 51
 
... ...
@@ -61,14 +62,14 @@ import (
61 61
 	"google.golang.org/grpc"
62 62
 )
63 63
 
64
-const swarmDirName = "swarm"
65
-const controlSocket = "control.sock"
66
-const swarmConnectTimeout = 20 * time.Second
67
-const swarmRequestTimeout = 20 * time.Second
68
-const stateFile = "docker-state.json"
69
-const defaultAddr = "0.0.0.0:2377"
70
-
71 64
 const (
65
+	swarmDirName                   = "swarm"
66
+	controlSocket                  = "control.sock"
67
+	swarmConnectTimeout            = 20 * time.Second
68
+	swarmRequestTimeout            = 20 * time.Second
69
+	stateFile                      = "docker-state.json"
70
+	defaultAddr                    = "0.0.0.0:2377"
71
+	isWindows                      = runtime.GOOS == "windows"
72 72
 	initialReconnectDelay          = 100 * time.Millisecond
73 73
 	maxReconnectDelay              = 30 * time.Second
74 74
 	contextPrefix                  = "com.docker.swarm"
... ...
@@ -4,7 +4,6 @@ import (
4 4
 	"context"
5 5
 	"fmt"
6 6
 	"path/filepath"
7
-	"runtime"
8 7
 	"strings"
9 8
 	"sync"
10 9
 	"time"
... ...
@@ -104,7 +103,7 @@ func (n *nodeRunner) Start(conf nodeStartConfig) error {
104 104
 
105 105
 func (n *nodeRunner) start(conf nodeStartConfig) error {
106 106
 	var control string
107
-	if runtime.GOOS == "windows" {
107
+	if isWindows {
108 108
 		control = `\\.\pipe\` + controlSocket
109 109
 	} else {
110 110
 		control = filepath.Join(n.cluster.runtimeRoot, controlSocket)
... ...
@@ -40,7 +40,7 @@ func merge(userConf, imageConf *containertypes.Config) error {
40 40
 			imageEnvKey := strings.Split(imageEnv, "=")[0]
41 41
 			for _, userEnv := range userConf.Env {
42 42
 				userEnvKey := strings.Split(userEnv, "=")[0]
43
-				if runtime.GOOS == "windows" {
43
+				if isWindows {
44 44
 					// Case insensitive environment variables on Windows
45 45
 					imageEnvKey = strings.ToUpper(imageEnvKey)
46 46
 					userEnvKey = strings.ToUpper(userEnvKey)
... ...
@@ -124,7 +124,7 @@ func (daemon *Daemon) CreateImageFromContainer(name string, c *backend.CreateIma
124 124
 	}
125 125
 
126 126
 	// It is not possible to commit a running container on Windows
127
-	if (runtime.GOOS == "windows") && container.IsRunning() {
127
+	if isWindows && container.IsRunning() {
128 128
 		return "", errors.Errorf("%+v does not support commit of a running container", runtime.GOOS)
129 129
 	}
130 130
 
... ...
@@ -67,7 +67,7 @@ func (daemon *Daemon) containerCreate(opts createOpts) (containertypes.Container
67 67
 	} else {
68 68
 		// This mean scratch. On Windows, we can safely assume that this is a linux
69 69
 		// container. On other platforms, it's the host OS (which it already is)
70
-		if runtime.GOOS == "windows" && system.LCOWSupported() {
70
+		if isWindows && system.LCOWSupported() {
71 71
 			os = "linux"
72 72
 		}
73 73
 	}
... ...
@@ -122,17 +122,17 @@ func (daemon *Daemon) create(opts createOpts) (retC *container.Container, retErr
122 122
 			os = img.OS
123 123
 		} else {
124 124
 			// default to the host OS except on Windows with LCOW
125
-			if runtime.GOOS == "windows" && system.LCOWSupported() {
125
+			if isWindows && system.LCOWSupported() {
126 126
 				os = "linux"
127 127
 			}
128 128
 		}
129 129
 		imgID = img.ID()
130 130
 
131
-		if runtime.GOOS == "windows" && img.OS == "linux" && !system.LCOWSupported() {
131
+		if isWindows && img.OS == "linux" && !system.LCOWSupported() {
132 132
 			return nil, errors.New("operating system on which parent image was created is not Windows")
133 133
 		}
134 134
 	} else {
135
-		if runtime.GOOS == "windows" {
135
+		if isWindows {
136 136
 			os = "linux" // 'scratch' case.
137 137
 		}
138 138
 	}
... ...
@@ -175,7 +175,7 @@ func (daemon *Daemon) create(opts createOpts) (retC *container.Container, retErr
175 175
 	// Merge the daemon's storage options if they aren't already present. We only
176 176
 	// do this on Windows as there's no effective sandbox size limit other than
177 177
 	// physical on Linux.
178
-	if runtime.GOOS == "windows" {
178
+	if isWindows {
179 179
 		if container.HostConfig.StorageOpt == nil {
180 180
 			container.HostConfig.StorageOpt = make(map[string]string)
181 181
 		}
... ...
@@ -74,7 +74,9 @@ import (
74 74
 )
75 75
 
76 76
 // ContainersNamespace is the name of the namespace used for users containers
77
-const ContainersNamespace = "moby"
77
+const (
78
+	ContainersNamespace = "moby"
79
+)
78 80
 
79 81
 var (
80 82
 	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
775 775
 	if err != nil {
776 776
 		return nil, fmt.Errorf("Unable to get the full path to the TempDir (%s): %s", tmp, err)
777 777
 	}
778
-	if runtime.GOOS == "windows" {
778
+	if isWindows {
779 779
 		if _, err := os.Stat(realTmp); err != nil && os.IsNotExist(err) {
780 780
 			if err := system.MkdirAll(realTmp, 0700); err != nil {
781 781
 				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
846 846
 		return nil, err
847 847
 	}
848 848
 
849
-	if runtime.GOOS == "windows" {
849
+	if isWindows {
850 850
 		if err := system.MkdirAll(filepath.Join(config.Root, "credentialspecs"), 0); err != nil {
851 851
 			return nil, err
852 852
 		}
... ...
@@ -860,7 +862,7 @@ func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.S
860 860
 	// initialization of the layerstore through driver priority order for example.
861 861
 	d.graphDrivers = make(map[string]string)
862 862
 	layerStores := make(map[string]layer.Store)
863
-	if runtime.GOOS == "windows" {
863
+	if isWindows {
864 864
 		d.graphDrivers[runtime.GOOS] = "windowsfilter"
865 865
 		if system.LCOWSupported() {
866 866
 			d.graphDrivers["linux"] = "lcow"
... ...
@@ -53,6 +53,8 @@ import (
53 53
 )
54 54
 
55 55
 const (
56
+	isWindows = false
57
+
56 58
 	// DefaultShimBinary is the default shim to be used by containerd if none
57 59
 	// is specified
58 60
 	DefaultShimBinary = "containerd-shim"
... ...
@@ -31,6 +31,7 @@ import (
31 31
 )
32 32
 
33 33
 const (
34
+	isWindows            = true
34 35
 	defaultNetworkSpace  = "172.16.0.0/12"
35 36
 	platformSupported    = true
36 37
 	windowsMinCPUShares  = 1
... ...
@@ -3,7 +3,6 @@ package daemon // import "github.com/docker/docker/daemon"
3 3
 import (
4 4
 	"fmt"
5 5
 	"io"
6
-	"runtime"
7 6
 
8 7
 	"github.com/docker/docker/container"
9 8
 	"github.com/docker/docker/errdefs"
... ...
@@ -20,7 +19,7 @@ func (daemon *Daemon) ContainerExport(name string, out io.Writer) error {
20 20
 		return err
21 21
 	}
22 22
 
23
-	if runtime.GOOS == "windows" && container.OS == "windows" {
23
+	if isWindows && container.OS == "windows" {
24 24
 		return fmt.Errorf("the daemon on this operating system does not support exporting Windows containers")
25 25
 	}
26 26
 
... ...
@@ -2,7 +2,6 @@ package daemon // import "github.com/docker/docker/daemon"
2 2
 
3 3
 import (
4 4
 	"context"
5
-	"runtime"
6 5
 	"strconv"
7 6
 	"time"
8 7
 
... ...
@@ -35,7 +34,7 @@ func (daemon *Daemon) ProcessEvent(id string, e libcontainerdtypes.EventType, ei
35 35
 	switch e {
36 36
 	case libcontainerdtypes.EventOOM:
37 37
 		// StateOOM is Linux specific and should never be hit on Windows
38
-		if runtime.GOOS == "windows" {
38
+		if isWindows {
39 39
 			return errors.New("received StateOOM from libcontainerd on Windows. This should never happen")
40 40
 		}
41 41
 
... ...
@@ -21,7 +21,7 @@ func (daemon *Daemon) ContainerStats(ctx context.Context, prefixOrName string, c
21 21
 	// Engine API version (used for backwards compatibility)
22 22
 	apiVersion := config.Version
23 23
 
24
-	if runtime.GOOS == "windows" && versions.LessThan(apiVersion, "1.21") {
24
+	if isWindows && versions.LessThan(apiVersion, "1.21") {
25 25
 		return errors.New("API versions pre v1.21 do not support stats on Windows")
26 26
 	}
27 27