Return labels in functions list endpoint

Signed-off-by: Alex Ellis <alexellis2@gmail.com>
This commit is contained in:
Alex Ellis
2017-11-01 20:05:51 +00:00
parent c1dfd9cfa2
commit b2c579370a
5 changed files with 43 additions and 21 deletions

View File

@ -73,18 +73,30 @@ func makeSpec(request *requests.CreateFunctionRequest, maxRestarts uint64, resta
} else {
constraints = linuxOnlyConstraints
}
labels := map[string]string{"function": "true"}
labels := map[string]string{
"com.openfaas.function": request.Service,
"function": "true", // backwards-compatible
}
if request.Labels != nil {
for k, v := range *request.Labels {
labels[k] = v
}
}
fmt.Println(labels)
nets := []swarm.NetworkAttachmentConfig{
{Target: request.Network},
{
Target: request.Network,
},
}
spec := swarm.ServiceSpec{
Annotations: swarm.Annotations{
Name: request.Service,
Labels: labels,
},
TaskTemplate: swarm.TaskSpec{
RestartPolicy: &swarm.RestartPolicy{
MaxAttempts: &maxRestarts,
@ -100,10 +112,6 @@ func makeSpec(request *requests.CreateFunctionRequest, maxRestarts uint64, resta
Constraints: constraints,
},
},
Annotations: swarm.Annotations{
Name: request.Service,
Labels: labels,
},
}
// TODO: request.EnvProcess should only be set if it's not nil, otherwise we override anything in the Docker image already

View File

@ -50,12 +50,15 @@ func MakeFunctionReader(metricsOptions metrics.MetricOptions, c client.ServiceAP
}
}
// Required (copy by value)
labels := service.Spec.Annotations.Labels
f := requests.Function{
Name: service.Spec.Name,
Image: service.Spec.TaskTemplate.ContainerSpec.Image,
InvocationCount: 0,
Replicas: *service.Spec.Mode.Replicated.Replicas,
EnvProcess: envProcess,
Labels: &labels,
}
functions = append(functions, f)

View File

@ -81,33 +81,34 @@ func updateSpec(request *requests.CreateFunctionRequest, spec *swarm.ServiceSpec
constraints = linuxOnlyConstraints
}
nets := []swarm.NetworkAttachmentConfig{
{Target: request.Network},
}
spec.TaskTemplate.RestartPolicy.MaxAttempts = &maxRestarts
spec.TaskTemplate.RestartPolicy.Condition = swarm.RestartPolicyConditionAny
spec.TaskTemplate.RestartPolicy.Delay = &restartDelay
spec.TaskTemplate.ContainerSpec.Image = request.Image
spec.TaskTemplate.ContainerSpec.Labels = map[string]string{
"function": "true",
"uid": fmt.Sprintf("%d", time.Now().Nanosecond()),
"function": "true",
"com.openfaas.function": request.Service,
"com.openfaas.uid": fmt.Sprintf("%d", time.Now().Nanosecond()),
}
if request.Labels != nil {
for k, v := range *request.Labels {
spec.TaskTemplate.ContainerSpec.Labels[k] = v
spec.Annotations.Labels[k] = v
}
}
spec.TaskTemplate.Networks = nets
spec.TaskTemplate.Networks = []swarm.NetworkAttachmentConfig{
{
Target: request.Network,
},
}
spec.TaskTemplate.Placement = &swarm.Placement{
Constraints: constraints,
}
spec.Annotations = swarm.Annotations{
Name: request.Service,
}
spec.Annotations.Name = request.Service
spec.RollbackConfig = &swarm.UpdateConfig{
FailureAction: "pause",