-
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
feat(ecr): Add emptyOnDelete CloudFormation property to Repository L2 construct #28233
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.
efa45be
to
161767a
Compare
161767a
to
5c3ee91
Compare
91a08b1
to
04296e6
Compare
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 left you some comments for some minor adjustments.
@@ -706,6 +714,7 @@ export class Repository extends RepositoryBase { | |||
imageScanningConfiguration: props.imageScanOnPush !== undefined ? { scanOnPush: props.imageScanOnPush } : undefined, | |||
imageTagMutability: props.imageTagMutability || undefined, | |||
encryptionConfiguration: this.parseEncryption(props), | |||
emptyOnDelete: props.emptyOnDelete, |
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 should ignore autoDeleteImages
if emptyOnDelete
is set here:
if (props.emptyOnDelete === undefined && props.autoDeleteImages) {
(I think that setting emptyOnDelete = false
should override autoDeleteImages = true
, but feel free to comment on this).
Also:
- This will need some extra unit tests
- Does
emptyOnDelete = true
requiresremovalPolicy === RemovalPolicy.DESTROY
? I wasn't able to find documentation on this
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 fine with only using
autoDeleteImages
ifemptyOnDelete
isundefined
. emptyOnDelete = true
does not requireremovalPolicy === RemovalPolicy.DESTROY
Made the change and added tests, please review 🙂
|
||
```ts | ||
const repository = new ecr.Repository(this, 'MyTempRepo', { | ||
removalPolicy: RemovalPolicy.DESTROY, | ||
autoDeleteImages: true, | ||
emptyOnDelete: true, | ||
}); | ||
``` | ||
|
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.
Don't you think it's better to remove autoDeleteImages
from the readme entirely? I've already marked it as deprecated in the JSDoc.
|
||
```ts | ||
const repository = new ecr.Repository(this, 'MyTempRepo', { | ||
removalPolicy: RemovalPolicy.DESTROY, | ||
autoDeleteImages: true, | ||
emptyOnDelete: true, | ||
}); | ||
``` | ||
|
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.
Don't you think it's better to remove autoDeleteImages
from the readme entirely? I've already marked it as deprecated in the JSDoc.
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.
Can you please provide documentation for
emptyOnDelete = true does not require removalPolicy === RemovalPolicy.DESTROY
?
@@ -176,12 +176,12 @@ policy is set to `RemovalPolicy.DESTROY`, the repository will be deleted as long | |||
as it does not contain any images. | |||
|
|||
To override this and force all images to get deleted during repository deletion, | |||
enable the`autoDeleteImages` option. | |||
enable the`emptyOnDelete` option. | |||
|
|||
```ts | |||
const repository = new ecr.Repository(this, 'MyTempRepo', { | |||
removalPolicy: RemovalPolicy.DESTROY, |
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.
removalPolicy: RemovalPolicy.DESTROY, |
Unnecessary.
Actually I misspoke. I was testing this out with JSON CloudFormation when I should have been testing it with 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.
Thanks!
I think we're just missing one validation and we'll be good to go.
@@ -723,7 +732,7 @@ export class Repository extends RepositoryBase { | |||
resourceName: this.physicalName, | |||
}); | |||
|
|||
if (props.autoDeleteImages) { | |||
if (props.emptyOnDelete === undefined && props.autoDeleteImages) { |
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.
Given #28233 (comment).
We should validate for emptyOnDelete
as well:
if (props.emptyOnDelete) {
if (props.removalPolicy !== RemovalPolicy.DESTROY) {
throw new Error('Cannot use \'emptyOnDelete\' property on a repository without setting removal policy to \'DESTROY\'.');
}
}
if (props.emptyOnDelete === undefined && props.autoDeleteImages) {
...
}
With a related unit test for coverage.
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 👍
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). |
Pull request has been modified.
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). |
Added
emptyOnDelete
prop to the ecrRepository
construct.emptyOndelete
is supported by CloudFormationSee here: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ecr-repository.html#cfn-ecr-repository-emptyondelete
I've also deprecated the
autoDeleteImages
prop that deployed a custom resource. According to #24572 this was added before CloudFormation added theEmptyOnDelete
property here aws-cloudformation/cloudformation-coverage-roadmap#515Closes #28196
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license