sort cpu values in conversion to fargate values

Signed-off-by: aiordache <anca.iordache@docker.com>
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
aiordache 2020-07-24 10:17:48 +02:00 committed by Nicolas De Loof
parent 94671e99e1
commit 716fd13690
No known key found for this signature in database
GPG Key ID: 9858809D6F8F6E7E
2 changed files with 11 additions and 3 deletions

View File

@ -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) {

View File

@ -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) {