Skip to content

Commit

Permalink
fix(eks): Could not use ec2 instance type and size that their names c…
Browse files Browse the repository at this point in the history
…ontains dashes (#28040)

Fix the Ec2 instance class regular expression to accept values that contains dashes like (m7i-flex, and metal-48xl).

Closes #27587.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
moelasmar committed Jan 30, 2024
1 parent 4034adb commit b32f47c
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 50 deletions.

Large diffs are not rendered by default.

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 @@ -4184,7 +4184,7 @@
{
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-us-east-1"
},
"/c8a7b417e8c7a99a49ab10844fbaf839d1238901e86bc4cb16cf5259e5899308.json"
"/b5cbe4d6c447664cb7945e7e3d2b0d01aeb8c348dacc25cb86a5dd3673800a2f.json"
]
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-us-east-1"
},
"S3Key": "1b5aaa158e02216aa983cbf998d740faf1176f70b3769f77295e9bd20f543edf.zip"
"S3Key": "61942cf3327d6ed09088c3ef6dc3323ede4f78254d605dda7068fd1de5dd704f.zip"
},
"Description": "onEvent handler for EKS cluster resource provider",
"Environment": {
Expand Down Expand Up @@ -115,7 +115,7 @@
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-us-east-1"
},
"S3Key": "1b5aaa158e02216aa983cbf998d740faf1176f70b3769f77295e9bd20f543edf.zip"
"S3Key": "61942cf3327d6ed09088c3ef6dc3323ede4f78254d605dda7068fd1de5dd704f.zip"
},
"Description": "isComplete handler for EKS cluster resource provider",
"Environment": {
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.

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 @@ -1528,7 +1528,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 @@ -1546,7 +1546,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 All @@ -135,6 +135,24 @@ describe('instance', () => {

});

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('instances with local NVME drive are correctly named', () => {
// GIVEN
const sampleInstanceClassKeys = [{
Expand Down

0 comments on commit b32f47c

Please sign in to comment.