1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

daemon: add "isWindows" const

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2019-10-13 02:29:21 +02:00
parent 19a4fa7bf1
commit 05469b5fa2
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
11 changed files with 29 additions and 27 deletions

View file

@ -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")
}

View file

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

View file

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

View file

@ -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)
}

View file

@ -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)
}

View file

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

View file

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

View file

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

View file

@ -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")
}

View file

@ -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")
}

View file

@ -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")
}