-
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
(ecs): small refactor for PortMapping ease of change #24170
Comments
Thanks for providing this feedback and your suggestions on how to improve this code after your previous experience of attempting to change it. @madeline-k you have some good context around this library, what do you think about this refactoring suggestion? |
This PR... - Refactor ecs.ContainerDefintion.addPortMapping method - The addPortMapping method had many if statements and it was difficult to understand what was being determined. - It was also difficult to make changes. - Therefore, I divided the classes by interest to improve visibility. Closes #24170 . ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
|
This PR... - Refactor ecs.ContainerDefintion.addPortMapping method - The addPortMapping method had many if statements and it was difficult to understand what was being determined. - It was also difficult to make changes. - Therefore, I divided the classes by interest to improve visibility. Closes aws#24170 . ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Describe the feature
Sorry if I have the wrong category for the Issue or the wrong place for the discussion!
While looking at Issue #23509, I was surprised by the following
addPortMappings
conditional branch.aws-cdk/packages/@aws-cdk/aws-ecs/lib/container-definition.ts
Lines 567 to 607 in de097ee
The ContainerDefinition class is responsible for many of the responsibilities, and many if statements are added to verify PortMapping's sanity.
I feel that by writing down if statements like this, we lose the ease of modification.
Therefore, I would like to refactor it so that many contributors can easily modify it here in a way that does not affect the existing system!
Use Case
ECS is a very widely used service, and I believe it is a service that will continue to see many bug fixes and feature additions.
I think that every time we add more properties in the future, we will make it harder to make changes by making miscellaneous changes!
I want to make it easy for many developers to contribute to this project!
Proposed Solution
I think
ContainerDefinition
has too many responsibility.An if statement is written in
addPortMappings
that assumes all contexts.aws-cdk/packages/@aws-cdk/aws-ecs/lib/container-definition.ts
Lines 567 to 607 in de097ee
For example, this nested if statement is also commented as Sevice Connect logick, but now I don't know what the decision logic is for.
aws-cdk/packages/@aws-cdk/aws-ecs/lib/container-definition.ts
Lines 578 to 606 in de097ee
So, I suggest creating a PortMap or similarly named class (I think it would be a Value Object) like below.
I thought it would make for a more prospective code by taking the responsibility for checking the sanity of PortMapping related properties out of the picture!
Other Information
No response
Acknowledgements
CDK version used
2.64.0
Environment details (OS name and version, etc.)
macOS Monterey
The text was updated successfully, but these errors were encountered: