Bläddra i källkod

sort cpu values in conversion to fargate values

Signed-off-by: aiordache <[email protected]>
Signed-off-by: Nicolas De Loof <[email protected]>
aiordache 5 år sedan
förälder
incheckning
716fd13690
2 ändrade filer med 11 tillägg och 3 borttagningar
  1. 1 1
      ecs/pkg/amazon/backend/cloudformation_test.go
  2. 10 2
      ecs/pkg/amazon/backend/convert.go

+ 1 - 1
ecs/pkg/amazon/backend/cloudformation_test.go

@@ -167,7 +167,7 @@ services:
           memory: 2043248M
           memory: 2043248M
 `)
 `)
 	_, err := Backend{}.Convert(model)
 	_, 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) {
 func TestLoadBalancerTypeNetwork(t *testing.T) {

+ 10 - 2
ecs/pkg/amazon/backend/convert.go

@@ -2,6 +2,7 @@ package backend
 
 
 import (
 import (
 	"fmt"
 	"fmt"
+	"sort"
 	"strconv"
 	"strconv"
 	"strings"
 	"strings"
 	"time"
 	"time"
@@ -148,7 +149,14 @@ func toLimits(service types.ServiceConfig) (string, string, error) {
 		return "", "", err
 		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 {
 		if v <= cpu*MiB {
 			for _, m := range mem {
 			for _, m := range mem {
 				if limits.MemoryBytes <= m*MiB {
 				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) {
 func toContainerReservation(service types.ServiceConfig) (string, int, error) {