From 716fd1369041bf7480469542bde15020b5b09db3 Mon Sep 17 00:00:00 2001 From: aiordache Date: Fri, 24 Jul 2020 10:17:48 +0200 Subject: [PATCH] sort cpu values in conversion to fargate values Signed-off-by: aiordache Signed-off-by: Nicolas De Loof --- ecs/pkg/amazon/backend/cloudformation_test.go | 2 +- ecs/pkg/amazon/backend/convert.go | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ecs/pkg/amazon/backend/cloudformation_test.go b/ecs/pkg/amazon/backend/cloudformation_test.go index 679d3fe6e..0c7edd8f6 100644 --- a/ecs/pkg/amazon/backend/cloudformation_test.go +++ b/ecs/pkg/amazon/backend/cloudformation_test.go @@ -167,7 +167,7 @@ services: memory: 2043248M `) _, err := Backend{}.Convert(model) - assert.ErrorContains(t, err, "The resources requested are not supported by ECS/Fargate") + assert.ErrorContains(t, err, "the resources requested are not supported by ECS/Fargate") } func TestLoadBalancerTypeNetwork(t *testing.T) { diff --git a/ecs/pkg/amazon/backend/convert.go b/ecs/pkg/amazon/backend/convert.go index 49b9b4454..e3591ee70 100644 --- a/ecs/pkg/amazon/backend/convert.go +++ b/ecs/pkg/amazon/backend/convert.go @@ -2,6 +2,7 @@ package backend import ( "fmt" + "sort" "strconv" "strings" "time" @@ -148,7 +149,14 @@ func toLimits(service types.ServiceConfig) (string, string, error) { return "", "", err } - for cpu, mem := range cpuToMem { + var cpus []int64 + for k := range cpuToMem { + cpus = append(cpus, k) + } + sort.Slice(cpus, func(i, j int) bool { return cpus[i] < cpus[j] }) + + for _, cpu := range cpus { + mem := cpuToMem[cpu] if v <= cpu*MiB { for _, m := range mem { if limits.MemoryBytes <= m*MiB { @@ -159,7 +167,7 @@ func toLimits(service types.ServiceConfig) (string, string, error) { } } } - return "", "", fmt.Errorf("The resources requested are not supported by ECS/Fargate") + return "", "", fmt.Errorf("the resources requested are not supported by ECS/Fargate") } func toContainerReservation(service types.ServiceConfig) (string, int, error) {