-
Notifications
You must be signed in to change notification settings - Fork 4k
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
feat(autoscaling): instance maintenance policy for AutoScalingGroup #28092
feat(autoscaling): instance maintenance policy for AutoScalingGroup #28092
Conversation
There was a problem hiding this 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.
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks 👍
I added some suggestions for improvements, feel free to comment.
packages/aws-cdk-lib/aws-autoscaling/test/auto-scaling-group.test.ts
Outdated
Show resolved
Hide resolved
fix by the review add new validation to clear previously set values add new unit tests
8e4e844
to
b4ef9f7
Compare
Thanks for your review. I fixed them! |
9f14ea4
to
5eb173e
Compare
I changed the properties to flat and optional! Please check them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks 👍
Just some minor adjustments and it will be good to go for me.
This reverts commit 5eb173e.
I changed. Please look at this comment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @go-to-k. Some minor comments, but great start!
@@ -288,6 +288,38 @@ autoScalingGroup.scaleOnSchedule('AllowDownscalingAtNight', { | |||
}); | |||
``` | |||
|
|||
### Instance Maintenance Policy | |||
|
|||
The instance maintenance policy allows you to configure an instance maintenance policy for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The instance maintenance policy allows you to configure an instance maintenance policy for | |
You can configure an instance maintenance policy for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed.
instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.MICRO), | ||
machineImage: ec2.MachineImage.latestAmazonLinux2(), | ||
maintenancePolicyMaxHealthPercentage: 200, | ||
maintenancePolicyMinHealthPercentage: 100, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not necessarily against this, but what was the reasoning against just minHealthPercentage
and maxHealthPercentage
? I think i prefer that unless it would be confusing if minimum health could point to other things besides maintenance policy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I was not sure at first, but I think I will do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to minHealthyPercentage
and maxHealthyPercentage
to match CloudFormation (with Health'y').
* | ||
* @see https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-instance-maintenance-policy.html | ||
* | ||
* @default - No instance maintenance policy. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If possible, I think we should just set the default to -1
. If I am reading the docs correctly, this is equivalent to undefined in CloudFormation. The only issue I see is if CloudFormation somehow fails if you set the value to -1
and there wasn't any previous value to clear. If that happens, then lets go down this path. If not, we can treat -1
and undefined
equivalently in CDK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I tried to run CloudFormation with -1 from the beginning, I got the following error in CFn. In other words, it seems that -1 and undefined must be distinguished.
MinHealthyPercentage must be between 0 and 100 (inclusive).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:(
if (maxHealthPercentage === -1 && minHealthPercentage === -1) { | ||
return { | ||
maxHealthyPercentage: maxHealthPercentage, | ||
minHealthyPercentage: minHealthPercentage, | ||
}; | ||
} | ||
if (minHealthPercentage === -1 || maxHealthPercentage === -1) { | ||
throw new Error(`Both maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage must be -1 to clear the previously set value, got maintenancePolicyMinHealthPercentage: ${minHealthPercentage} and maintenancePolicyMaxHealthPercentage: ${maxHealthPercentage}`); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (maxHealthPercentage === -1 && minHealthPercentage === -1) { | |
return { | |
maxHealthyPercentage: maxHealthPercentage, | |
minHealthyPercentage: minHealthPercentage, | |
}; | |
} | |
if (minHealthPercentage === -1 || maxHealthPercentage === -1) { | |
throw new Error(`Both maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage must be -1 to clear the previously set value, got maintenancePolicyMinHealthPercentage: ${minHealthPercentage} and maintenancePolicyMaxHealthPercentage: ${maxHealthPercentage}`); | |
} | |
if (minHealthPercentage === -1 || maxHealthPercentage === -1 && minHealthPercentage !== maxHealthPercentage) { | |
throw new Error(`Both maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage must be -1 to clear the previously set value, got maintenancePolicyMinHealthPercentage: ${minHealthPercentage} and maintenancePolicyMaxHealthPercentage: ${maxHealthPercentage}`); | |
} |
This would be equivalent and remove an additional if condition, but isn't a huge deal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, in the case for the code and both maxHealthPercentage and minHealthPercentage is -1
, the next branch causes an error.
if (maxHealthPercentage < 100 || maxHealthPercentage > 200) {
throw new Error(`maxHealthPercentage must be between 100 and 200, or -1 to clear the previously set value, got ${maxHealthPercentage}`);
}
if (minHealthPercentage < 0 || minHealthPercentage > 100) {
throw new Error(`minHealthPercentage must be between 0 and 100, or -1 to clear the previously set value, got ${minHealthPercentage}`);
}
So, if both are -1
, we need to return them as soon as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or, the following code would work. I will go with this!
if ((minHealthPercentage === -1 || maxHealthPercentage === -1) && minHealthPercentage !== maxHealthPercentage) {
throw new Error(`Both minHealthPercentage and maxHealthPercentage must be -1 to clear the previously set value, got minHealthPercentage: ${minHealthPercentage} and maxHealthPercentage: ${maxHealthPercentage}`);
}
if (maxHealthPercentage !== -1 && (maxHealthPercentage < 100 || maxHealthPercentage > 200)) {
throw new Error(`maxHealthPercentage must be between 100 and 200, or -1 to clear the previously set value, got ${maxHealthPercentage}`);
}
if (minHealthPercentage !== -1 && (minHealthPercentage < 0 || minHealthPercentage > 100)) {
throw new Error(`minHealthPercentage must be between 0 and 100, or -1 to clear the previously set value, got ${minHealthPercentage}`);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed.
} | ||
if (maxHealthPercentage - minHealthPercentage > 100) { | ||
throw new Error(`The difference between maintenancePolicyMinHealthPercentage and maintenancePolicyMaxHealthPercentage cannot be greater than 100, got ${maxHealthPercentage - minHealthPercentage}`); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can store all errors we get in an array and throw them all at the same time, so the user will know all the issues present.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, is that necessary?
I think the information given to the user would be more complex, and type inference would not work and branching would become more complicated.
(Because of the eslint error, in numerical comparisons, minHealthyPercentage !== undefined
and maxHealthyPercentage !== undefined
must be added to the numerical comparison.)
const errors: string[] = [];
if (minHealthyPercentage === undefined && maxHealthyPercentage === undefined) return;
if (minHealthyPercentage === undefined || maxHealthyPercentage === undefined) {
errors.push(`Both or neither of minHealthyPercentage and maxHealthyPercentage must be specified, got minHealthyPercentage: ${minHealthyPercentage} and maxHealthyPercentage: ${maxHealthyPercentage}`);
}
if ((minHealthyPercentage === -1 || maxHealthyPercentage === -1) && minHealthyPercentage !== maxHealthyPercentage) {
errors.push(`Both minHealthyPercentage and maxHealthyPercentage must be -1 to clear the previously set value, got minHealthyPercentage: ${minHealthyPercentage} and maxHealthyPercentage: ${maxHealthyPercentage}`);
}
if (minHealthyPercentage !== -1 && minHealthyPercentage !== undefined && (minHealthyPercentage < 0 || minHealthyPercentage > 100)) {
errors.push(`minHealthyPercentage must be between 0 and 100, or -1 to clear the previously set value, got ${minHealthyPercentage}`);
}
if (maxHealthyPercentage !== -1 && maxHealthyPercentage !== undefined && (maxHealthyPercentage < 0 || maxHealthyPercentage > 100)) {
errors.push(`maxHealthyPercentage must be between 100 and 200, or -1 to clear the previously set value, got ${maxHealthyPercentage}`);
}
if (maxHealthyPercentage !== undefined && minHealthyPercentage !== undefined && maxHealthyPercentage - minHealthyPercentage > 100) {
errors.push(`The difference between minHealthyPercentage and maxHealthyPercentage cannot be greater than 100, got ${maxHealthyPercentage - minHealthyPercentage}`);
}
if (errors.length > 0) {
throw new Error(errors.join('\n'));
}
return {
minHealthyPercentage,
maxHealthyPercentage,
};
Pull request has been modified.
…HealthyPercentage and minHealthyPercentage
Thanks for your review! I fixed and commented back. I would especially appreciate it if you would read the following comment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the -1
thing is kind of dumb but I can't think of a reasonable way of doing it in cdk-land besides just passing on that user-experience to the user. Oh well. Everything else looks good -- my comments on the errors were just nits anyway. Thanks again.
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). |
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). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
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). |
…ws#28092) This PR supports for configuring AutoScalingGroup's instance maintenance policy. - https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-autoscaling-autoscalinggroup-instancemaintenancepolicy.html - https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-instance-maintenance-policy.html - https://docs.aws.amazon.com/autoscaling/ec2/userguide/instance-maintenance-policy-overview-and-considerations.html Closes aws#28042. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
This PR supports for configuring AutoScalingGroup's instance maintenance policy.
Closes #28042.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license