Compare commits

..

7 Commits

Author SHA1 Message Date
a4c1995587 Alter IP range and share kvm
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
2021-03-14 19:33:07 +00:00
5a7a5b2d6d 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) <alexellis2@gmail.com>
2021-03-14 18:53:08 +00:00
dca036ee51 Update to newer faas-provider
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
2021-03-11 21:08:28 +00:00
583f5ad1b0 Update faasd main help message
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
2021-03-11 21:08:28 +00:00
659f98cc0d Populate CreatedAt
Populates the CreatedAt value from the container's info
field.

Ref: https://github.com/openfaas/faas-provider/issues/59

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
2021-03-11 21:08:28 +00:00
c7d9353991 Bump gateway version
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
2021-02-27 20:38:03 +00:00
29bb5ad9cc Upgrade to faas-provider 0.17.1
**What**
Update faas-provider to get the proxy implementation that allows CORS
requests (OPTIONS) and HEAD.

Signed-off-by: Lucas Roesler <roesler.lucas@gmail.com>
2021-02-27 09:51:50 +00:00
13 changed files with 54 additions and 18 deletions

View File

@ -46,7 +46,12 @@ var rootCommand = &cobra.Command{
Use: "faasd",
Short: "Start faasd",
Long: `
faasd - serverless without Kubernetes
faasd - Serverless For Everyone Else
Learn how to build, secure, and monitor functions with faasd with
the eBook:
https://gumroad.com/l/serverless-for-everyone-else
`,
RunE: runRootCommand,
SilenceUsage: true,

View File

@ -41,7 +41,7 @@ services:
- "127.0.0.1:9090:9090"
gateway:
image: ghcr.io/openfaas/gateway:0.20.8
image: ghcr.io/openfaas/gateway:0.20.11
environment:
- basic_auth=true
- functions_provider_url=http://faasd-provider:8081/

2
go.mod
View File

@ -30,7 +30,7 @@ require (
github.com/opencontainers/runc v1.0.0-rc9 // indirect
github.com/opencontainers/runtime-spec v1.0.2
github.com/openfaas/faas v0.0.0-20201205125747-9bbb25e3c7c4
github.com/openfaas/faas-provider v0.17.0
github.com/openfaas/faas-provider v0.17.3
github.com/pkg/errors v0.9.1
github.com/prometheus/procfs v0.2.0 // indirect
github.com/sethvargo/go-password v0.1.3

6
go.sum
View File

@ -183,6 +183,12 @@ github.com/openfaas/faas v0.0.0-20201205125747-9bbb25e3c7c4 h1:JJjthDw7WziZQ7sC5
github.com/openfaas/faas v0.0.0-20201205125747-9bbb25e3c7c4/go.mod h1:E0m2rLup0Vvxg53BKxGgaYAGcZa3Xl+vvL7vSi5yQ14=
github.com/openfaas/faas-provider v0.17.0 h1:4rT8CosKhI5xaAMqbyihEgR6KefO/ViJdF0a8THTgwM=
github.com/openfaas/faas-provider v0.17.0/go.mod h1:fq1JL0mX4rNvVVvRLaLRJ3H6o667sHuyP5p/7SZEe98=
github.com/openfaas/faas-provider v0.17.1 h1:P5xTLN+/08PLLh4auIlO/PaUD/J3BUTmaC3en8N5zbs=
github.com/openfaas/faas-provider v0.17.1/go.mod h1:fq1JL0mX4rNvVVvRLaLRJ3H6o667sHuyP5p/7SZEe98=
github.com/openfaas/faas-provider v0.17.2 h1:jZ+Z83A/tyJoI1AnpyLN3o0B4K0UEsz1YJ3erASMu+s=
github.com/openfaas/faas-provider v0.17.2/go.mod h1:fq1JL0mX4rNvVVvRLaLRJ3H6o667sHuyP5p/7SZEe98=
github.com/openfaas/faas-provider v0.17.3 h1:LN76lrXUKAx27o5X8l+daKWEzsdiW2E99jMOlI1SO5Q=
github.com/openfaas/faas-provider v0.17.3/go.mod h1:fq1JL0mX4rNvVVvRLaLRJ3H6o667sHuyP5p/7SZEe98=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=

View File

@ -42,7 +42,7 @@ const (
defaultBridgeName = "openfaas0"
// defaultSubnet is the default subnet used in the defaultCNIConf -- this value is set to not collide with common container networking subnets:
defaultSubnet = "10.62.0.0/16"
defaultSubnet = "10.63.0.0/16"
// defaultIfPrefix is the interface name to be created in the container
defaultIfPrefix = "eth"
@ -179,7 +179,7 @@ func GetIPAddress(container string, PID uint32) (string, error) {
//
// Example:
//
// /var/run/cni/openfaas-cni-bridge/10.62.0.2
// /var/run/cni/openfaas-cni-bridge/10.63.0.2
//
// nats-621
// eth1

View File

@ -10,7 +10,7 @@ import (
func Test_isCNIResultForPID_Found(t *testing.T) {
body := `nats-621
eth1`
fileName := `10.62.0.2`
fileName := `10.63.0.2`
container := "nats"
PID := uint32(621)
fullPath := filepath.Join(os.TempDir(), fileName)
@ -38,7 +38,7 @@ eth1`
func Test_isCNIResultForPID_NoMatch(t *testing.T) {
body := `nats-621
eth1`
fileName := `10.62.0.3`
fileName := `10.63.0.3`
container := "gateway"
PID := uint32(621)
fullPath := filepath.Join(os.TempDir(), fileName)

View File

@ -29,8 +29,8 @@ import (
const annotationLabelPrefix = "com.openfaas.annotations."
// MakeDeployHandler returns a handler to deploy a function
func MakeDeployHandler(client *containerd.Client, cni gocni.CNI, secretMountPath string, alwaysPull bool) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
if r.Body == nil {
@ -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),
@ -151,8 +148,18 @@ func deploy(ctx context.Context, req types.FunctionDeployment, client *container
oci.WithCapabilities([]string{"CAP_NET_RAW"}),
oci.WithMounts(mounts),
oci.WithEnv(envs),
oci.WithLinuxDevice("/dev/kvm", "rmw"),
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 {

View File

@ -5,6 +5,7 @@ import (
"fmt"
"log"
"strings"
"time"
"github.com/opencontainers/runtime-spec/specs-go"
@ -27,6 +28,7 @@ type Function struct {
secrets []string
envVars map[string]string
envProcess string
createdAt time.Time
}
// ListFunctions returns a map of all functions with running tasks on namespace
@ -81,6 +83,11 @@ func GetFunction(client *containerd.Client, name string) (Function, error) {
return Function{}, fmt.Errorf("unable to load function spec for reading secrets: %s, error %s", name, err)
}
info, err := c.Info(ctx)
if err != nil {
return Function{}, fmt.Errorf("can't load info for: %s, error %s", name, err)
}
envVars, envProcess := readEnvFromProcessEnv(spec.Process.Env)
secrets := readSecretsFromMounts(spec.Mounts)
@ -92,6 +99,7 @@ func GetFunction(client *containerd.Client, name string) (Function, error) {
fn.secrets = secrets
fn.envVars = envVars
fn.envProcess = envProcess
fn.createdAt = info.CreatedAt
replicas := 0
task, err := c.Task(ctx, nil)

View File

@ -34,6 +34,7 @@ func MakeReadHandler(client *containerd.Client) func(w http.ResponseWriter, r *h
Secrets: fn.secrets,
EnvVars: fn.envVars,
EnvProcess: fn.envProcess,
CreatedAt: fn.createdAt,
})
}
@ -41,6 +42,5 @@ func MakeReadHandler(client *containerd.Client) func(w http.ResponseWriter, r *h
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write(body)
}
}

View File

@ -26,6 +26,7 @@ func MakeReplicaReaderHandler(client *containerd.Client) func(w http.ResponseWri
Secrets: f.secrets,
EnvVars: f.envVars,
EnvProcess: f.envProcess,
CreatedAt: f.createdAt,
}
functionBytes, _ := json.Marshal(found)

View File

@ -74,8 +74,9 @@ func NewHandlerFunc(config types.FaaSConfig, resolver BaseURLResolver) http.Hand
http.MethodPut,
http.MethodPatch,
http.MethodDelete,
http.MethodGet:
http.MethodGet,
http.MethodOptions,
http.MethodHead:
proxyRequest(w, r, proxyClient, resolver)
default:

View File

@ -1,5 +1,7 @@
package types
import "time"
// FunctionDeployment represents a request to create or update a Function.
type FunctionDeployment struct {
@ -100,7 +102,9 @@ type FunctionStatus struct {
// mount-point.
ReadOnlyRootFilesystem bool `json:"readOnlyRootFilesystem,omitempty"`
// ** Status fields *8
// ================
// Fields for status
// ================
// InvocationCount count of invocations
InvocationCount float64 `json:"invocationCount,omitempty"`
@ -111,4 +115,8 @@ type FunctionStatus struct {
// AvailableReplicas is the count of replicas ready to receive
// invocations as reported by the faas-provider
AvailableReplicas uint64 `json:"availableReplicas,omitempty"`
// CreatedAt is the time read back from the faas backend's
// data store for when the function or its container was created.
CreatedAt time.Time `json:"createdAt,omitempty"`
}

2
vendor/modules.txt generated vendored
View File

@ -195,7 +195,7 @@ github.com/opencontainers/runtime-spec/specs-go
# github.com/openfaas/faas v0.0.0-20201205125747-9bbb25e3c7c4
## explicit
github.com/openfaas/faas/gateway/requests
# github.com/openfaas/faas-provider v0.17.0
# github.com/openfaas/faas-provider v0.17.3
## explicit
github.com/openfaas/faas-provider
github.com/openfaas/faas-provider/auth