From e4a1ef2d6bdab0a033c139d33d6da7a83cf9a888 Mon Sep 17 00:00:00 2001 From: Alex Ellis Date: Sun, 22 Oct 2017 20:57:51 +0100 Subject: [PATCH] Add label support to Swarm Signed-off-by: Alex Ellis --- gateway/handlers/createhandler.go | 15 +++++++++++---- gateway/requests/requests.go | 4 ++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/gateway/handlers/createhandler.go b/gateway/handlers/createhandler.go index 06f78362..2ee7b4f0 100644 --- a/gateway/handlers/createhandler.go +++ b/gateway/handlers/createhandler.go @@ -12,13 +12,13 @@ import ( "strings" "time" - "github.com/openfaas/faas/gateway/metrics" - "github.com/openfaas/faas/gateway/requests" "github.com/docker/distribution/reference" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/client" "github.com/docker/docker/registry" + "github.com/openfaas/faas/gateway/metrics" + "github.com/openfaas/faas/gateway/requests" ) var linuxOnlyConstraints = []string{"node.platform.os == linux"} @@ -73,6 +73,12 @@ func makeSpec(request *requests.CreateFunctionRequest, maxRestarts uint64, resta } else { constraints = linuxOnlyConstraints } + labels := map[string]string{"function": "true"} + if request.Labels != nil { + for k, v := range request.Labels { + labels[k] = v + } + } nets := []swarm.NetworkAttachmentConfig{ {Target: request.Network}, @@ -87,7 +93,7 @@ func makeSpec(request *requests.CreateFunctionRequest, maxRestarts uint64, resta }, ContainerSpec: swarm.ContainerSpec{ Image: request.Image, - Labels: map[string]string{"function": "true"}, + Labels: labels, }, Networks: nets, Placement: &swarm.Placement{ @@ -95,7 +101,8 @@ func makeSpec(request *requests.CreateFunctionRequest, maxRestarts uint64, resta }, }, Annotations: swarm.Annotations{ - Name: request.Service, + Name: request.Service, + Labels: labels, }, } diff --git a/gateway/requests/requests.go b/gateway/requests/requests.go index a0a019ac..b221d98f 100644 --- a/gateway/requests/requests.go +++ b/gateway/requests/requests.go @@ -30,6 +30,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 + // back-end for making scheduling or routing decisions + Labels *map[string]string `json:"labels"` } // DeleteFunctionRequest delete a deployed function