Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable labeling containers #45

Merged
merged 1 commit into from
Feb 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/provider/handlers/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func deploy(ctx context.Context, req types.FunctionDeployment, client *container
oci.WithCapabilities([]string{"CAP_NET_RAW"}),
oci.WithMounts(mounts),
oci.WithEnv(envs)),
containerd.WithContainerLabels(*req.Labels),
)

if err != nil {
Expand Down
14 changes: 12 additions & 2 deletions pkg/provider/handlers/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package handlers
import (
"context"
"fmt"
"log"

"github.com/openfaas/faasd/pkg/cninetwork"
"github.com/containerd/containerd"
"github.com/containerd/containerd/namespaces"
"github.com/openfaas/faasd/pkg/cninetwork"
)

type Function struct {
Expand All @@ -16,6 +17,7 @@ type Function struct {
pid uint32
replicas int
IP string
labels map[string]string
}

const (
Expand Down Expand Up @@ -44,10 +46,18 @@ func GetFunction(client *containerd.Client, name string) (Function, error) {
if err == nil {

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{
name: c.ID(),
name: containerName,
namespace: FunctionNamespace,
image: image.Name(),
labels: labels,
}

replicas := 0
Expand Down
1 change: 1 addition & 0 deletions pkg/provider/handlers/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func MakeReadHandler(client *containerd.Client) func(w http.ResponseWriter, r *h
Image: function.image,
Replicas: uint64(function.replicas),
Namespace: function.namespace,
Labels: &function.labels,
})
}

Expand Down