Skip to content
Snippets Groups Projects
Commit e4a1ef2d authored by Alex Ellis's avatar Alex Ellis
Browse files

Add label support to Swarm


Signed-off-by: default avatarAlex Ellis <alexellis2@gmail.com>
parent 6584b822
No related branches found
No related tags found
No related merge requests found
......@@ -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,
},
}
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment