Skip to content

Commit d4b0732

Browse files
author
John Howard
committed
Windows: Fix 'isolation'
Signed-off-by: John Howard <jhoward@microsoft.com>
1 parent 2658341 commit d4b0732

File tree

11 files changed

+42
-29
lines changed

11 files changed

+42
-29
lines changed

api/client/build.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
6666
flCgroupParent := cmd.String([]string{"-cgroup-parent"}, "", "Optional parent cgroup for the container")
6767
flBuildArg := opts.NewListOpts(runconfigopts.ValidateEnv)
6868
cmd.Var(&flBuildArg, []string{"-build-arg"}, "Set build-time variables")
69-
isolation := cmd.String([]string{"-isolation"}, "", "Container isolation level")
69+
isolation := cmd.String([]string{"-isolation"}, "", "Container isolation technology")
7070

7171
ulimits := make(map[string]*units.Ulimit)
7272
flUlimits := runconfigopts.NewUlimitOpt(&ulimits)
@@ -224,7 +224,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
224224
Remove: *rm,
225225
ForceRemove: *forceRm,
226226
PullParent: *pull,
227-
IsolationLevel: container.IsolationLevel(*isolation),
227+
Isolation: container.Isolation(*isolation),
228228
CPUSetCPUs: *flCPUSetCpus,
229229
CPUSetMems: *flCPUSetMems,
230230
CPUShares: *flCPUShares,

api/server/router/build/build_routes.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ func newImageBuildOptions(ctx context.Context, r *http.Request) (*types.ImageBui
6060
options.ShmSize = shmSize
6161
}
6262

63-
if i := container.IsolationLevel(r.FormValue("isolation")); i != "" {
64-
if !container.IsolationLevel.IsValid(i) {
63+
if i := container.Isolation(r.FormValue("isolation")); i != "" {
64+
if !container.Isolation.IsValid(i) {
6565
return nil, fmt.Errorf("Unsupported isolation: %q", i)
6666
}
67-
options.IsolationLevel = i
67+
options.Isolation = i
6868
}
6969

7070
var buildUlimits = []*units.Ulimit{}

builder/dockerfile/internals.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ func (b *Builder) create() (string, error) {
506506

507507
// TODO: why not embed a hostconfig in builder?
508508
hostConfig := &container.HostConfig{
509-
Isolation: b.options.IsolationLevel,
509+
Isolation: b.options.Isolation,
510510
ShmSize: b.options.ShmSize,
511511
Resources: resources,
512512
}

daemon/execdriver/driver_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type Command struct {
5353
Hostname string `json:"hostname"` // Windows sets the hostname in the execdriver
5454
LayerFolder string `json:"layer_folder"` // Layer folder for a command
5555
LayerPaths []string `json:"layer_paths"` // Layer paths for a command
56-
Isolation string `json:"isolation"` // Isolation level for the container
56+
Isolation string `json:"isolation"` // Isolation technology for the container
5757
ArgsEscaped bool `json:"args_escaped"` // True if args are already escaped
5858
HvPartition bool `json:"hv_partition"` // True if it's an hypervisor partition
5959
}

daemon/execdriver/windows/windows.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ var dummyMode bool
2828
// This allows the daemon to force kill (HCS terminate) rather than shutdown
2929
var forceKill bool
3030

31-
// DefaultIsolation allows users to specify a default isolation mode for
31+
// DefaultIsolation allows users to specify a default isolation technology for
3232
// when running a container on Windows. For example docker daemon -D
3333
// --exec-opt isolation=hyperv will cause Windows to always run containers
3434
// as Hyper-V containers unless otherwise specified.
35-
var DefaultIsolation container.IsolationLevel = "process"
35+
var DefaultIsolation container.Isolation = "process"
3636

3737
// Define name and version for windows
3838
var (
@@ -83,13 +83,13 @@ func NewDriver(root string, options []string) (*Driver, error) {
8383
}
8484

8585
case "isolation":
86-
if !container.IsolationLevel(val).IsValid() {
86+
if !container.Isolation(val).IsValid() {
8787
return nil, fmt.Errorf("Unrecognised exec driver option 'isolation':'%s'", val)
8888
}
89-
if container.IsolationLevel(val).IsHyperV() {
89+
if container.Isolation(val).IsHyperV() {
9090
DefaultIsolation = "hyperv"
9191
}
92-
logrus.Infof("Windows default isolation level: '%s'", val)
92+
logrus.Infof("Windows default isolation: '%s'", val)
9393
default:
9494
return nil, fmt.Errorf("Unrecognised exec driver option %s\n", key)
9595
}

daemon/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ func includeContainerInList(container *container.Container, ctx *listContext) it
246246
return excludeContainer
247247
}
248248

249-
// Do not include container if the isolation mode doesn't match
249+
// Do not include container if isolation doesn't match
250250
if excludeContainer == excludeByIsolation(container, ctx) {
251251
return excludeContainer
252252
}

runconfig/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ func DecodeContainerConfig(src io.Reader) (*container.Config, *container.HostCon
4444
return nil, nil, nil, err
4545
}
4646

47-
// Validate the isolation level
48-
if err := ValidateIsolationLevel(hc); err != nil {
47+
// Validate isolation
48+
if err := ValidateIsolation(hc); err != nil {
4949
return nil, nil, nil, err
5050
}
5151
return w.Config, hc, w.NetworkingConfig, nil

runconfig/config_test.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func TestDecodeContainerConfig(t *testing.T) {
6565
}
6666
}
6767

68-
// TestDecodeContainerConfigIsolation validates the isolation level passed
68+
// TestDecodeContainerConfigIsolation validates isolation passed
6969
// to the daemon in the hostConfig structure. Note this is platform specific
7070
// as to what level of container isolation is supported.
7171
func TestDecodeContainerConfigIsolation(t *testing.T) {
@@ -77,17 +77,30 @@ func TestDecodeContainerConfigIsolation(t *testing.T) {
7777
}
7878
}
7979

80-
// Blank isolation level (== default)
80+
// Blank isolation (== default)
8181
if _, _, _, err := callDecodeContainerConfigIsolation(""); err != nil {
8282
t.Fatal("Blank isolation should have succeeded")
8383
}
8484

85-
// Default isolation level
85+
// Default isolation
8686
if _, _, _, err := callDecodeContainerConfigIsolation("default"); err != nil {
8787
t.Fatal("default isolation should have succeeded")
8888
}
8989

90-
// Hyper-V Containers isolation level (Valid on Windows only)
90+
// Process isolation (Valid on Windows only)
91+
if runtime.GOOS == "windows" {
92+
if _, _, _, err := callDecodeContainerConfigIsolation("process"); err != nil {
93+
t.Fatal("process isolation should have succeeded")
94+
}
95+
} else {
96+
if _, _, _, err := callDecodeContainerConfigIsolation("process"); err != nil {
97+
if !strings.Contains(err.Error(), `invalid --isolation: "process"`) {
98+
t.Fatal(err)
99+
}
100+
}
101+
}
102+
103+
// Hyper-V Containers isolation (Valid on Windows only)
91104
if runtime.GOOS == "windows" {
92105
if _, _, _, err := callDecodeContainerConfigIsolation("hyperv"); err != nil {
93106
t.Fatal("hyperv isolation should have succeeded")
@@ -102,7 +115,7 @@ func TestDecodeContainerConfigIsolation(t *testing.T) {
102115
}
103116

104117
// callDecodeContainerConfigIsolation is a utility function to call
105-
// DecodeContainerConfig for validating isolation levels
118+
// DecodeContainerConfig for validating isolation
106119
func callDecodeContainerConfigIsolation(isolation string) (*container.Config, *container.HostConfig, *networktypes.NetworkingConfig, error) {
107120
var (
108121
b []byte
@@ -112,7 +125,7 @@ func callDecodeContainerConfigIsolation(isolation string) (*container.Config, *c
112125
Config: &container.Config{},
113126
HostConfig: &container.HostConfig{
114127
NetworkMode: "none",
115-
Isolation: container.IsolationLevel(isolation)},
128+
Isolation: container.Isolation(isolation)},
116129
}
117130
if b, err = json.Marshal(w); err != nil {
118131
return nil, nil, nil, fmt.Errorf("Error on marshal %s", err.Error())

runconfig/hostconfig_unix.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ func ValidateNetMode(c *container.Config, hc *container.HostConfig) error {
7070
return nil
7171
}
7272

73-
// ValidateIsolationLevel performs platform specific validation of the
74-
// isolation level in the hostconfig structure. Linux only supports "default"
73+
// ValidateIsolation performs platform specific validation of
74+
// isolation in the hostconfig structure. Linux only supports "default"
7575
// which is LXC container isolation
76-
func ValidateIsolationLevel(hc *container.HostConfig) error {
76+
func ValidateIsolation(hc *container.HostConfig) error {
7777
// We may not be passed a host config, such as in the case of docker commit
7878
if hc == nil {
7979
return nil

runconfig/hostconfig_windows.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ func ValidateNetMode(c *container.Config, hc *container.HostConfig) error {
3434
return nil
3535
}
3636

37-
// ValidateIsolationLevel performs platform specific validation of the
38-
// isolation level in the hostconfig structure. Windows supports 'default' (or
37+
// ValidateIsolation performs platform specific validation of the
38+
// isolation in the hostconfig structure. Windows supports 'default' (or
3939
// blank), 'process', or 'hyperv'.
40-
func ValidateIsolationLevel(hc *container.HostConfig) error {
40+
func ValidateIsolation(hc *container.HostConfig) error {
4141
// We may not be passed a host config, such as in the case of docker commit
4242
if hc == nil {
4343
return nil

0 commit comments

Comments
 (0)