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(codedeploy): supporting the creation of deployment groups with multiple load balancers #27474

Closed
wants to merge 18 commits into from

Conversation

nicolastremblay1
Copy link
Contributor

@nicolastremblay1 nicolastremblay1 commented Oct 10, 2023

Summary

This change adds multiple load balancer support for CodeDeploy deployment groups.

There is a currently a loadBalancer field in the ServerDeploymentGroup, adding loadBalancers might be a good field to extend the functionality to create a deployment group with multiple load balancers.

Closes #27407


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 Oct 10, 2023
@aws-cdk-automation aws-cdk-automation requested a review from a team October 10, 2023 04:29
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.

@nicolastremblay1 nicolastremblay1 changed the title Add multiple load balancers to CodeDeploy deployment group feat: add multiple load balancers to CodeDeploy deployment group Oct 10, 2023
@aws-cdk-automation aws-cdk-automation dismissed their stale review October 10, 2023 04:47

✅ 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 Oct 10, 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.

The implementation looks correct, anyway, some changes are needed in my opinion.
Also:

  1. Can you update the title to specify the module? (eg feat(codedeploy) ...) (see guidelines)
  2. Can you update the description of the PR and remove the duplicate reference to the target issue?

Thanks 💪

packages/aws-cdk-lib/aws-codedeploy/README.md Outdated Show resolved Hide resolved
packages/aws-cdk-lib/aws-codedeploy/README.md Outdated Show resolved Hide resolved
@@ -22,10 +23,29 @@ elb.addListener({
externalPort: 80,
});

const alb = new lb2.ApplicationLoadBalancer(stack, 'ALB', {
Copy link
Contributor

Choose a reason for hiding this comment

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

A separate integration test should be added for the new attribute.

packages/aws-cdk-lib/aws-codedeploy/README.md Outdated Show resolved Hide resolved
nicolastremblay1 and others added 2 commits October 10, 2023 09:31
…p.ts

Co-authored-by: Luca Pizzini <lpizzini7@gmail.com>
Co-authored-by: Luca Pizzini <lpizzini7@gmail.com>
@nicolastremblay1 nicolastremblay1 changed the title feat: add multiple load balancers to CodeDeploy deployment group feat(codedeploy): supporting the creation of deployment groups with multiple load balancers Oct 10, 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!
Just some minor adjustments and a missing test case to be added.

Also, the integration test is failing because it seems that you have not executed it.
You should:

  1. Rollback changes to the snapshots of integ.deployment-group
  2. Execute integ.deployment-group-multiple-load-balancers locally (see guidelines)
  3. Push the generated snapshots

@@ -168,9 +168,19 @@ export interface ServerDeploymentGroupProps {
* or an Application Load Balancer / Network Load Balancer Target Group.
*
* @default - Deployment Group will not have a load balancer defined.
* @deprecated - Deprecated in favor of loadBalancers.
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
* @deprecated - Deprecated in favor of loadBalancers.
* @deprecated - Use `loadBalancers` instead.

More concise

this.loadBalancers = props.loadBalancers || (props.loadBalancer ? [props.loadBalancer]: undefined);

if (this.loadBalancers && this.loadBalancers.length === 0) {
throw new Error('Cannot set empty loadBalancers array');
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
throw new Error('Cannot set empty loadBalancers array');
throw new Error('loadBalancers must be a non-empty array');

Formatting. Also, a unit test needs to be added to verify that the error is thrown if loadBalancers: [].

],
};
}
return loadBalancers.reduce((accumulator : {
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
return loadBalancers.reduce((accumulator : {
return loadBalancers?.reduce((accumulator : {

After if statement removal.

Comment on lines 391 to 395

if (!loadBalancers) {
return undefined;
}

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
if (!loadBalancers) {
return undefined;
}

Unnecessary.

@@ -212,6 +213,70 @@ describe('CodeDeploy Server Deployment Group', () => {
});
});

test('can be created with multiple ALB Target Groups as the load balancers', () => {
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
test('can be created with multiple ALB Target Groups as the load balancers', () => {
test('can be created with multiple Target Groups as the load balancers', () => {

You can specify also CLBs and NLBs.

@@ -150,6 +150,29 @@ const deploymentGroup = new codedeploy.ServerDeploymentGroup(this, 'DeploymentGr
});
```

To provide multiple Elastic Load Balancers as target groups use the `loadBalancers` parameter:
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
To provide multiple Elastic Load Balancers as target groups use the `loadBalancers` parameter:
The `loadBalancer` property has been deprecated. To provide multiple Elastic Load Balancers
as target groups use the `loadBalancers` parameter:

Note about deprecation.

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.

The build is still failing but I note now that you opened the PR from your main branch.
Merge requests opened from the main branch cannot be merged.
You should close this PR and open a new one from a separate branch.
Thanks 💪

Comment on lines +216 to +231
test.each<{ clbCount: number, albCount: number, nlbCount: number, TargetGroupInfoList: string[], ElbInfoList: string[] }>([
{ clbCount: 0, albCount: 0, nlbCount: 1, TargetGroupInfoList: ['NLBListenerNLB0FleetGroup657E42E4'], ElbInfoList: [] },
{ clbCount: 0, albCount: 0, nlbCount: 2, TargetGroupInfoList: ['NLBListenerNLB0FleetGroup657E42E4', 'NLBListenerNLB1FleetGroup5298209F'], ElbInfoList: [] },
{ clbCount: 0, albCount: 1, nlbCount: 0, TargetGroupInfoList: ['ALBListenerALB0FleetGroupF4CBAA91'], ElbInfoList: [] },
{ clbCount: 0, albCount: 2, nlbCount: 0, TargetGroupInfoList: ['ALBListenerALB0FleetGroupF4CBAA91', 'ALBListenerALB1FleetGroupD8E824C3'], ElbInfoList: [] },
{ clbCount: 0, albCount: 1, nlbCount: 1, TargetGroupInfoList: ['ALBListenerALB0FleetGroupF4CBAA91', 'NLBListenerNLB0FleetGroup657E42E4'], ElbInfoList: [] },
{ clbCount: 0, albCount: 2, nlbCount: 2, TargetGroupInfoList: ['ALBListenerALB0FleetGroupF4CBAA91', 'ALBListenerALB1FleetGroupD8E824C3', 'NLBListenerNLB0FleetGroup657E42E4', 'NLBListenerNLB1FleetGroup5298209F'], ElbInfoList: [] },
{ clbCount: 1, albCount: 0, nlbCount: 0, TargetGroupInfoList: [], ElbInfoList: ['CLB0677386E0'] },
{ clbCount: 2, albCount: 0, nlbCount: 0, TargetGroupInfoList: [], ElbInfoList: ['CLB0677386E0', 'CLB18DCC2BD6'] },
{ clbCount: 1, albCount: 0, nlbCount: 1, TargetGroupInfoList: ['NLBListenerNLB0FleetGroup657E42E4'], ElbInfoList: ['CLB0677386E0'] },
{ clbCount: 2, albCount: 0, nlbCount: 2, TargetGroupInfoList: ['NLBListenerNLB0FleetGroup657E42E4', 'NLBListenerNLB1FleetGroup5298209F'], ElbInfoList: ['CLB0677386E0', 'CLB18DCC2BD6'] },
{ clbCount: 1, albCount: 1, nlbCount: 0, TargetGroupInfoList: ['ALBListenerALB0FleetGroupF4CBAA91'], ElbInfoList: ['CLB0677386E0'] },
{ clbCount: 2, albCount: 2, nlbCount: 0, TargetGroupInfoList: ['ALBListenerALB0FleetGroupF4CBAA91', 'ALBListenerALB1FleetGroupD8E824C3'], ElbInfoList: ['CLB0677386E0', 'CLB18DCC2BD6'] },
{ clbCount: 1, albCount: 1, nlbCount: 1, TargetGroupInfoList: ['ALBListenerALB0FleetGroupF4CBAA91', 'NLBListenerNLB0FleetGroup657E42E4'], ElbInfoList: ['CLB0677386E0'] },
{ clbCount: 2, albCount: 2, nlbCount: 2, TargetGroupInfoList: ['ALBListenerALB0FleetGroupF4CBAA91', 'ALBListenerALB1FleetGroupD8E824C3', 'NLBListenerNLB0FleetGroup657E42E4', 'NLBListenerNLB1FleetGroup5298209F'], ElbInfoList: ['CLB0677386E0', 'CLB18DCC2BD6'] },
])('Should build ServerDeploymentGroup with $clbCount CLBs, $albCount ALBs and $nlbCount NLBs expecting TargetGroupInfoList $TargetGroupInfoList and ElbInfoList $ElbInfoList', ({ clbCount, albCount, nlbCount, TargetGroupInfoList, ElbInfoList }) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

The test added below already gives test coverage for the new feature.
What's the benefit of checking for all potential combinations of ELBs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just wanted to make sure as many test cases were covered as possible in case I might of missed a corner case.

@nicolastremblay1
Copy link
Contributor Author

Moving the PR here

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

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 pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CDK CodeDeploy: Support more then one NLB
3 participants