Skip to content

Commit

Permalink
fix: update the instance type and size reg expression to accept value…
Browse files Browse the repository at this point in the history
…s that contains dashes like m7i-flex
  • Loading branch information
moelasmar committed Jan 17, 2024
1 parent 539cdc5 commit 3b0d489
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 322 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3485,7 +3485,7 @@
"InstanceTypes": [
"c5.large",
"c5a.large",
"c5d.large"
"m7i-flex.large"
],
"NodeRole": {
"Fn::GetAtt": [
Expand Down Expand Up @@ -4047,7 +4047,7 @@
"OpenIdConnectIssuerUrl"
]
},
"CodeHash": "fe07e5b9d977c2146233a33c70d0afd1d984895920c4f555e3e2282e022361f6"
"CodeHash": "9243a37c51ef38f361f19b938e8dd0cd37fd4a2c18460dca4546ad79d72b465c"
},
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
Expand Down Expand Up @@ -4348,7 +4348,7 @@
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-us-east-1"
},
"S3Key": "fe07e5b9d977c2146233a33c70d0afd1d984895920c4f555e3e2282e022361f6.zip"
"S3Key": "9243a37c51ef38f361f19b938e8dd0cd37fd4a2c18460dca4546ad79d72b465c.zip"
},
"Timeout": 900,
"MemorySize": 128,
Expand Down Expand Up @@ -4394,7 +4394,7 @@
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-us-east-1"
},
"S3Key": "f58e5b0009fc349d5e78d41594373bd6723e705a3c961a42adfbefa36cbe1bcf.zip"
"S3Key": "7e3e77a5ee3d2db0eeb9f1ca27d1864b68dcd5f1ef5f72269689043834710c60.zip"
},
"Timeout": 900,
"MemorySize": 128,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class EksClusterStack extends Stack {
instanceTypes: [
new ec2.InstanceType('c5.large'),
new ec2.InstanceType('c5a.large'),
new ec2.InstanceType('c5d.large'),
new ec2.InstanceType('m7i-flex.large'),
],
minSize: 3,
// reusing the default capacity nodegroup instance role when available
Expand Down
4 changes: 2 additions & 2 deletions packages/aws-cdk-lib/aws-ec2/lib/instance-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1522,7 +1522,7 @@ export class InstanceType {
*/
public get architecture(): InstanceArchitecture {
// capture the family, generation, capabilities, and size portions of the instance type id
const instanceTypeComponents = this.instanceTypeIdentifier.match(/^([a-z]+)(\d{1,2})([a-z]*)\.([a-z0-9]+)$/);
const instanceTypeComponents = this.instanceTypeIdentifier.match(/^([a-z]+)(\d{1,2})([a-z\-]*)\.([a-z0-9\-]+)$/);
if (instanceTypeComponents == null) {
throw new Error('Malformed instance type identifier');
}
Expand All @@ -1540,7 +1540,7 @@ export class InstanceType {
}

public sameInstanceClassAs(other: InstanceType): boolean {
const instanceClass: RegExp = /^([a-z]+\d{1,2}[a-z]*)\.([a-z0-9]+)$/;
const instanceClass: RegExp = /^([a-z]+\d{1,2}[a-z\-]*)\.([a-z0-9\-]+)$/;
const instanceClassId = this.instanceTypeIdentifier.match(instanceClass);
const otherInstanceClassId = other.instanceTypeIdentifier.match(instanceClass);
if (instanceClassId == null || otherInstanceClassId == null) {
Expand Down
20 changes: 19 additions & 1 deletion packages/aws-cdk-lib/aws-ec2/test/instance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ describe('instance', () => {
});
test('instance architecture is correctly discerned for x86-64 instance', () => {
// GIVEN
const sampleInstanceClasses = ['c5', 'm5ad', 'r5n', 'm6', 't3a', 'r6i', 'r6a', 'p4de', 'p5']; // A sample of x86-64 instance classes
const sampleInstanceClasses = ['c5', 'm5ad', 'r5n', 'm6', 't3a', 'r6i', 'r6a', 'p4de', 'p5', 'm7i-flex']; // A sample of x86-64 instance classes

for (const instanceClass of sampleInstanceClasses) {
// WHEN
Expand Down Expand Up @@ -741,6 +741,24 @@ test('sameInstanceClassAs compares InstanceTypes correctly regardless of size',
expect(largerInstanceType.sameInstanceClassAs(comparitor)).toBeTruthy();
});

test('sameInstanceClassAs compares InstanceTypes contains dashes', () => {
// GIVEN
const comparitor = InstanceType.of(InstanceClass.M7I_FLEX, InstanceSize.LARGE);
//WHEN
const largerInstanceType = InstanceType.of(InstanceClass.M7I_FLEX, InstanceSize.XLARGE);
//THEN
expect(largerInstanceType.sameInstanceClassAs(comparitor)).toBeTruthy();
});

test('sameInstanceClassAs compares InstanceSize contains dashes', () => {
// GIVEN
const comparitor = new InstanceType('c7a.metal-48xl');
//WHEN
const largerInstanceType = new InstanceType('c7a.xlarge');
//THEN
expect(largerInstanceType.sameInstanceClassAs(comparitor)).toBeTruthy();
});

test('sameInstanceClassAs compares different InstanceTypes correctly', () => {
// GIVEN
const comparitor = InstanceType.of(InstanceClass.C4, InstanceSize.LARGE);
Expand Down

0 comments on commit 3b0d489

Please sign in to comment.