Skip to content

Commit

Permalink
Add null-checking for labels
Browse files Browse the repository at this point in the history
Fixes an issue introduced in #45 which was undetected. When
users do not pass in "labels" to the deployment - or a valid
empty object, then a nil dereference causes a panic.

Fixes: #101

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Sep 11, 2020
1 parent 6752a61 commit 917b65a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/provider/handlers/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func deploy(ctx context.Context, req types.FunctionDeployment, client *container
if err != nil {
return err
}

imgRef := reference.TagNameOnly(r).String()

snapshotter := ""
Expand Down Expand Up @@ -98,6 +99,11 @@ func deploy(ctx context.Context, req types.FunctionDeployment, client *container

name := req.Service

labels := map[string]string{}
if req.Labels != nil {
labels = *req.Labels
}

container, err := client.NewContainer(
ctx,
name,
Expand All @@ -108,7 +114,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),
containerd.WithContainerLabels(labels),
)

if err != nil {
Expand Down

0 comments on commit 917b65a

Please sign in to comment.