From 5a7a5b2d6db6b3601e448260511d6c90a8977b83 Mon Sep 17 00:00:00 2001 From: "Alex Ellis (OpenFaaS Ltd)" Date: Sun, 14 Mar 2021 18:53:08 +0000 Subject: [PATCH] Allow alternative runtimes for functions By setting FUNCTION_RUNTIME, in theory an alternative container runtime could be used such as libkrun or kata. In practice, other changes are required like using the VM network. Signed-off-by: Alex Ellis (OpenFaaS Ltd) --- pkg/provider/handlers/deploy.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/pkg/provider/handlers/deploy.go b/pkg/provider/handlers/deploy.go index 25b92d2..aa3c0f8 100644 --- a/pkg/provider/handlers/deploy.go +++ b/pkg/provider/handlers/deploy.go @@ -140,10 +140,7 @@ func deploy(ctx context.Context, req types.FunctionDeployment, client *container memory.Limit = &v } - container, err := client.NewContainer( - ctx, - name, - containerd.WithImage(image), + ctrOps := []containerd.NewContainerOpts{containerd.WithImage(image), containerd.WithSnapshotter(snapshotter), containerd.WithNewSnapshot(name+"-snapshot", image), containerd.WithNewSpec(oci.WithImageConfig(image), @@ -152,7 +149,16 @@ func deploy(ctx context.Context, req types.FunctionDeployment, client *container oci.WithMounts(mounts), oci.WithEnv(envs), withMemory(memory)), - containerd.WithContainerLabels(labels), + containerd.WithContainerLabels(labels)} + + if v, ok := os.LookupEnv("FUNCTION_RUNTIME"); ok && len(v) > 0 { + ctrOps = append(ctrOps, containerd.WithRuntime(v, nil)) + } + + container, err := client.NewContainer( + ctx, + name, + ctrOps..., ) if err != nil {