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(ecr): AutoDeleteImages custom resource description contains "undefined" #26800

Merged
merged 5 commits into from
Aug 22, 2023

Conversation

go-to-k
Copy link
Contributor

@go-to-k go-to-k commented Aug 18, 2023

The repository name is embedded in the description of CustomResourceProvider for the ECR AutoDeleteImages, but the repository name becomes to undefined because the CustomResourceProvider is created before the repository name is set.

  private enableAutoDeleteImages() {
    const firstTime = Stack.of(this).node.tryFindChild(`${AUTO_DELETE_IMAGES_RESOURCE_TYPE}CustomResourceProvider`) === undefined;
    const provider = CustomResourceProvider.getOrCreateProvider(this, AUTO_DELETE_IMAGES_RESOURCE_TYPE, {
      codeDirectory: path.join(__dirname, '..', '..', 'custom-resource-handlers', 'dist', 'aws-ecr', 'auto-delete-images-handler'),
      useCfnResponseWrapper: false,
      runtime: CustomResourceProviderRuntime.NODEJS_18_X,
      description: `Lambda function for auto-deleting images in ${this.repositoryName} repository.`,
    });

So I moved the enableAutoDeleteImages calls after following codes that set repositoryName in the Repository constructor.

this.repositoryName = this.getResourceNameAttribute(resource.ref);

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@aws-cdk-automation aws-cdk-automation requested a review from a team August 18, 2023 04:52
@github-actions github-actions bot added p2 valued-contributor [Pilot] contributed between 6-12 PRs to the CDK labels Aug 18, 2023
@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 Aug 18, 2023
Copy link
Contributor

@tmokmss tmokmss left a comment

Choose a reason for hiding this comment

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

If we just move this assignment before calling enableAutoDeleteImages, will that resolve the problem?

this.repositoryName = this.getResourceNameAttribute(resource.ref);

@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 Aug 19, 2023
@go-to-k
Copy link
Contributor Author

go-to-k commented Aug 19, 2023

@tmokmss

If we just move this assignment before calling enableAutoDeleteImages, will that resolve the problem?

In that case, ${this.repositoryName} is just Token[XX] instead of undefined, which may not make much sense.

I considered that as well, since it is more natural for the source code, but I did not change it out of respect for the intent of the original code.

@go-to-k
Copy link
Contributor Author

go-to-k commented Aug 19, 2023

@tmokmss

Sorry, I was misunderstood.

The getResourceNameAttribute uses mimicReference that produces a Lazy. So we should move the assignment before calling enableAutoDeleteImages.

I will change.

Copy link
Contributor

@tmokmss tmokmss left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM. Make sure you change PR title and description as well :)

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Aug 19, 2023
@go-to-k go-to-k changed the title chore(ecr): repository name embedded in AutoDeleteImages CustomResourceProvider description should be Lazy chore(ecr): repositoryName is embedded in AutoDeleteImages CustomResourceProvider description before it is set Aug 19, 2023
@go-to-k
Copy link
Contributor Author

go-to-k commented Aug 19, 2023

Thank you, I changed!

@rix0rrr rix0rrr changed the title chore(ecr): repositoryName is embedded in AutoDeleteImages CustomResourceProvider description before it is set fix(ecr): AutoDeleteImages custom resource description contains "undefined" Aug 21, 2023
@rix0rrr rix0rrr added pr-linter/exempt-test The PR linter will not require test changes pr-linter/exempt-integ-test The PR linter will not require integ test changes labels Aug 21, 2023
rix0rrr
rix0rrr previously approved these changes Aug 21, 2023
@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Aug 21, 2023
@mergify
Copy link
Contributor

mergify bot commented Aug 21, 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 rix0rrr’s stale review August 22, 2023 08:40

Pull request has been modified.

@mergify
Copy link
Contributor

mergify bot commented Aug 22, 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: 23d4871
  • 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 a7a6428 into aws:main Aug 22, 2023
@mergify
Copy link
Contributor

mergify bot commented Aug 22, 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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2 pr-linter/exempt-integ-test The PR linter will not require integ test changes pr-linter/exempt-test The PR linter will not require test changes valued-contributor [Pilot] contributed between 6-12 PRs to the CDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants