mirror of
https://github.com/openfaas/faas.git
synced 2025-06-14 19:26:48 +00:00
Add label support to Swarm
Signed-off-by: Alex Ellis <alexellis2@gmail.com>
This commit is contained in:
parent
6584b8225b
commit
e4a1ef2d6b
@ -12,13 +12,13 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/openfaas/faas/gateway/metrics"
|
|
||||||
"github.com/openfaas/faas/gateway/requests"
|
|
||||||
"github.com/docker/distribution/reference"
|
"github.com/docker/distribution/reference"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/swarm"
|
"github.com/docker/docker/api/types/swarm"
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
"github.com/docker/docker/registry"
|
"github.com/docker/docker/registry"
|
||||||
|
"github.com/openfaas/faas/gateway/metrics"
|
||||||
|
"github.com/openfaas/faas/gateway/requests"
|
||||||
)
|
)
|
||||||
|
|
||||||
var linuxOnlyConstraints = []string{"node.platform.os == linux"}
|
var linuxOnlyConstraints = []string{"node.platform.os == linux"}
|
||||||
@ -73,6 +73,12 @@ func makeSpec(request *requests.CreateFunctionRequest, maxRestarts uint64, resta
|
|||||||
} else {
|
} else {
|
||||||
constraints = linuxOnlyConstraints
|
constraints = linuxOnlyConstraints
|
||||||
}
|
}
|
||||||
|
labels := map[string]string{"function": "true"}
|
||||||
|
if request.Labels != nil {
|
||||||
|
for k, v := range request.Labels {
|
||||||
|
labels[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
nets := []swarm.NetworkAttachmentConfig{
|
nets := []swarm.NetworkAttachmentConfig{
|
||||||
{Target: request.Network},
|
{Target: request.Network},
|
||||||
@ -87,7 +93,7 @@ func makeSpec(request *requests.CreateFunctionRequest, maxRestarts uint64, resta
|
|||||||
},
|
},
|
||||||
ContainerSpec: swarm.ContainerSpec{
|
ContainerSpec: swarm.ContainerSpec{
|
||||||
Image: request.Image,
|
Image: request.Image,
|
||||||
Labels: map[string]string{"function": "true"},
|
Labels: labels,
|
||||||
},
|
},
|
||||||
Networks: nets,
|
Networks: nets,
|
||||||
Placement: &swarm.Placement{
|
Placement: &swarm.Placement{
|
||||||
@ -96,6 +102,7 @@ func makeSpec(request *requests.CreateFunctionRequest, maxRestarts uint64, resta
|
|||||||
},
|
},
|
||||||
Annotations: swarm.Annotations{
|
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 list of secrets to be made available to function
|
||||||
Secrets []string `json:"secrets"`
|
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
|
// DeleteFunctionRequest delete a deployed function
|
||||||
|
Loading…
x
Reference in New Issue
Block a user