Enable labeling containers

Enabling the faasd-provider to label containers

Signed-off-by: Martin Dekov <mvdekov@gmail.com>
This commit is contained in:
Martin Dekov 2020-02-15 20:42:38 +02:00 committed by Alex Ellis
parent 93325b713e
commit 560c295eb0
3 changed files with 14 additions and 2 deletions

View File

@ -107,6 +107,7 @@ func deploy(ctx context.Context, req types.FunctionDeployment, client *container
oci.WithCapabilities([]string{"CAP_NET_RAW"}), oci.WithCapabilities([]string{"CAP_NET_RAW"}),
oci.WithMounts(mounts), oci.WithMounts(mounts),
oci.WithEnv(envs)), oci.WithEnv(envs)),
containerd.WithContainerLabels(*req.Labels),
) )
if err != nil { if err != nil {

View File

@ -3,10 +3,11 @@ package handlers
import ( import (
"context" "context"
"fmt" "fmt"
"log"
"github.com/openfaas/faasd/pkg/cninetwork"
"github.com/containerd/containerd" "github.com/containerd/containerd"
"github.com/containerd/containerd/namespaces" "github.com/containerd/containerd/namespaces"
"github.com/openfaas/faasd/pkg/cninetwork"
) )
type Function struct { type Function struct {
@ -16,6 +17,7 @@ type Function struct {
pid uint32 pid uint32
replicas int replicas int
IP string IP string
labels map[string]string
} }
const ( const (
@ -44,10 +46,18 @@ func GetFunction(client *containerd.Client, name string) (Function, error) {
if err == nil { if err == nil {
image, _ := c.Image(ctx) image, _ := c.Image(ctx)
containerName := c.ID()
labels, labelErr := c.Labels(ctx)
if labelErr != nil {
log.Printf("cannot list container %s labels: %s", containerName, labelErr.Error())
}
f := Function{ f := Function{
name: c.ID(), name: containerName,
namespace: FunctionNamespace, namespace: FunctionNamespace,
image: image.Name(), image: image.Name(),
labels: labels,
} }
replicas := 0 replicas := 0

View File

@ -26,6 +26,7 @@ func MakeReadHandler(client *containerd.Client) func(w http.ResponseWriter, r *h
Image: function.image, Image: function.image,
Replicas: uint64(function.replicas), Replicas: uint64(function.replicas),
Namespace: function.namespace, Namespace: function.namespace,
Labels: &function.labels,
}) })
} }