Skip to content

Commit 43e5aeb

Browse files
committed
case insensitive selector evaluation for strings
1 parent 12196cb commit 43e5aeb

File tree

5 files changed

+18
-26
lines changed

5 files changed

+18
-26
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,8 @@ Filter Flags:
395395
-z, --availability-zones strings Availability zones or zone ids to check EC2 capacity offered in specific AZs
396396
--baremetal Bare Metal instance types (.metal instances)
397397
-b, --burst-support Burstable instance types
398-
-a, --cpu-architecture string CPU architecture [x86_64, amd64, x86_64_mac, i386, or arm64]
399-
--cpu-manufacturer string CPU manufacturer [amd, intel, aws]
398+
-a, --cpu-architecture string CPU architecture [x86_64, amd64, x86_64_mac, i386, arm64, or arm64_mac]
399+
--cpu-manufacturer string CPU manufacturer [amd, intel, aws, apple]
400400
--current-generation Current generation instance types (explicitly set this to false to not return current generation instance types)
401401
--dedicated-hosts Dedicated Hosts supported
402402
--deny-list string List of instance types which should be excluded w/ regex syntax (Example: m[1-2]\.*)

cmd/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ Full docs can be found at github.com/aws/amazon-` + binName
168168
cli.Int32MinMaxRangeFlags(vcpus, cli.StringMe("c"), nil, "Number of vcpus available to the instance type.")
169169
cli.ByteQuantityMinMaxRangeFlags(memory, cli.StringMe("m"), nil, "Amount of Memory available (Example: 4 GiB)")
170170
cli.RatioFlag(vcpusToMemoryRatio, nil, nil, "The ratio of vcpus to GiBs of memory. (Example: 1:2)")
171-
cli.StringOptionsFlag(cpuArchitecture, cli.StringMe("a"), nil, "CPU architecture [x86_64, amd64, x86_64_mac, i386, or arm64]", []string{"x86_64", "x86_64_mac", "amd64", "i386", "arm64"})
172-
cli.StringOptionsFlag(cpuManufacturer, nil, nil, "CPU manufacturer [amd, intel, aws]", []string{"amd", "intel", "aws"})
171+
cli.StringOptionsFlag(cpuArchitecture, cli.StringMe("a"), nil, "CPU architecture [x86_64, amd64, x86_64_mac, i386, arm64, or arm64_mac]", []string{"x86_64", "x86_64_mac", "amd64", "i386", "arm64", "arm64_mac"})
172+
cli.StringOptionsFlag(cpuManufacturer, nil, nil, "CPU manufacturer [amd, intel, aws, apple]", []string{"amd", "intel", "aws", "apple"})
173173
cli.Int32MinMaxRangeFlags(gpus, cli.StringMe("g"), nil, "Total Number of GPUs (Example: 4)")
174174
cli.ByteQuantityMinMaxRangeFlags(gpuMemoryTotal, nil, nil, "Number of GPUs' total memory (Example: 4 GiB)")
175175
cli.StringFlag(gpuManufacturer, nil, nil, "GPU Manufacturer name (Example: NVIDIA)", nil)

pkg/cli/flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ func (cl *CommandLineInterface) StringOptionsFlagOnFlagSet(flagSet *pflag.FlagSe
386386
return nil
387387
}
388388
for _, v := range validOpts {
389-
if v == *val.(*string) {
389+
if strings.EqualFold(v, *val.(*string)) {
390390
return nil
391391
}
392392
}

pkg/selector/comparators.go

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func isSupportedFromString(instanceTypeValue *string, target *string) bool {
4141
if instanceTypeValue == nil {
4242
return false
4343
}
44-
return *instanceTypeValue == *target
44+
return strings.EqualFold(*instanceTypeValue, *target)
4545
}
4646

4747
func isSupportedFromStrings(instanceTypeValues []*string, target *string) bool {
@@ -83,7 +83,7 @@ func isSupportedUsageClassType(instanceTypeValue []ec2types.UsageClassType, targ
8383
}
8484

8585
for _, potentialType := range instanceTypeValue {
86-
if potentialType == *target {
86+
if strings.EqualFold(string(potentialType), string(*target)) {
8787
return true
8888
}
8989
}
@@ -102,7 +102,7 @@ func isSupportedArchitectureType(instanceTypeValue []ec2types.ArchitectureType,
102102
}
103103

104104
for _, potentialType := range instanceTypeValue {
105-
if potentialType == *target {
105+
if strings.EqualFold(string(potentialType), string(*target)) {
106106
return true
107107
}
108108
}
@@ -120,7 +120,7 @@ func isSupportedVirtualizationType(instanceTypeValue []ec2types.VirtualizationTy
120120
return true
121121
}
122122
for _, potentialType := range instanceTypeValue {
123-
if potentialType == *target {
123+
if strings.EqualFold(string(potentialType), string(*target)) {
124124
return true
125125
}
126126
}
@@ -134,7 +134,7 @@ func isSupportedInstanceTypeHypervisorType(instanceTypeValue ec2types.InstanceTy
134134
if reflect.ValueOf(*target).IsZero() {
135135
return true
136136
}
137-
if instanceTypeValue == *target {
137+
if strings.EqualFold(string(instanceTypeValue), string(*target)) {
138138
return true
139139
}
140140
return false
@@ -151,7 +151,7 @@ func isSupportedRootDeviceType(instanceTypeValue []ec2types.RootDeviceType, targ
151151
return true
152152
}
153153
for _, potentialType := range instanceTypeValue {
154-
if potentialType == *target {
154+
if strings.EqualFold(string(potentialType), string(*target)) {
155155
return true
156156
}
157157
}
@@ -165,7 +165,7 @@ func isMatchingCpuArchitecture(instanceTypeValue CPUManufacturer, target *CPUMan
165165
if reflect.ValueOf(*target).IsZero() {
166166
return true
167167
}
168-
if instanceTypeValue == *target {
168+
if strings.EqualFold(string(instanceTypeValue), string(*target)) {
169169
return true
170170
}
171171
return false
@@ -376,19 +376,6 @@ func getEBSOptimizedBaselineIOPS(ebsInfo *ec2types.EbsInfo) *int32 {
376376
return ebsInfo.EbsOptimizedInfo.BaselineIops
377377
}
378378

379-
func getCPUManufacturer(instanceTypeInfo *ec2types.InstanceTypeInfo) CPUManufacturer {
380-
for _, it := range instanceTypeInfo.ProcessorInfo.SupportedArchitectures {
381-
if it == ec2types.ArchitectureTypeArm64 {
382-
return CPUManufacturerAWS
383-
}
384-
}
385-
386-
if amdRegex.Match([]byte(instanceTypeInfo.InstanceType)) {
387-
return CPUManufacturerAMD
388-
}
389-
return CPUManufacturerIntel
390-
}
391-
392379
// getInstanceTypeGeneration returns the generation from an instance type name
393380
// i.e. c7i.xlarge -> 7
394381
// if any error occurs, 0 will be returned.

pkg/selector/selector.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,16 @@ func (s Selector) prepareFilter(ctx context.Context, filters Filters, instanceTy
309309
filterInstanceTypes = nil
310310
}
311311

312+
var cpuManufacturerFilter *string
313+
if filters.CPUManufacturer != nil {
314+
cpuManufacturerFilter = aws.String(string(*filters.CPUManufacturer))
315+
}
316+
312317
// filterToInstanceSpecMappingPairs is a map of filter name [key] to filter pair [value].
313318
// A filter pair includes user input filter value and instance spec value retrieved from DescribeInstanceTypes
314319
filterToInstanceSpecMappingPairs := map[string]filterPair{
315320
cpuArchitecture: {filters.CPUArchitecture, instanceTypeInfo.ProcessorInfo.SupportedArchitectures},
316-
cpuManufacturer: {filters.CPUManufacturer, getCPUManufacturer(&instanceTypeInfo.InstanceTypeInfo)},
321+
cpuManufacturer: {cpuManufacturerFilter, instanceTypeInfo.ProcessorInfo.Manufacturer},
317322
usageClass: {filters.UsageClass, instanceTypeInfo.SupportedUsageClasses},
318323
rootDeviceType: {filters.RootDeviceType, instanceTypeInfo.SupportedRootDeviceTypes},
319324
hibernationSupported: {filters.HibernationSupported, instanceTypeInfo.HibernationSupported},

0 commit comments

Comments
 (0)