@@ -19,13 +19,15 @@ import (
1919 awscreds "sigs.k8s.io/cluster-api-provider-aws/cmd/clusterawsadm/credentials"
2020 iamv1 "sigs.k8s.io/cluster-api-provider-aws/iam/api/v1beta1"
2121
22+ "github.com/vmware-tanzu/tanzu-framework/pkg/v1/config"
2223 "github.com/vmware-tanzu/tanzu-framework/pkg/v1/tkg/web/server/models"
2324)
2425
2526const (
26- defaultControlPlaneMinMemoryInGB = 8
27- defaultControlPlaneMinCPU = 2
28- tanzuMissionControlPoliciesSID = "tmccloudvmwarecom"
27+ defaultNodeMinMemoryInGB = 8
28+ defaultNodeMinCPU = 2
29+ cpuArm64 = "arm64"
30+ tanzuMissionControlPoliciesSID = "tmccloudvmwarecom"
2931)
3032
3133type client struct {
@@ -372,8 +374,9 @@ func (c *client) ListInstanceTypes(optionalAZName string) ([]string, error) {
372374 if err != nil {
373375 return nil , err
374376 }
375- filteredInstances := filterInstanceType (candidates )
376- diffInstancesPerAz := getSetDifference (instances , filteredInstances )
377+ // filter and build a list of unsupported instance types
378+ unsupportedInstances := getUnsupportedInstanceTypes (candidates )
379+ diffInstancesPerAz := getSetDifference (instances , unsupportedInstances )
377380
378381 return diffInstancesPerAz , nil
379382 }
@@ -383,8 +386,8 @@ func (c *client) ListInstanceTypes(optionalAZName string) ([]string, error) {
383386 return nil , err
384387 }
385388
386- // here we filter the unsupported instance types
387- filteredInstances := filterInstanceType (candidates )
389+ // filter and build a list of unsupported instance types
390+ unsupportedInstances := getUnsupportedInstanceTypes (candidates )
388391 var res []string
389392 for i , az := range azs .AvailabilityZones {
390393 filters := []* ec2.Filter {
@@ -398,7 +401,7 @@ func (c *client) ListInstanceTypes(optionalAZName string) ([]string, error) {
398401 instances , err := getInstanceTypeOffering (svc , filter )
399402
400403 // Do the set difference operation to filter out the unsupported instances
401- diffInstancesPerAz := getSetDifference (instances , filteredInstances )
404+ diffInstancesPerAz := getSetDifference (instances , unsupportedInstances )
402405 if err != nil {
403406 return nil , err
404407 }
@@ -412,10 +415,31 @@ func (c *client) ListInstanceTypes(optionalAZName string) ([]string, error) {
412415 return res , nil
413416}
414417
415- // meetsNodeMininumRequirements checks if the node meet the minimum requirements of the controlplane node
416- func meetsNodeMininumRequirements (instanceInfo * ec2.InstanceTypeInfo ) bool {
417- return ((* instanceInfo .MemoryInfo .SizeInMiB / 1024 ) >= defaultControlPlaneMinMemoryInGB ) &&
418- (* instanceInfo .VCpuInfo .DefaultVCpus >= defaultControlPlaneMinCPU )
418+ // meetsNodeMinimumRequirements checks if the instance type meets the minimum requirements of the target node
419+ func meetsNodeMinimumRequirements (instanceInfo * ec2.InstanceTypeInfo ) bool {
420+ return ((* instanceInfo .MemoryInfo .SizeInMiB / 1024 ) >= defaultNodeMinMemoryInGB ) &&
421+ (* instanceInfo .VCpuInfo .DefaultVCpus >= defaultNodeMinCPU )
422+ }
423+
424+ // isSupportedInstance checks feature flag to determine if CPU supported architecture filters should be applied
425+ func isSupportedInstance (instanceInfo * ec2.InstanceTypeInfo ) bool {
426+ if config .IsFeatureActivated (config .FeatureFlagAwsInstanceTypesExcludeArm ) {
427+ // feature flag is active; apply filtering
428+ return isSupportedCPUArchitecture (instanceInfo )
429+ }
430+ return true
431+ }
432+
433+ // isSupportedCPUArchitecture checks if the node includes unsupported CPU architecture
434+ func isSupportedCPUArchitecture (instanceInfo * ec2.InstanceTypeInfo ) bool {
435+ // SupportedArchitectures []*string is a list of CPU architectures which are supported in the instance type
436+ // if arm64 is present then exclude this instance type
437+ for _ , cpu := range instanceInfo .ProcessorInfo .SupportedArchitectures {
438+ if * cpu == cpuArm64 {
439+ return false
440+ }
441+ }
442+ return true
419443}
420444
421445func getInstanceTypes (svc * ec2.EC2 ) ([]* ec2.InstanceTypeInfo , error ) {
@@ -475,12 +499,13 @@ func getSetDifference(a, b []string) (diff []string) {
475499 return diff
476500}
477501
478- func filterInstanceType (ss []* ec2.InstanceTypeInfo ) (ret []string ) {
479- for _ , s := range ss {
480- // using control-plane node requirements as the criteria to filter the unsupported instance type
481- controlPlaneTest := meetsNodeMininumRequirements (s )
482- if ! controlPlaneTest {
483- ret = append (ret , aws .StringValue (s .InstanceType ))
502+ // getUnsupportedInstanceTypes generates list of unsupported instance types
503+ func getUnsupportedInstanceTypes (instanceTypes []* ec2.InstanceTypeInfo ) (ret []string ) {
504+ for _ , instanceTypeObj := range instanceTypes {
505+ // using node requirements as the criteria to filter the unsupported instance type
506+ supportedInstanceType := meetsNodeMinimumRequirements (instanceTypeObj ) && isSupportedInstance (instanceTypeObj )
507+ if ! supportedInstanceType {
508+ ret = append (ret , aws .StringValue (instanceTypeObj .InstanceType ))
484509 }
485510 }
486511 return
0 commit comments