From 4ec710ba6a59a191279216dff762a9a0e5f175a3 Mon Sep 17 00:00:00 2001 From: Brandon Wagner Date: Mon, 20 Jul 2020 12:19:16 -0500 Subject: [PATCH] treat amd64 the same as x86_64 --- README.md | 2 +- cmd/main.go | 2 +- pkg/selector/selector.go | 7 +++++++ pkg/selector/selector_test.go | 15 +++++++++++++++ pkg/selector/types.go | 2 +- 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 67f2843..1c681a4 100644 --- a/README.md +++ b/README.md @@ -139,7 +139,7 @@ Filter Flags: -z, --availability-zones strings Availability zones or zone ids to check EC2 capacity offered in specific AZs --baremetal Bare Metal instance types (.metal instances) -b, --burst-support Burstable instance types - -a, --cpu-architecture string CPU architecture [x86_64, i386, or arm64] + -a, --cpu-architecture string CPU architecture [x86_64/amd64, i386, or arm64] --current-generation Current generation instance types (explicitly set this to false to not return current generation instance types) --deny-list string List of instance types which should be excluded w/ regex syntax (Example: m[1-2]\.*) -e, --ena-support Instance types where ENA is supported or required diff --git a/cmd/main.go b/cmd/main.go index 77ead80..143da19 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -118,7 +118,7 @@ Full docs can be found at github.com/aws/amazon-` + binName cli.IntMinMaxRangeFlags(vcpus, cli.StringMe("c"), nil, "Number of vcpus available to the instance type.") cli.IntMinMaxRangeFlags(memory, cli.StringMe("m"), nil, "Amount of Memory available in MiB (Example: 4096)") cli.RatioFlag(vcpusToMemoryRatio, nil, nil, "The ratio of vcpus to memory in MiB. (Example: 1:2)") - cli.StringFlag(cpuArchitecture, cli.StringMe("a"), nil, "CPU architecture [x86_64, i386, or arm64]", nil) + cli.StringFlag(cpuArchitecture, cli.StringMe("a"), nil, "CPU architecture [x86_64/amd64, i386, or arm64]", nil) cli.IntMinMaxRangeFlags(gpus, cli.StringMe("g"), nil, "Total Number of GPUs (Example: 4)") cli.IntMinMaxRangeFlags(gpuMemoryTotal, nil, nil, "Number of GPUs' total memory in MiB (Example: 4096)") cli.StringFlag(placementGroupStrategy, nil, nil, "Placement group strategy: [cluster, partition, spread]", nil) diff --git a/pkg/selector/selector.go b/pkg/selector/selector.go index eabfa6c..1fb3f7f 100644 --- a/pkg/selector/selector.go +++ b/pkg/selector/selector.go @@ -62,6 +62,9 @@ const ( networkPerformance = "networkPerformance" allowList = "allowList" denyList = "denyList" + + cpuArchitectureAMD64 = "amd64" + cpuArchitectureX8664 = "x86_64" ) // New creates an instance of Selector provided an aws session @@ -149,6 +152,10 @@ func (itf Selector) rawFilter(filters Filters) ([]*ec2.InstanceTypeInfo, error) } } + if filters.CPUArchitecture != nil && *filters.CPUArchitecture == cpuArchitectureAMD64 { + *filters.CPUArchitecture = cpuArchitectureX8664 + } + if filters.AvailabilityZones != nil { locations = *filters.AvailabilityZones } else if filters.Region != nil { diff --git a/pkg/selector/selector_test.go b/pkg/selector/selector_test.go index 6344b41..6f596cf 100644 --- a/pkg/selector/selector_test.go +++ b/pkg/selector/selector_test.go @@ -554,3 +554,18 @@ func TestFilter_AllowAndDenyList(t *testing.T) { h.Ok(t, err) h.Assert(t, len(results) == 4, "Allow/Deny List Regex: 'c4.large' should return 4 instance types matching the regex but returned %d", len(results)) } + +func TestFilter_X8664_AMD64(t *testing.T) { + ec2Mock := setupMock(t, describeInstanceTypesPages, "t3_micro.json") + itf := selector.Selector{ + EC2: ec2Mock, + } + filters := selector.Filters{ + CPUArchitecture: aws.String("amd64"), + } + results, err := itf.Filter(filters) + h.Ok(t, err) + log.Println(results) + h.Assert(t, len(results) == 1, "Should only return 1 instance type with x86_64/amd64 cpu architecture") + h.Assert(t, results[0] == "t3.micro", "Should return t3.micro, got %s instead", results[0]) +} diff --git a/pkg/selector/types.go b/pkg/selector/types.go index ecd0bd1..1d1bbe2 100644 --- a/pkg/selector/types.go +++ b/pkg/selector/types.go @@ -96,7 +96,7 @@ type Filters struct { Burstable *bool // CPUArchitecture of the EC2 instance type - // Possible values are: x86_64 or arm64 + // Possible values are: x86_64/amd64 or arm64 CPUArchitecture *string // CurrentGeneration returns the latest generation of instance types