diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-eks/test/integ.eks-cluster.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-eks/test/integ.eks-cluster.ts index 59011249edfa7..c43ef29fbfd0b 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-eks/test/integ.eks-cluster.ts +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-eks/test/integ.eks-cluster.ts @@ -75,6 +75,8 @@ class EksClusterStack extends Stack { this.assertNodeGroupCustomAmi(); + this.assertNodeGroupGpu(); + this.assertSimpleManifest(); this.assertManifestWithoutValidation(); @@ -277,6 +279,19 @@ class EksClusterStack extends Stack { nodeRole: this.cluster.defaultCapacity ? this.cluster.defaultCapacity.role : undefined, }); } + private assertNodeGroupGpu() { + // add a GPU nodegroup + this.cluster.addNodegroupCapacity('extra-ng-gpu', { + instanceTypes: [ + new ec2.InstanceType('p2.xlarge'), + new ec2.InstanceType('g5.xlarge'), + new ec2.InstanceType('g6e.xlarge'), + ], + minSize: 1, + // reusing the default capacity nodegroup instance role when available + nodeRole: this.cluster.defaultCapacity ? this.cluster.defaultCapacity.role : undefined, + }); + } private assertSpotCapacity() { // spot instances (up to 10) this.cluster.addAutoScalingGroupCapacity('spot', { diff --git a/packages/aws-cdk-lib/aws-eks/lib/managed-nodegroup.ts b/packages/aws-cdk-lib/aws-eks/lib/managed-nodegroup.ts index c1c0cc9232a38..974c27019ed26 100644 --- a/packages/aws-cdk-lib/aws-eks/lib/managed-nodegroup.ts +++ b/packages/aws-cdk-lib/aws-eks/lib/managed-nodegroup.ts @@ -612,11 +612,11 @@ const gpuAmiTypes: NodegroupAmiType[] = [ * This function check if the instanceType is GPU instance. * @param instanceType The EC2 instance type */ -function isGpuInstanceType(instanceType: InstanceType): boolean { +export function isGpuInstanceType(instanceType: InstanceType): boolean { //compare instanceType to known GPU InstanceTypes const knownGpuInstanceTypes = [InstanceClass.P2, InstanceClass.P3, InstanceClass.P3DN, InstanceClass.P4DE, InstanceClass.P4D, - InstanceClass.G3S, InstanceClass.G3, InstanceClass.G4DN, InstanceClass.G4AD, InstanceClass.G5, InstanceClass.G5G, - InstanceClass.INF1, InstanceClass.INF2]; + InstanceClass.G3S, InstanceClass.G3, InstanceClass.G4DN, InstanceClass.G4AD, InstanceClass.G5, InstanceClass.G5G, InstanceClass.G6, + InstanceClass.G6E, InstanceClass.INF1, InstanceClass.INF2]; return knownGpuInstanceTypes.some((c) => instanceType.sameInstanceClassAs(InstanceType.of(c, InstanceSize.LARGE))); } diff --git a/packages/aws-cdk-lib/aws-eks/test/nodegroup.test.ts b/packages/aws-cdk-lib/aws-eks/test/nodegroup.test.ts index 5bcebbc21082a..8a4e2c02a1024 100644 --- a/packages/aws-cdk-lib/aws-eks/test/nodegroup.test.ts +++ b/packages/aws-cdk-lib/aws-eks/test/nodegroup.test.ts @@ -6,7 +6,7 @@ import * as iam from '../../aws-iam'; import * as cdk from '../../core'; import * as cxapi from '../../cx-api'; import * as eks from '../lib'; -import { NodegroupAmiType, TaintEffect } from '../lib'; +import { isGpuInstanceType, NodegroupAmiType, TaintEffect } from '../lib'; /* eslint-disable max-len */ @@ -617,8 +617,8 @@ describe('node group', () => { new eks.Nodegroup(stack, 'Nodegroup', { cluster, instanceTypes: [ - new ec2.InstanceType('p3.large'), - new ec2.InstanceType('g3.large'), + new ec2.InstanceType('g6e.large'), + new ec2.InstanceType('g5.large'), ], }); @@ -1735,3 +1735,38 @@ describe('node group', () => { expect(() => cluster.addNodegroupCapacity('ng', { maxUnavailablePercentage: 101 })).toThrow(/maxUnavailablePercentage must be between 1 and 100/); }); }); + +describe('isGpuInstanceType', () => { + it('should return true for known GPU instance types', () => { + const gpuInstanceTypes = [ + ec2.InstanceType.of(ec2.InstanceClass.P2, ec2.InstanceSize.XLARGE), + ec2.InstanceType.of(ec2.InstanceClass.G3, ec2.InstanceSize.XLARGE), + ec2.InstanceType.of(ec2.InstanceClass.P4D, ec2.InstanceSize.LARGE), + ec2.InstanceType.of(ec2.InstanceClass.G6, ec2.InstanceSize.MEDIUM), + ec2.InstanceType.of(ec2.InstanceClass.G6E, ec2.InstanceSize.XLARGE2), + ]; + gpuInstanceTypes.forEach(instanceType => { + expect(isGpuInstanceType(instanceType)).toBe(true); + }); + }); + it('should return false for non-GPU instance types', () => { + const nonGpuInstanceTypes = [ + ec2.InstanceType.of(ec2.InstanceClass.T3, ec2.InstanceSize.MICRO), + ec2.InstanceType.of(ec2.InstanceClass.M5, ec2.InstanceSize.LARGE), + ec2.InstanceType.of(ec2.InstanceClass.C5, ec2.InstanceSize.XLARGE), + ]; + nonGpuInstanceTypes.forEach(instanceType => { + expect(isGpuInstanceType(instanceType)).toBe(false); + }); + }); + it('should return true for different sizes of GPU instance types', () => { + const gpuInstanceTypes = [ + ec2.InstanceType.of(ec2.InstanceClass.G6, ec2.InstanceSize.XLARGE), + ec2.InstanceType.of(ec2.InstanceClass.G6, ec2.InstanceSize.XLARGE16), + ec2.InstanceType.of(ec2.InstanceClass.G6, ec2.InstanceSize.XLARGE48), + ]; + gpuInstanceTypes.forEach(instanceType => { + expect(isGpuInstanceType(instanceType)).toBe(true); + }); + }); +});