Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(eks): update nodegroup gpu check #31445

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
6 changes: 3 additions & 3 deletions packages/aws-cdk-lib/aws-eks/lib/managed-nodegroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -602,11 +602,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)));
}

Expand Down
41 changes: 38 additions & 3 deletions packages/aws-cdk-lib/aws-eks/test/nodegroup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down Expand Up @@ -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'),
],
});

Expand Down Expand Up @@ -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);
});
});
});
Loading