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

[WIP] Adding mount options to functions. #309

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gateway/handlers/createhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion 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 @@ -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"`
}
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