diff --git a/ecs/pkg/amazon/backend/cloudformation_test.go b/ecs/pkg/amazon/backend/cloudformation_test.go index e7efad187..c8622a1ac 100644 --- a/ecs/pkg/amazon/backend/cloudformation_test.go +++ b/ecs/pkg/amazon/backend/cloudformation_test.go @@ -154,6 +154,21 @@ services: assert.Equal(t, def.Cpu, "4096") assert.Equal(t, def.Memory, "8192") } +func TestTaskSizeConvertFailure(t *testing.T) { + model := loadConfig(t, "test", ` +version: "3" +services: + test: + image: nginx + deploy: + resources: + limits: + cpus: '0.5' + memory: 2043248M +`) + _, err := Backend{}.Convert(model) + assert.ErrorContains(t, err, "unable to find cpu/mem for the required resources") +} func TestLoadBalancerTypeNetwork(t *testing.T) { template := convertYaml(t, "test", ` @@ -256,6 +271,13 @@ func load(t *testing.T, paths ...string) *types.Project { } func convertYaml(t *testing.T, name string, yaml string) *cloudformation.Template { + model := loadConfig(t, name, yaml) + template, err := Backend{}.Convert(model) + assert.NilError(t, err) + return template +} + +func loadConfig(t *testing.T, name string, yaml string) *types.Project { dict, err := loader.ParseYAML([]byte(yaml)) assert.NilError(t, err) model, err := loader.Load(types.ConfigDetails{ @@ -266,7 +288,5 @@ func convertYaml(t *testing.T, name string, yaml string) *cloudformation.Templat options.Name = "Test" }) assert.NilError(t, err) - template, err := Backend{}.Convert(model) - assert.NilError(t, err) - return template + return model } diff --git a/ecs/pkg/amazon/backend/convert.go b/ecs/pkg/amazon/backend/convert.go index 6bd66255d..828618b45 100644 --- a/ecs/pkg/amazon/backend/convert.go +++ b/ecs/pkg/amazon/backend/convert.go @@ -116,7 +116,7 @@ func toSystemControls(sysctls types.Mapping) []ecs.TaskDefinition_SystemControl return sys } -const Mb = 1024 * 1024 +const MiB = 1024 * 1024 func toLimits(service types.ServiceConfig) (string, string, error) { // All possible cpu/mem values for Fargate @@ -149,9 +149,9 @@ func toLimits(service types.ServiceConfig) (string, string, error) { } for cpu, mem := range cpuToMem { - if v <= cpu*Mb { + if v <= cpu*MiB { for _, m := range mem { - if limits.MemoryBytes <= m*Mb { + if limits.MemoryBytes <= m*MiB { cpuLimit = strconv.FormatInt(cpu, 10) memLimit = strconv.FormatInt(int64(m), 10) return cpuLimit, memLimit, nil @@ -174,7 +174,7 @@ func toContainerReservation(service types.ServiceConfig) (string, int, error) { if reservations == nil { return cpuReservation, memReservation, nil } - return reservations.NanoCPUs, int(reservations.MemoryBytes / Mb), nil + return reservations.NanoCPUs, int(reservations.MemoryBytes / MiB), nil } func toRequiresCompatibilities(isolation string) []*string {