-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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(codebuild): prevent fleet and batch build combined usage #30615
base: main
Are you sure you want to change the base?
fix(codebuild): prevent fleet and batch build combined usage #30615
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.
// !! Failsafe !! This should not occur with the current methods, given: | ||
// * The fleet can only be set with the constructor | ||
// * The batch builds can only be enabled with the `enableBatchBuilds` method | ||
if (this.isBatchBuildEnabled) { | ||
throw new Error('Build batch is not supported for project using reserved capacity'); | ||
} |
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.
As mentioned in the comment, this condition should never be true. I've added it just in case a future CDK API change enables this behavior
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.
Agree, this is a good regression check.
Exemption Request: This is a synth time check, a unit test should be sufficient |
e992d32
to
354694a
Compare
354694a
to
a576189
Compare
6754b0e
to
1402d51
Compare
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
This PR has been in the CHANGES REQUESTED state for 3 weeks, and looks abandoned. To keep this PR from being closed, please continue work on it. If not, it will automatically be closed in a week. |
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.
Overall I like the idea here. This case seems fairly easy to run in to, and the error from CloudFormation is not immediately clear on how you have messed up your CDK configuration, so I support the synth-time check.
We have ran into a couple issues with synth-time checks being overly restrictive, so a couple questions on hypothetical cases where a user could run into this.
- Is there any way for a user to set the fleet property but not use reserved capacity? (This may be the definition of the CFN fleet resource, but wanted to make sure theres no way to set on-demand fleets with this property)
- Is there a way for a user to pass in a "dummy" fleet for their environment, which would not result in reserved capacity, but would still trigger this check?
I'd expect no to both, but still worth a consideration.
Lastly, I don't quite understand the boolean variable and the getter method. I do not believe both are needed. The variable is never set, and the getter method evaluates a different variable. Could you set the variable to true in the enableBatchBuilds()
method, and then reference it directly in configureFleet()
? Or could the function be the evaluation without the corresponding variable?
Of the two, I would prefer the direct set of the variable, but up to you.
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
Hey @scanlonp, thanks for the review and sorry for the late reply.
Not as far as I can tell, setting a fleet to a CodeBuild project makes it become a reserved capacity project, see Working with reserved capacity in AWS CodeBuild
I'm not sure how they would do that. The
The boolean value and the getter method are one and the same. |
Issue # (if applicable)
None, initially reported by @michaelbwebb, see #30596
Reason for this change
The following stack would cause a CloudFormation deployment error:
I initially thought that the
fleet
property was not correctly set forPipelineProject
s, but this is only tangentially related CodePipeline, see Working with reserved capacity in AWS CodeBuild:This is reflected by the CloudFormation error thrown by the above stack:
While I understand the CDK does not need to double check every CloudFormation exception, fleets can be slow to deploy, and particularly slow to destroy. This process can be costly depending on the compute resource allocation, which in my opinion warrants a synth time check
Description of changes
Project.isBatchBuildEnabled
property, giving the ability to check whetherenableBatchBuilds()
has been invokedProject._environment
property, to retrieve the environment value synthesized in theconstructor
methodDescription of how you validated changes
Added a unit test. The CloudFormation error was found whilst attempting to add an integration test for a reserved capacity
PipelineProject
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license