8000 Merge pull request #37400 from olljanat/34795-allow-npipe · moby/moby@7bfec8c · GitHub
[go: up one dir, main page]

Skip to content

Commit 7bfec8c

Browse files
authored
Merge pull request #37400 from olljanat/34795-allow-npipe
Allow mount type npipe on service/stack
2 parents 7fe4f7d + 1144159 commit 7bfec8c

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

api/swagger.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,13 @@ definitions:
238238
- `bind` Mounts a file or directory from the host into the container. Must exist prior to creating the container.
239239
- `volume` Creates a volume with the given name and options (or uses a pre-existing volume with the same name and options). These are **not** removed when the container is removed.
240240
- `tmpfs` Create a tmpfs with the given options. The mount source cannot be specified for tmpfs.
241+
- `npipe` Mounts a named pipe from the host into the container. Must exist prior to creating the container.
241242
type: "string"
242243
enum:
243244
- "bind"
244245
- "volume"
245246
- "tmpfs"
247+
- "npipe"
246248
ReadOnly:
247249
description: "Whether the mount should be read-only."
248250
type: "boolean"

daemon/cluster/executor/container/container.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ func convertMount(m api.Mount) enginemount.Mount {
285285
mount.Type = enginemount.TypeVolume
286286
case api.MountTypeTmpfs:
287287
mount.Type = enginemount.TypeTmpfs
288+
case api.MountTypeNamedPipe:
289+
mount.Type = enginemount.TypeNamedPipe
288290
}
289291

290292
if m.BindOptions != nil {

daemon/cluster/executor/container/validate.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import (
1111
func validateMounts(mounts []api.Mount) error {
1212
for _, mount := range mounts {
1313
// Target must always be absolute
14-
if !filepath.IsAbs(mount.Target) {
14+
// except if target is Windows named pipe
15+
if !filepath.IsAbs(mount.Target) && mount.Type != api.MountTypeNamedPipe {
1516
return fmt.Errorf("invalid mount target, must be an absolute path: %s", mount.Target)
1617
}
1718

@@ -32,6 +33,10 @@ func validateMounts(mounts []api.Mount) error {
3233
if mount.Source != "" {
3334
return errors.New("invalid tmpfs source, source must be empty")
3435
}
36+
case api.MountTypeNamedPipe:
F1A0 37+
if mount.Source == "" {
38+
return errors.New("invalid npipe source, source must not be empty")
39+
}
3540
default:
3641
return fmt.Errorf("invalid mount type: %s", mount.Type)
3742
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
// +build windows
22

33
package container // import "github.com/docker/docker/daemon/cluster/executor/container"
4+
import (
5+
"strings"
6+
"testing"
7+
8+
"github.com/docker/swarmkit/api"
9+
)
410

511
const (
612
testAbsPath = `c:\foo`
713
testAbsNonExistent = `c:\some-non-existing-host-path\`
814
)
15+
16+
func TestControllerValidateMountNamedPipe(t *testing.T) {
17+
if _, err := newTestControllerWithMount(api.Mount{
18+
Type: api.MountTypeNamedPipe,
19+
Source: "",
20+
Target: `\\.\pipe\foo`,
21+
}); err == nil || !strings.Contains(err.Error(), "invalid npipe source, source must not be empty") {
22+
t.Fatalf("expected error, got: %v", err)
23+
}
24+
}

0 commit comments

Comments
 (0)
0