Skip to content

Commit

Permalink
post rebase fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Ferquel <simon.ferquel@docker.com>
  • Loading branch information
simonferquel committed Nov 2, 2017
1 parent e194773 commit 92b49da
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 9 deletions.
38 changes: 34 additions & 4 deletions cli/command/service/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,36 @@ func convertExtraHostsToSwarmHosts(extraHosts []string) []string {
return hosts
}

type isolationOpts struct {
value *container.Isolation
source string
}

func (o *isolationOpts) Set(value string) error {
o.source = value
tv := container.Isolation(value)
if tv.IsDefault() || tv.IsHyperV() || tv.IsProcess() {
o.value = &tv
return nil
}
return fmt.Errorf("Unknown isolation mode %s. Valid values are %v, %v, %v", value, container.IsolationDefault, container.IsolationProcess, container.IsolationHyperV)
}

func (o *isolationOpts) Type() string {
return "isolation"
}

func (o *isolationOpts) String() string {
return o.source
}

func (o *isolationOpts) Value() container.Isolation {
if o.value == nil {
return container.IsolationEmpty
}
return *o.value
}

type serviceOptions struct {
detach bool
quiet bool
Expand Down Expand Up @@ -506,7 +536,7 @@ type serviceOptions struct {
secrets opts.SecretOpt
configs opts.ConfigOpt

isolation string
isolation isolationOpts
}

func newServiceOptions() *serviceOptions {
Expand Down Expand Up @@ -616,7 +646,7 @@ func (options *serviceOptions) ToService(ctx context.Context, apiClient client.N
Hosts: convertExtraHostsToSwarmHosts(options.hosts.GetAll()),
StopGracePeriod: options.ToStopGracePeriod(flags),
Healthcheck: healthConfig,
Isolation: options.isolation,
Isolation: options.isolation.Value(),
},
Networks: networks,
Resources: options.resources.ToResourceRequirements(),
Expand Down Expand Up @@ -787,8 +817,8 @@ func addServiceFlags(flags *pflag.FlagSet, opts *serviceOptions, defaultFlagValu

flags.StringVar(&opts.stopSignal, flagStopSignal, "", "Signal to stop the container")
flags.SetAnnotation(flagStopSignal, "version", []string{"1.28"})
flags.StringVar(&opts.isolation, flagIsolation, "", "defines the isolation mode (hyperv, process)")
flags.SetAnnotation(flagIsolation, "version", []string{"1.32"})
flags.Var(&opts.isolation, flagIsolation, "defines the isolation mode (hyperv, process)")
flags.SetAnnotation(flagIsolation, "version", []string{"1.35"})
}

const (
Expand Down
17 changes: 16 additions & 1 deletion cli/command/service/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,19 @@ func updateService(ctx context.Context, apiClient client.NetworkAPIClient, flags
}
}

updateIsolation := func(flag string, field *container.Isolation) error {
if flags.Changed(flag) {
o := isolationOpts{}
val := flags.Lookup(flag).Value.String()
err := o.Set(val)
if err != nil {
return err
}
*field = o.Value()
}
return nil
}

cspec := spec.TaskTemplate.ContainerSpec
task := &spec.TaskTemplate

Expand All @@ -288,7 +301,9 @@ func updateService(ctx context.Context, apiClient client.NetworkAPIClient, flags
updateString(flagWorkdir, &cspec.Dir)
updateString(flagUser, &cspec.User)
updateString(flagHostname, &cspec.Hostname)
updateString(flagIsolation, &cspec.Isolation)
if err := updateIsolation(flagIsolation, &cspec.Isolation); err != nil {
return err
}
if err := updateMounts(flags, &cspec.Mounts); err != nil {
return err
}
Expand Down
7 changes: 6 additions & 1 deletion cli/compose/convert/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ func Service(
}
}

isolation := container.Isolation(service.Isolation)
if !isolation.IsDefault() && !isolation.IsHyperV() && !isolation.IsProcess() {
return swarm.ServiceSpec{}, fmt.Errorf("Unsupported isolation %s. Valid values are %s, %s, %s", isolation, container.IsolationDefault, container.IsolationProcess, container.IsolationHyperV)
}

serviceSpec := swarm.ServiceSpec{
Annotations: swarm.Annotations{
Name: name,
Expand Down Expand Up @@ -149,7 +154,7 @@ func Service(
Configs: configs,
ReadOnly: service.ReadOnly,
Privileges: &privileges,
Isolation: service.Isolation,
Isolation: isolation,
},
LogDriver: logDriver,
Resources: resources,
Expand Down
4 changes: 2 additions & 2 deletions cli/compose/convert/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,11 @@ func TestConvertUpdateConfigOrder(t *testing.T) {

func TestIsolation(t *testing.T) {
src := composetypes.ServiceConfig{
Isolation: "test",
Isolation: "hyperv",
}
result, err := Service("1.32", Namespace{name: "foo"}, src, nil, nil, nil, nil)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, "test", result.TaskTemplate.ContainerSpec.Isolation)
assert.Equal(t, container.IsolationHyperV, result.TaskTemplate.ContainerSpec.Isolation)
}
2 changes: 1 addition & 1 deletion cli/trust/trust.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func GetNotaryRepository(in io.Reader, out io.Writer, userAgent string, repoInfo
}

// Skip configuration headers since request is not going to Docker daemon
modifiers := registry.DockerHeaders(userAgent, http.Header{})
modifiers := registry.Headers(userAgent, http.Header{})
authTransport := transport.NewTransport(base, modifiers...)
pingClient := &http.Client{
Transport: authTransport,
Expand Down

0 comments on commit 92b49da

Please sign in to comment.