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

fix(eks): Could not use ec2 instance type and size that their names contains dashes #28040

Merged
merged 8 commits into from
Jan 30, 2024

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'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were you able to run this integ test and deploy the resource to your account?

Copy link
Contributor Author

@moelasmar moelasmar Nov 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to run the test case, but I did not try to deploy it, let me try to deploy it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. Let me know if I can help.

],
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
Loading