Skip to content

Commit b32f47c

Browse files
authored
fix(eks): Could not use ec2 instance type and size that their names contains 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*
1 parent 4034adb commit b32f47c

File tree

9 files changed

+71
-50
lines changed

9 files changed

+71
-50
lines changed
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-eks/test/integ.eks-cluster.js.snapshot/aws-cdk-eks-cluster.assets.json

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-eks/test/integ.eks-cluster.js.snapshot/aws-cdk-eks-cluster.template.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -3485,7 +3485,7 @@
34853485
"InstanceTypes": [
34863486
"c5.large",
34873487
"c5a.large",
3488-
"c5d.large"
3488+
"m7i-flex.large"
34893489
],
34903490
"NodeRole": {
34913491
"Fn::GetAtt": [
@@ -4184,7 +4184,7 @@
41844184
{
41854185
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-us-east-1"
41864186
},
4187-
"/c8a7b417e8c7a99a49ab10844fbaf839d1238901e86bc4cb16cf5259e5899308.json"
4187+
"/b5cbe4d6c447664cb7945e7e3d2b0d01aeb8c348dacc25cb86a5dd3673800a2f.json"
41884188
]
41894189
]
41904190
}

packages/@aws-cdk-testing/framework-integ/test/aws-eks/test/integ.eks-cluster.js.snapshot/awscdkeksclusterawscdkawseksClusterResourceProvider0DD9B7A4.nested.template.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"S3Bucket": {
5151
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-us-east-1"
5252
},
53-
"S3Key": "1b5aaa158e02216aa983cbf998d740faf1176f70b3769f77295e9bd20f543edf.zip"
53+
"S3Key": "61942cf3327d6ed09088c3ef6dc3323ede4f78254d605dda7068fd1de5dd704f.zip"
5454
},
5555
"Description": "onEvent handler for EKS cluster resource provider",
5656
"Environment": {
@@ -115,7 +115,7 @@
115115
"S3Bucket": {
116116
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-us-east-1"
117117
},
118-
"S3Key": "1b5aaa158e02216aa983cbf998d740faf1176f70b3769f77295e9bd20f543edf.zip"
118+
"S3Key": "61942cf3327d6ed09088c3ef6dc3323ede4f78254d605dda7068fd1de5dd704f.zip"
119119
},
120120
"Description": "isComplete handler for EKS cluster resource provider",
121121
"Environment": {

packages/@aws-cdk-testing/framework-integ/test/aws-eks/test/integ.eks-cluster.js.snapshot/manifest.json

+5-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-eks/test/integ.eks-cluster.js.snapshot/tree.json

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-eks/test/integ.eks-cluster.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ class EksClusterStack extends Stack {
223223
instanceTypes: [
224224
new ec2.InstanceType('c5.large'),
225225
new ec2.InstanceType('c5a.large'),
226-
new ec2.InstanceType('c5d.large'),
226+
new ec2.InstanceType('m7i-flex.large'),
227227
],
228228
minSize: 3,
229229
// reusing the default capacity nodegroup instance role when available

packages/aws-cdk-lib/aws-ec2/lib/instance-types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1528,7 +1528,7 @@ export class InstanceType {
15281528
*/
15291529
public get architecture(): InstanceArchitecture {
15301530
// capture the family, generation, capabilities, and size portions of the instance type id
1531-
const instanceTypeComponents = this.instanceTypeIdentifier.match(/^([a-z]+)(\d{1,2})([a-z]*)\.([a-z0-9]+)$/);
1531+
const instanceTypeComponents = this.instanceTypeIdentifier.match(/^([a-z]+)(\d{1,2})([a-z\-]*)\.([a-z0-9\-]+)$/);
15321532
if (instanceTypeComponents == null) {
15331533
throw new Error('Malformed instance type identifier');
15341534
}
@@ -1546,7 +1546,7 @@ export class InstanceType {
15461546
}
15471547

15481548
public sameInstanceClassAs(other: InstanceType): boolean {
1549-
const instanceClass: RegExp = /^([a-z]+\d{1,2}[a-z]*)\.([a-z0-9]+)$/;
1549+
const instanceClass: RegExp = /^([a-z]+\d{1,2}[a-z\-]*)\.([a-z0-9\-]+)$/;
15501550
const instanceClassId = this.instanceTypeIdentifier.match(instanceClass);
15511551
const otherInstanceClassId = other.instanceTypeIdentifier.match(instanceClass);
15521552
if (instanceClassId == null || otherInstanceClassId == null) {

packages/aws-cdk-lib/aws-ec2/test/instance.test.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ describe('instance', () => {
123123
});
124124
test('instance architecture is correctly discerned for x86-64 instance', () => {
125125
// GIVEN
126-
const sampleInstanceClasses = ['c5', 'm5ad', 'r5n', 'm6', 't3a', 'r6i', 'r6a', 'p4de', 'p5']; // A sample of x86-64 instance classes
126+
const sampleInstanceClasses = ['c5', 'm5ad', 'r5n', 'm6', 't3a', 'r6i', 'r6a', 'p4de', 'p5', 'm7i-flex']; // A sample of x86-64 instance classes
127127

128128
for (const instanceClass of sampleInstanceClasses) {
129129
// WHEN
@@ -135,6 +135,24 @@ describe('instance', () => {
135135

136136
});
137137

138+
test('sameInstanceClassAs compares InstanceTypes contains dashes', () => {
139+
// GIVEN
140+
const comparitor = InstanceType.of(InstanceClass.M7I_FLEX, InstanceSize.LARGE);
141+
//WHEN
142+
const largerInstanceType = InstanceType.of(InstanceClass.M7I_FLEX, InstanceSize.XLARGE);
143+
//THEN
144+
expect(largerInstanceType.sameInstanceClassAs(comparitor)).toBeTruthy();
145+
});
146+
147+
test('sameInstanceClassAs compares InstanceSize contains dashes', () => {
148+
// GIVEN
149+
const comparitor = new InstanceType('c7a.metal-48xl');
150+
//WHEN
151+
const largerInstanceType = new InstanceType('c7a.xlarge');
152+
//THEN
153+
expect(largerInstanceType.sameInstanceClassAs(comparitor)).toBeTruthy();
154+
});
155+
138156
test('instances with local NVME drive are correctly named', () => {
139157
// GIVEN
140158
const sampleInstanceClassKeys = [{

0 commit comments

Comments
 (0)