Skip to content

Commit 87e5e4f

Browse files
authored
AWS filter out arm64 instance type options (vmware-tanzu#1657)
Add backend filtering for arm64 cpu based instance types to be removed from AWS
1 parent bac6d03 commit 87e5e4f

File tree

4 files changed

+237
-201
lines changed

4 files changed

+237
-201
lines changed

pkg/v1/config/clientconfig.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ const (
4646
// AVI_MANAGEMENT_CLUSTER_CONTROL_PLANE_VIP_NETWORK_NAME and AVI_MANAGEMENT_CLUSTER_CONTROL_PLANE_VIP_NETWORK_CIDR
4747
// when creating a cluster.
4848
FeatureFlagManagementClusterNetworkSeparation = "features.management-cluster.network-separation-beta"
49+
// AWS Instance Types Exclude ARM feature flags determine whether instance types with processor architecture
50+
// support of ARM should be included when discovering available AWS instance types. Setting feature flag to true
51+
// filters out ARM supporting instance types; false allows ARM instance types to be included in results.
52+
FeatureFlagAwsInstanceTypesExcludeArm = "features.management-cluster.aws-instance-types-exclude-arm"
4953
)
5054

5155
// DefaultCliFeatureFlags is used to populate an initially empty config file with default values for feature flags.
@@ -73,6 +77,7 @@ var (
7377
FeatureFlagManagementClusterCustomNameservers: false,
7478
FeatureFlagClusterCustomNameservers: false,
7579
FeatureFlagManagementClusterNetworkSeparation: false,
80+
FeatureFlagAwsInstanceTypesExcludeArm: true,
7681
}
7782
)
7883

pkg/v1/tkg/aws/client.go

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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

2526
const (
26-
defaultControlPlaneMinMemoryInGB = 8
27-
defaultControlPlaneMinCPU = 2
28-
tanzuMissionControlPoliciesSID = "tmccloudvmwarecom"
27+
defaultNodeMinMemoryInGB = 8
28+
defaultNodeMinCPU = 2
29+
cpuArm64 = "arm64"
30+
tanzuMissionControlPoliciesSID = "tmccloudvmwarecom"
2931
)
3032

3133
type 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

421445
func 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

pkg/v1/tkg/manifest/server/zz_generated.bindata.go

Lines changed: 182 additions & 182 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/v1/tkg/web/node-server/src/routes/api/mockService.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,9 @@ router.get(`${ENDPOINT}/providers/aws/nodetypes`, (req, res) => {
687687
'm5.xlarge',
688688
'm5a.2xlarge',
689689
'm5a.4xlarge',
690+
'c6gn.small',
691+
'c6gn.medium',
692+
'c6gn.large',
690693
'r4.8xlarge',
691694
'i3.xlarge',
692695
't3.small',
@@ -698,7 +701,10 @@ router.get(`${ENDPOINT}/providers/aws/nodetypes`, (req, res) => {
698701
'm5a.2xlarge',
699702
'm5a.4xlarge',
700703
'r4.8xlarge',
701-
'i3.xlarge'
704+
'i3.xlarge',
705+
't4g.small',
706+
't4g.medium',
707+
't4g.large'
702708
]);
703709
});
704710

0 commit comments

Comments
 (0)