Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Windows named pipes mounts #2691

Merged
merged 4 commits into from Sep 12, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions agent/exec/dockerapi/container.go
Expand Up @@ -301,6 +301,8 @@ func convertMount(m api.Mount) enginemount.Mount {
mount.Type = enginemount.TypeBind
case api.MountTypeVolume:
mount.Type = enginemount.TypeVolume
case api.MountTypeNamedPipe:
mount.Type = enginemount.TypeNamedPipe
}

if m.BindOptions != nil {
Expand Down
4 changes: 4 additions & 0 deletions agent/exec/dockerapi/container_test.go
Expand Up @@ -29,6 +29,10 @@ func TestVolumesAndBinds(t *testing.T) {
enginemount.Mount{Type: enginemount.TypeVolume, Source: "banana", Target: "/kerfluffle", VolumeOptions: &enginemount.VolumeOptions{NoCopy: true}}},
{"Volume with no source", api.Mount{Type: api.MountTypeVolume, Target: "/kerfluffle"},
enginemount.Mount{Type: enginemount.TypeVolume, Target: "/kerfluffle"}},
{"Named pipe using Windows format", api.Mount{Type: api.MountTypeNamedPipe, Source: `\\.\pipe\foo`, Target: `\\.\pipe\foo`},
enginemount.Mount{Type: enginemount.TypeNamedPipe, Source: `\\.\pipe\foo`, Target: `\\.\pipe\foo`}},
{"Named pipe using Unix format", api.Mount{Type: api.MountTypeNamedPipe, Source: "//./pipe/foo", Target: "//./pipe/foo"},
enginemount.Mount{Type: enginemount.TypeNamedPipe, Source: "//./pipe/foo", Target: "//./pipe/foo"}},
}

for _, c := range cases {
Expand Down
7 changes: 7 additions & 0 deletions api/api.pb.txt
Expand Up @@ -2520,6 +2520,13 @@ file {
66001: "MountTypeTmpfs"
}
}
value {
name: "NPIPE"
number: 3
options {
66001: "MountTypeNamedPipe"
}
}
options {
62001: 0
62023: "MountType"
Expand Down
652 changes: 328 additions & 324 deletions api/types.pb.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions api/types.proto
Expand Up @@ -202,6 +202,7 @@ message Mount {
BIND = 0 [(gogoproto.enumvalue_customname) = "MountTypeBind"]; // Bind mount host dir
VOLUME = 1 [(gogoproto.enumvalue_customname) = "MountTypeVolume"]; // Remote storage volumes
TMPFS = 2 [(gogoproto.enumvalue_customname) = "MountTypeTmpfs"]; // Mount a tmpfs
NPIPE = 3 [(gogoproto.enumvalue_customname) = "MountTypeNamedPipe"]; // Windows named pipes
}

// Type defines the nature of the mount.
Expand Down
5 changes: 5 additions & 0 deletions cmd/swarmctl/service/flagparser/flags.go
Expand Up @@ -55,6 +55,7 @@ func AddServiceFlags(flags *pflag.FlagSet) {
flags.StringSlice("bind", nil, "define a bind mount")
flags.StringSlice("volume", nil, "define a volume mount")
flags.StringSlice("tmpfs", nil, "define a tmpfs mount")
flags.StringSlice("npipe", nil, "define a npipe mount")

flags.String("log-driver", "", "specify a log driver")
flags.StringSlice("log-opt", nil, "log driver options, as key value pairs")
Expand Down Expand Up @@ -143,6 +144,10 @@ func Merge(cmd *cobra.Command, spec *api.ServiceSpec, c api.ControlClient) error
return err
}

if err := parseNpipe(flags, spec); err != nil {
return err
}

driver, err := common.ParseLogDriverFlags(flags)
if err != nil {
return err
Expand Down
35 changes: 35 additions & 0 deletions cmd/swarmctl/service/flagparser/npipe.go
@@ -0,0 +1,35 @@
package flagparser

import (
"fmt"
"strings"

"github.com/docker/swarmkit/api"
"github.com/spf13/pflag"
)

// parseNpipe only supports a very simple version of anonymous npipes for
// testing the most basic of data flows. Replace with a --mount flag, similar
// to what we have in docker service.
func parseNpipe(flags *pflag.FlagSet, spec *api.ServiceSpec) error {
if flags.Changed("npipe") {
npipes, err := flags.GetStringSlice("npipe")
if err != nil {
return err
}

container := spec.Task.GetContainer()

for _, npipe := range npipes {
if strings.Contains(npipe, ":") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johnstep @cpuguy83 should we have more/other validation here? (don't know if there's a utility somewhere to validate these)

Copy link
Contributor Author

@olljanat olljanat Jul 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thaJeztah good question, there looks to be quite a lot validations on engine side already. Is there is any point to duplicate them to here?

return fmt.Errorf("npipe format %q not supported", npipe)
}
container.Mounts = append(container.Mounts, api.Mount{
Type: api.MountTypeNamedPipe,
Target: npipe,
})
}
}

return nil
}