mirror of
https://github.com/openfaas/faasd.git
synced 2025-06-08 08:05:03 +00:00
* Fixes upstream deprecations for containerd * Fixes deprecations in ioutil package usage * Break out separate files for function handlers * Upgrades containerd to 1.7.22 * Fixes default namespace functionality * Pre-deploy checks as per license agreement * Removes extra log messages for payload in HTTP handlers, you can enable FAAS_DEBUG=1 in the CLI instead to see this from the client's perspective * Add additional Google DNS server 8.8.4.4 for functions Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
62 lines
1.3 KiB
Go
62 lines
1.3 KiB
Go
package handlers
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"log"
|
|
"time"
|
|
|
|
"github.com/containerd/containerd"
|
|
"github.com/containerd/containerd/namespaces"
|
|
)
|
|
|
|
type Function struct {
|
|
name string
|
|
namespace string
|
|
image string
|
|
pid uint32
|
|
replicas int
|
|
IP string
|
|
labels map[string]string
|
|
annotations map[string]string
|
|
secrets []string
|
|
envVars map[string]string
|
|
envProcess string
|
|
memoryLimit int64
|
|
createdAt time.Time
|
|
}
|
|
|
|
// ListFunctions returns a map of all functions with running tasks on namespace
|
|
func ListFunctions(client *containerd.Client, namespace string) (map[string]*Function, error) {
|
|
|
|
// Check if namespace exists, and it has the openfaas label
|
|
valid, err := validNamespace(client.NamespaceService(), namespace)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if !valid {
|
|
return nil, errors.New("namespace not valid")
|
|
}
|
|
|
|
ctx := namespaces.WithNamespace(context.Background(), namespace)
|
|
functions := make(map[string]*Function)
|
|
|
|
containers, err := client.Containers(ctx)
|
|
if err != nil {
|
|
return functions, err
|
|
}
|
|
|
|
for _, c := range containers {
|
|
name := c.ID()
|
|
f, err := GetFunction(client, name, namespace)
|
|
if err != nil {
|
|
log.Printf("skipping %s, error: %s", name, err)
|
|
} else {
|
|
functions[name] = &f
|
|
}
|
|
}
|
|
|
|
return functions, nil
|
|
}
|