From cbfefb6fa53bdba70bc73a07c54d55fa2cd028a8 Mon Sep 17 00:00:00 2001 From: Shikachuu Date: Sat, 18 Sep 2021 00:42:19 +0200 Subject: [PATCH] Extend the Function type with a memoryLimit field, create a conversion to k8s resource value and return it through the REST API. Signed-off-by: Shikachuu --- pkg/provider/handlers/functions.go | 2 ++ pkg/provider/handlers/read.go | 3 +++ 2 files changed, 5 insertions(+) diff --git a/pkg/provider/handlers/functions.go b/pkg/provider/handlers/functions.go index a7031c7..ef638a4 100644 --- a/pkg/provider/handlers/functions.go +++ b/pkg/provider/handlers/functions.go @@ -29,6 +29,7 @@ type Function struct { secrets []string envVars map[string]string envProcess string + memoryLimit int64 createdAt time.Time } @@ -112,6 +113,7 @@ func GetFunction(client *containerd.Client, name string, namespace string) (Func fn.envVars = envVars fn.envProcess = envProcess fn.createdAt = info.CreatedAt + fn.memoryLimit = *spec.Linux.Resources.Memory.Limit replicas := 0 task, err := c.Task(ctx, nil) diff --git a/pkg/provider/handlers/read.go b/pkg/provider/handlers/read.go index fecaad9..f487866 100644 --- a/pkg/provider/handlers/read.go +++ b/pkg/provider/handlers/read.go @@ -2,6 +2,7 @@ package handlers import ( "encoding/json" + "k8s.io/apimachinery/pkg/api/resource" "log" "net/http" @@ -37,6 +38,7 @@ func MakeReadHandler(client *containerd.Client) func(w http.ResponseWriter, r *h for _, fn := range fns { annotations := &fn.annotations labels := &fn.labels + memory := resource.NewQuantity(fn.memoryLimit, resource.BinarySI) res = append(res, types.FunctionStatus{ Name: fn.name, Image: fn.image, @@ -47,6 +49,7 @@ func MakeReadHandler(client *containerd.Client) func(w http.ResponseWriter, r *h Secrets: fn.secrets, EnvVars: fn.envVars, EnvProcess: fn.envProcess, + Limits: &types.FunctionResources{Memory: memory.String()}, CreatedAt: fn.createdAt, }) }