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

feat(ecr): Add emptyOnDelete CloudFormation property to Repository L2 construct #28233

Merged
merged 17 commits into from
Dec 19, 2023

Conversation

markmansur
Copy link
Contributor

@markmansur markmansur commented Dec 2, 2023

Added emptyOnDelete prop to the ecr Repository construct. emptyOndelete is supported by CloudFormation
See 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 the EmptyOnDelete property here aws-cloudformation/cloudformation-coverage-roadmap#515

Closes #28196


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 beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2 labels Dec 2, 2023
@aws-cdk-automation aws-cdk-automation requested a review from a team December 2, 2023 03:01
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.

@aws-cdk-automation aws-cdk-automation dismissed their stale review December 2, 2023 03:42

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

@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Dec 2, 2023
Copy link
Contributor

@lpizzinidev lpizzinidev left a 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,
Copy link
Contributor

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 requires removalPolicy === RemovalPolicy.DESTROY? I wasn't able to find documentation on this

Copy link
Contributor Author

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 if emptyOnDelete is undefined.
  • emptyOnDelete = true does not require removalPolicy === 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,
});
```

Copy link
Contributor Author

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.

packages/@aws-cdk/app-staging-synthesizer-alpha/README.md Outdated Show resolved Hide resolved
@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Dec 3, 2023

```ts
const repository = new ecr.Repository(this, 'MyTempRepo', {
removalPolicy: RemovalPolicy.DESTROY,
autoDeleteImages: true,
emptyOnDelete: true,
});
```

Copy link
Contributor Author

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.

Copy link
Contributor

@lpizzinidev lpizzinidev left a 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,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
removalPolicy: RemovalPolicy.DESTROY,

Unnecessary.

@markmansur
Copy link
Contributor Author

Can you please provide documentation for

emptyOnDelete = true does not require removalPolicy === RemovalPolicy.DESTROY

?

Actually I misspoke. I was testing this out with JSON CloudFormation when I should have been testing it with CDK.
By default CDK sets the RemovalPolicy to RETAIN which will override the emptyOnDelete setting. I was wrong, RemovalPolicy.DESTROY is required when using emptyOnDelete. I've updated the readme, sorry for the confusion 🙂

Copy link
Contributor

@lpizzinidev lpizzinidev left a 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) {
Copy link
Contributor

@lpizzinidev lpizzinidev Dec 7, 2023

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.

Copy link
Contributor

@lpizzinidev lpizzinidev left a comment

Choose a reason for hiding this comment

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

Thanks 👍

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Dec 9, 2023
@sumupitchayan sumupitchayan self-assigned this Dec 18, 2023
sumupitchayan
sumupitchayan previously approved these changes Dec 19, 2023
Copy link
Contributor

mergify bot commented Dec 19, 2023

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-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Dec 19, 2023
Copy link
Contributor

mergify bot commented Dec 19, 2023

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 dismissed sumupitchayan’s stale review December 19, 2023 15:55

Pull request has been modified.

Copy link
Contributor

mergify bot commented Dec 19, 2023

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-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

@mergify mergify bot merged commit a175da8 into aws:main Dec 19, 2023
10 checks passed
Copy link
Contributor

mergify bot commented Dec 19, 2023

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

@markmansur markmansur deleted the feat/ecr-empty-on-delete branch December 22, 2023 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws-cdk-lib/aws-ecr: No option available in CDK to set EmptyOnDelete property for ECR repo
5 participants