Skip to content

Commit

Permalink
Adding mount options to functions.
Browse files Browse the repository at this point in the history
This allows functions to mouunt volumes and other
directories. It uses the same configuration as is
used by docker.

Fixes openfaas#320

Signed-off-by: Ali Al-Shabibi <[email protected]>
  • Loading branch information
alshabib committed Oct 20, 2017
1 parent e4d494a commit c8a67d2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions gateway/handlers/createhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/client"
"github.com/docker/docker/registry"

)

var linuxOnlyConstraints = []string{"node.platform.os == linux"}
Expand Down Expand Up @@ -88,6 +89,7 @@ func makeSpec(request *requests.CreateFunctionRequest, maxRestarts uint64, resta
ContainerSpec: swarm.ContainerSpec{
Image: request.Image,
Labels: map[string]string{"function": "true"},
Mounts: request.Mounts,
},
Networks: nets,
Placement: &swarm.Placement{
Expand Down
5 changes: 5 additions & 0 deletions gateway/requests/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -30,6 +32,9 @@ type CreateFunctionRequest struct {

// Secrets list of secrets to be made available to function
Secrets []string `json:"secrets"`

// Mounts to be mounted by the container running the function
Mounts []mount.Mount `json:"mounts,omitempty"`
}

// DeleteFunctionRequest delete a deployed function
Expand Down
38 changes: 38 additions & 0 deletions gateway/tests/integration/createfunction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit c8a67d2

Please sign in to comment.