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

Conversation

moelasmar
Copy link
Contributor

@moelasmar moelasmar commented Nov 16, 2023

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

@github-actions github-actions bot added bug This issue is a bug. effort/small Small work item – less than a day of effort p2 repeat-contributor [Pilot] contributed between 3-5 PRs to the CDK labels Nov 16, 2023
@aws-cdk-automation aws-cdk-automation requested a review from a team November 16, 2023 20:38
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@moelasmar moelasmar changed the title fix: update the instance type and size reg expression to accept values that contains dashes like m7i-flex fix(ec2): update the instance type and size reg expression to accept values that contains dashes like m7i-flex Nov 16, 2023
@aws-cdk-automation aws-cdk-automation dismissed their stale review November 16, 2023 22:18

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Nov 16, 2023
@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Nov 16, 2023
Copy link
Contributor

@vinayak-kukreja vinayak-kukreja left a comment

Choose a reason for hiding this comment

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

Hey, @moelasmar thank you for opening a contribution with us.

Couple of comments,

  • The PR title, when it is a fix should tell more about the error/issue and not the solution. So for instance, fix(ec2): instance type and size regex does not accommodate dashes
  • Could you add to integ test present in ec2 to verify we are able to provision these instances. If you are unable to run these test on your account, please let me know and I can verify those.

@@ -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.

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Nov 17, 2023
@moelasmar moelasmar changed the title fix(ec2): update the instance type and size reg expression to accept values that contains dashes like m7i-flex fix(ec2): instance type and size regex does not accommodate dashes Nov 17, 2023
@moelasmar moelasmar changed the title fix(ec2): instance type and size regex does not accommodate dashes fix(eks): Could not use ec2 instance type and size that their names contains dashes Nov 17, 2023
@moelasmar
Copy link
Contributor Author

Hey, @moelasmar thank you for opening a contribution with us.

Couple of comments,

  • The PR title, when it is a fix should tell more about the error/issue and not the solution. So for instance, fix(ec2): instance type and size regex does not accommodate dashes
  • Could you add to integ test present in ec2 to verify we are able to provision these instances. If you are unable to run these test on your account, please let me know and I can verify those.

The problem is mainly related to adding new managed node groups to an EKS Cluster, and not while creating EC2 instances. The problem is mainly in these 2 functions:

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\-]+)$/);
if (instanceTypeComponents == null) {
throw new Error('Malformed instance type identifier');
}
const family = instanceTypeComponents[1];
const capabilities = instanceTypeComponents[3];
// Instance family `a` are first-gen Graviton instances
// Capability `g` indicates the instance is Graviton2 powered
if (family === 'a' || capabilities.includes('g')) {
return InstanceArchitecture.ARM_64;
}
return InstanceArchitecture.X86_64;
}
public sameInstanceClassAs(other: InstanceType): boolean {
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) {
throw new Error('Malformed instance type identifier');
}
return instanceClassId[1] === otherInstanceClassId[1];
}

Where are mainly used in these functions in eks managed nodegroup

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];
return knownGpuInstanceTypes.some((c) => instanceType.sameInstanceClassAs(InstanceType.of(c, InstanceSize.LARGE)));
}
/**
* This function check if the instanceType is supported by Windows AMI.
* https://docs.aws.amazon.com/eks/latest/userguide/windows-support.html
* @param instanceType The EC2 instance type
*/
function isWindowsSupportedInstanceType(instanceType: InstanceType): boolean {
//compare instanceType to forbidden InstanceTypes for Windows. Add exception for m6a.16xlarge.
//NOTE: i2 instance class is not present in the InstanceClass enum.
const forbiddenInstanceClasses: InstanceClass[] = [InstanceClass.C3, InstanceClass.C4, InstanceClass.D2, InstanceClass.M4,
InstanceClass.M6A, InstanceClass.R3];
return instanceType.toString() === InstanceType.of(InstanceClass.M4, InstanceSize.XLARGE16).toString() ||
forbiddenInstanceClasses.every((c) => !instanceType.sameInstanceClassAs(InstanceType.of(c, InstanceSize.LARGE)) && !instanceType.toString().match(/^i2/));
}

Anyway, I will try to add a new Ec2 test case

@vinayak-kukreja
Copy link
Contributor

Hey @moelasmar , I ran the integ test and have added that. Looks like the fork needs to be updated. Could you please do that and update here? I can resolve the other conflicts.

@moelasmar
Copy link
Contributor Author

Hey @moelasmar , I ran the integ test and have added that. Looks like the fork needs to be updated. Could you please do that and update here? I can resolve the other conflicts.

I found some issues on resolving the conflicts, so I start from a fresh fork of the main branch, and added my changes again.
I also executed yarn integ --directory test/aws-eks/test --update-on-failed to run the integration test cases and update the snapshot, and also executed yarn test aws-ec2 to verify the unit test cases.

@moelasmar moelasmar force-pushed the fix_instances_reg_exp branch from 3b0d489 to fb07b36 Compare January 17, 2024 23:19
@moelasmar moelasmar force-pushed the fix_instances_reg_exp branch from f462335 to 340cc73 Compare January 18, 2024 11:47
@paulhcsun
Copy link
Contributor

@Mergifyio update

Copy link
Contributor

mergify bot commented Jan 30, 2024

update

✅ Branch has been successfully updated

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: fa18285
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@moelasmar moelasmar dismissed vinayak-kukreja’s stale review January 30, 2024 22:52

it is already approved by paulhcsun, and the requested change got resolved

Copy link
Contributor

mergify bot commented Jan 30, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit b32f47c into aws:main Jan 30, 2024
13 of 14 checks passed
@moelasmar moelasmar deleted the fix_instances_reg_exp branch January 30, 2024 22:53
SankyRed pushed a commit that referenced this pull request Feb 8, 2024
…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*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. contribution/core This is a PR that came from AWS. effort/small Small work item – less than a day of effort p2 repeat-contributor [Pilot] contributed between 3-5 PRs to the CDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws-cdk-lib/aws-ec2: "Malformed instance type identifier" when creating ec2 instance of type 'm7i-flex.large'
4 participants