Sfoglia il codice sorgente

Merge pull request #37400 from olljanat/34795-allow-npipe

Allow mount type npipe on service/stack
Yong Tang 6 anni fa
parent
commit
7bfec8cd80

+ 2 - 0
api/swagger.yaml

@@ -238,11 +238,13 @@ definitions:
           - `bind` Mounts a file or directory from the host into the container. Must exist prior to creating the container.
           - `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.
           - `tmpfs` Create a tmpfs with the given options. The mount source cannot be specified for tmpfs.
+          - `npipe` Mounts a named pipe from the host into the container. Must exist prior to creating the container.
         type: "string"
         enum:
           - "bind"
           - "volume"
           - "tmpfs"
+          - "npipe"
       ReadOnly:
         description: "Whether the mount should be read-only."
         type: "boolean"

+ 2 - 0
daemon/cluster/executor/container/container.go

@@ -285,6 +285,8 @@ func convertMount(m api.Mount) enginemount.Mount {
 		mount.Type = enginemount.TypeVolume
 	case api.MountTypeTmpfs:
 		mount.Type = enginemount.TypeTmpfs
+	case api.MountTypeNamedPipe:
+		mount.Type = enginemount.TypeNamedPipe
 	}
 
 	if m.BindOptions != nil {

+ 6 - 1
daemon/cluster/executor/container/validate.go

@@ -11,7 +11,8 @@ import (
 func validateMounts(mounts []api.Mount) error {
 	for _, mount := range mounts {
 		// Target must always be absolute
-		if !filepath.IsAbs(mount.Target) {
+		// except if target is Windows named pipe
+		if !filepath.IsAbs(mount.Target) && mount.Type != api.MountTypeNamedPipe {
 			return fmt.Errorf("invalid mount target, must be an absolute path: %s", mount.Target)
 		}
 
@@ -32,6 +33,10 @@ func validateMounts(mounts []api.Mount) error {
 			if mount.Source != "" {
 				return errors.New("invalid tmpfs source, source must be empty")
 			}
+		case api.MountTypeNamedPipe:
+			if mount.Source == "" {
+				return errors.New("invalid npipe source, source must not be empty")
+			}
 		default:
 			return fmt.Errorf("invalid mount type: %s", mount.Type)
 		}

+ 16 - 0
daemon/cluster/executor/container/validate_windows_test.go

@@ -1,8 +1,24 @@
 // +build windows
 
 package container // import "github.com/docker/docker/daemon/cluster/executor/container"
+import (
+	"strings"
+	"testing"
+
+	"github.com/docker/swarmkit/api"
+)
 
 const (
 	testAbsPath        = `c:\foo`
 	testAbsNonExistent = `c:\some-non-existing-host-path\`
 )
+
+func TestControllerValidateMountNamedPipe(t *testing.T) {
+	if _, err := newTestControllerWithMount(api.Mount{
+		Type:   api.MountTypeNamedPipe,
+		Source: "",
+		Target: `\\.\pipe\foo`,
+	}); err == nil || !strings.Contains(err.Error(), "invalid npipe source, source must not be empty") {
+		t.Fatalf("expected error, got: %v", err)
+	}
+}