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(core): CfnResource depends on methods #20419
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.
I like the additions this makes. However, if the intended use case is for users to write
foo = stack.tryFindChild('Foo');
if (foo.obtainDependsOn().contains(bar)) {
foo.removeDependsOn(bar);
fi
foo.addDependsOn(barReplacement);
we should also add a replaceDependsOn(bar, barReplacement)
that does exactly what the above snippet does.
packages/@aws-cdk/core/lib/deps.ts
Outdated
function resourceInCommonStackFor(element: CfnResource | Stack, commonStack: Stack): CfnResource { | ||
const resource = Stack.isStack(element) ? element.nestedStackResource : element; | ||
if (!resource) { | ||
throw new Error('assertion failure'); // see "assertion" above |
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.
this is not a very descriptive error message.
packages/@aws-cdk/core/lib/stack.ts
Outdated
let index; | ||
let filteredReasons = filterReasons(dep, reasonFilter); | ||
if (filteredReasons.length > 1) { | ||
throw new Error(`Reason for dependency removal is too ambiguous: ${reasonFilter}`); |
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.
throw new Error(`Reason for dependency removal is too ambiguous: ${reasonFilter}`); | |
throw new Error(`There cannot be more than one reason for dependency removal, found: ${reasonFilter}`); |
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.
Took your message but swapped /reasonFilter/filteredReasons/ since I think the latter makes more sense with your message.
ccfd779
to
e066b02
Compare
@comcalvi, based on what I learned in #20281, I think we'll eventually have to reopen this pull request from a personal fork of |
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.
These test failures have to do with a bug we had when you last merged from main. Please rebase so we can see if the build is succeeding before we can provide another round of reviews.
c701ed0
to
561f0a6
Compare
Pull request has been modified.
@jusdino Go into the aws-cdk-lib package and run |
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.
@comcalvi is already providing great feedback but I just want to add that I think this needs more testing. I'd like to see both more unit test coverage for these changes and integration tests as well. If you have any questions about writing integration tests, see our integration test guide.
Pull request has been modified.
Ok, I detected the |
a24c577
to
65bc9a5
Compare
07912f2
to
e71c405
Compare
I missed that the method whose signature changed was internal, that's my mistake.
Sorry I wasn't more clear; I do not understand this mechanism. The main thing I'm missing the usage of
The method additions and name changes are good, this comment was about the new mechanism. A comment block detailing this mechanism would be helpful. I'm not understanding what precise capability this is adding. |
Ah ok. So the Would adding a comment block with something along those lines be helpful? |
I don't see the purpose of filtering reasons in this process though. From this, I understand that we need to track resource dependencies across stacks. I think today we don't do this, and instead only track the stack itself as a dependency; this is a problem. As you explain, if we only track the stack as a dependency and a user removes one dependency but not the other, we can't determine that the stack dependency should actually be left in place; therefore, we need a mechanism to track the resources themselves as dependencies and not just the stack. With that in mind, I would expect the fundamental change to add the construct path to the dependency list, eg |
Sorry for the slow reply - I've been sick and wanted to think this through. My short answer is, looking closer, the What we really need is to be able to match a It sounds like your preference would be to simplify. I could simplify/remove the |
Thanks for the explanation, this makes sense. It's good to think of edge cases like this, and we should definitely guard against it. However I'd prefer to fail in this case, since the API shouldn't allow this to happen. Even it happens to be impossible for this case to occur with today's code, future changes may have bugs that create a |
Sounds good. I'll work on that next along with the smaller changes from your last review. |
Pull request has been modified.
@comcalvi, @MrArnoldPalmer, I think this covers everything except for what to do about |
for |
@jusdino Can you please enable contributions by maintainers to your fork? I have a commit I'd like to push to this PR, and then I'll be happy to approve it. Thanks for all your hard work on this PR, this is in a really good spot now! |
Glad to be close to the finish line! So this PR is from a fork on a GitHub organization and I wasn’t able to find a way to do that with my last PR from there. Last time, I ended up reopening a new PR from a personal fork. I can do that here as well though it will take me a bit - got some personal stuff going on atm. For reference: |
Thanks! Just link it here and I'll approve once I push a commit to it. |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Closing this one in favor of #23383 |
Reopening #20419 from a personal fork to allow maintainer edits. @comcalvi 👋 Add some new methods to allow a minimal interface for viewing and editing resource-to-resource dependencies that mirrors the behavior of CfnResource.addDependsOn(). Related to #20418 - details for justification are there ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Construct Runtime Dependencies: * [ ] This PR adds new construct runtime dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-construct-runtime-dependencies) ### New Features * [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Reopening aws#20419 from a personal fork to allow maintainer edits. @comcalvi 👋 Add some new methods to allow a minimal interface for viewing and editing resource-to-resource dependencies that mirrors the behavior of CfnResource.addDependsOn(). Related to aws#20418 - details for justification are there ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Construct Runtime Dependencies: * [ ] This PR adds new construct runtime dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-construct-runtime-dependencies) ### New Features * [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Reopening aws#20419 from a personal fork to allow maintainer edits. @comcalvi 👋 Add some new methods to allow a minimal interface for viewing and editing resource-to-resource dependencies that mirrors the behavior of CfnResource.addDependsOn(). Related to aws#20418 - details for justification are there ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Construct Runtime Dependencies: * [ ] This PR adds new construct runtime dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-construct-runtime-dependencies) ### New Features * [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Add some new methods to allow a minimal interface for viewing and editing resource-to-resource dependencies that mirrors the behavior of
CfnResource.addDependsOn()
.Related to #20418 - details for justification are there
All Submissions:
yarn integ
to deploy the infrastructure and generate the snapshot (i.e.yarn integ
without--dry-run
)?Adding new Unconventional Dependencies:
New Features
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license