diff --git a/gateway/handlers/createhandler.go b/gateway/handlers/createhandler.go index 1bc6497e2..05607fe0e 100644 --- a/gateway/handlers/createhandler.go +++ b/gateway/handlers/createhandler.go @@ -93,6 +93,7 @@ func makeSpec(request *requests.CreateFunctionRequest, maxRestarts uint64, resta }, ContainerSpec: swarm.ContainerSpec{ Image: request.Image, + Mounts: request.Mounts, Labels: labels, }, Networks: nets, diff --git a/gateway/requests/requests.go b/gateway/requests/requests.go index b221d98fc..841fe25ce 100644 --- a/gateway/requests/requests.go +++ b/gateway/requests/requests.go @@ -3,6 +3,8 @@ package requests +import "github.com/docker/docker/api/types/mount" + // CreateFunctionRequest create a function in the swarm. type CreateFunctionRequest struct { // Service corresponds to a Docker Service @@ -31,7 +33,10 @@ type CreateFunctionRequest struct { // Secrets list of secrets to be made available to function Secrets []string `json:"secrets"` - // Labels are metadata for functions which may be used by the + // Mounts to be mounted by the container running the function + Mounts []mount.Mount `json:"mounts,omitempty"` + + // Labels are metadata for functions which may be used by the // back-end for making scheduling or routing decisions Labels *map[string]string `json:"labels"` } diff --git a/gateway/tests/integration/createfunction_test.go b/gateway/tests/integration/createfunction_test.go index 019e49989..2657702fe 100644 --- a/gateway/tests/integration/createfunction_test.go +++ b/gateway/tests/integration/createfunction_test.go @@ -10,6 +10,7 @@ import ( "testing" "github.com/openfaas/faas/gateway/requests" + "github.com/docker/docker/api/types/mount" ) func createFunction(request requests.CreateFunctionRequest) (string, int, error) { @@ -46,6 +47,43 @@ func TestCreate_ValidRequest(t *testing.T) { deleteFunction("test_resizer") } +func TestCreate_ValidMountRequest(t *testing.T) { + mounts := []mount.Mount{ + mount.Mount{ + Type: "volume", + Source: "Test1", + Target: "/tmp", + }, + mount.Mount{ + Type: "bind", + Source: "/tmp", + Target: "/tmp", + }, + } + request := requests.CreateFunctionRequest{ + Service: "test_resizer", + Image: "functions/resizer", + Network: "func_functions", + Mounts: mounts, + EnvProcess: "", + } + + _, code, err := createFunction(request) + + if err != nil { + t.Log(err) + t.Fail() + } + + expectedErrorCode := http.StatusOK + if code != expectedErrorCode { + t.Errorf("Got HTTP code: %d, want %d\n", code, expectedErrorCode) + return + } + + deleteFunction("test_resizer") +} + func TestCreate_InvalidImage(t *testing.T) { request := requests.CreateFunctionRequest{ Service: "test_resizer",