From 0c0088e8b0ef1e918f12baa7f7c4b0dc7e89b265 Mon Sep 17 00:00:00 2001 From: Shikachuu Date: Mon, 20 Sep 2021 21:05:01 +0200 Subject: [PATCH] Change readMemoryLimitFromSpec, to a more clear implementation, edited error message. Signed-off-by: Shikachuu --- pkg/provider/handlers/functions.go | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/pkg/provider/handlers/functions.go b/pkg/provider/handlers/functions.go index 7f3a33b..f76cbee 100644 --- a/pkg/provider/handlers/functions.go +++ b/pkg/provider/handlers/functions.go @@ -93,7 +93,7 @@ func GetFunction(client *containerd.Client, name string, namespace string) (Func spec, err := c.Spec(ctx) if err != nil { - return Function{}, fmt.Errorf("unable to load function spec for reading secrets and limits: %s, error %w", name, err) + return Function{}, fmt.Errorf("unable to load function %s error: %w", name, err) } info, err := c.Info(ctx) @@ -235,16 +235,7 @@ func findNamespace(target string, items []string) bool { } func readMemoryLimitFromSpec(spec *specs.Spec) int64 { - if spec.Linux != nil { - return 0 - } - if spec.Linux.Resources == nil { - return 0 - } - if spec.Linux.Resources.Memory == nil { - return 0 - } - if spec.Linux.Resources.Memory.Limit == nil { + if spec.Linux == nil || spec.Linux.Resources == nil || spec.Linux.Resources.Memory == nil || spec.Linux.Resources.Memory.Limit == nil { return 0 } return *spec.Linux.Resources.Memory.Limit