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): loadbalancer support for imported Target Groups #17848

Merged
merged 13 commits into from
Dec 20, 2021

Conversation

eastNine
Copy link
Contributor

@eastNine eastNine commented Dec 5, 2021

This PR fixes that imported alb and nlb target group be able to configure to loadBalancer property.

Fixes #9677.

example:

import * as cdk from '@aws-cdk/core';
import * as codedeploy from '@aws-cdk/aws-codedeploy';
import * as elbv2 from '@aws-cdk/aws-elasticloadbalancingv2';

const deploymentGroup = new codedeploy.ServerDeploymentGroup(this, 'deploymentGroup', {
    ...

    // configurable imported application loadbalancer targetgroup
    loadBalancer: codedeploy.LoadBalancer.application(
        elbv2.ApplicationTargetGroup.fromTargetGroupAttributes(this, 'importedAlbTg', {
            targetGroupArn: 'arn:aws:elasticloadbalancing:ap-northeast-2:111111111111:targetgroup/myAlbTargetgroup/abcd12345678efgf'
        })
    ),

    // also network loadbalancer targetgroup
    loadBalancer: codedeploy.LoadBalancer.network(
        elbv2.NetworkTargetGroup.fromTargetGroupAttributes(this, 'importedNlbTg', {
            targetGroupArn: 'arn:aws:elasticloadbalancing:ap-northeast-2:111111111111:targetgroup/myNlbTargetgroup/wxyz09876543opqr'
        })
    ),
});

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

@gitpod-io
Copy link

gitpod-io bot commented Dec 5, 2021

@github-actions github-actions bot added the @aws-cdk/aws-codedeploy Related to AWS CodeDeploy label Dec 5, 2021
@mergify
Copy link
Contributor

mergify bot commented Dec 5, 2021

Title does not follow the guidelines of Conventional Commits. Please adjust title before merge.

eastNine and others added 4 commits December 5, 2021 19:32
Move `parameterGroup` from `DatabaseInstanceSourceProps` to
`DatabaseInstanceNewProps` since the parameter group of a replica
instance can be customized.

Closes aws#17580


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@eastNine eastNine changed the title fix(codedeploy) : loadbalancer support imported application and network loadbalancer targetgroup fix(codedeploy): loadbalancer support imported application and network loadbalancer targetgroup Dec 5, 2021
Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution @eastNine! I think we should go a slightly different route than what you proposed here.

Let me know if you agree with my proposal!

Thanks,
Adam

'Ref': 'NLBListenerFleetGroupB882EC86',
},
],
},
],
},
},
Copy link
Contributor

Choose a reason for hiding this comment

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

We're missing a unit test for using LoadBalancer with imported Target Groups here 🙂.

class AlbLoadBalancer extends LoadBalancer {
public readonly generation = LoadBalancerGeneration.SECOND;
public readonly name = albTargetGroup.targetGroupName;
public readonly name = targetGruopNameFromArn(albTargetGroup.targetGroupArn);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't particularly like this solution. I actually think this is putting the logic of how to get the name of the Target Group from its ARN in the wrong place.

Let's do this a little bit differently:

  1. Let's add a targetGroupName property to ITargetGroup.
  2. In imported Target Groups, let's add the logic of parsing it from the ARN of the Target Group.
  3. Let's keep using public readonly name = albTargetGroup.targetGroupName; here, but now, this will Just Work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I agree your proposal.👌
I will update soon with this approach.

@mergify mergify bot dismissed skinny85’s stale review December 8, 2021 16:05

Pull request has been modified.

Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

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

Looks good @eastNine, but we need a few changes before we merge this in.

@@ -350,7 +350,12 @@ export interface TargetGroupAttributes {
* ARN of the target group
*/
readonly targetGroupArn: string;

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's keep this empty line (there should be an empty line separating the properties).

*
* @default targetGroupName
*/
readonly targetGroupName?: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing empty line after this line.

/**
* The name of the target group
*
* @default targetGroupName
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we adding this property here? targetGroupArn is already required, so what does providing an optional targetGroupName accomplish? I also don't see you using this property anywhere.

I think we should remove 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.

This code added while my test.
I removed this.

@@ -14,7 +15,10 @@ export abstract class ImportedTargetGroupBase extends CoreConstruct implements I
* ARN of the target group
*/
public readonly targetGroupArn: string;

Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment here (there should be an empty line separating the fields).

* Return the targetGroupName from targetGroupArn
*/
export function targetGroupNameFromArn(targetGroupArn: string) {
const arnParts = Fn.split('/', targetGroupArn);
Copy link
Contributor

Choose a reason for hiding this comment

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

We have a function in the core Stack for this already: Stack.splitArn(). See how it's used here, for example.

),
});

expect(stack).toHaveResource('AWS::CodeDeploy::DeploymentGroup', {
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
expect(stack).toHaveResource('AWS::CodeDeploy::DeploymentGroup', {
expect(stack).toHaveResourceLike('AWS::CodeDeploy::DeploymentGroup', {

Comment on lines 496 to 499
'DeploymentStyle': {
'DeploymentOption': 'WITH_TRAFFIC_CONTROL',
},
});
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is relevant to this test, let's just remove this.

Comment on lines +453 to +455
'DeploymentStyle': {
'DeploymentOption': 'WITH_TRAFFIC_CONTROL',
},
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is relevant to this test, let's just remove this.

@skinny85
Copy link
Contributor

@eastNine make sure to re-request my review (there's a button in the top-right of the PR window, next to my avatar) once you're ready for another round of reviews - this way, I won't miss another iteration when it's ready. Thanks!

@mergify mergify bot dismissed skinny85’s stale review December 19, 2021 09:24

Pull request has been modified.

@eastNine
Copy link
Contributor Author

eastNine commented Dec 19, 2021

@skinny85
Thanks for review!
I updated PR.

this.targetGroupName = cdk.Stack.of(scope).splitArn(props.targetGroupArn, cdk.ArnFormat.SLASH_RESOURCE_SLASH_RESOURCE_NAME).resourceName!;

I tried above,
it returns myAlbTargetGroup/73e2d6bc24d8a067 as resourcename in test.

I think we can't use return value of Stack.splitArn().
Because, property targetGroupInfo.Name is only aceept targetgroup's name instead of resourcename.

Reference aws-properties-codedeploy-deploymentgroup-targetgroupinfo

So I added one more split.

https://github.com/eastNine/aws-cdk/blob/fix-codedeploy-loadbalancer/packages/%40aws-cdk/aws-elasticloadbalancingv2/lib/shared/imported.ts#L37

Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

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

Looks great @eastNine, thanks so much for the contribution!

@mergify
Copy link
Contributor

mergify bot commented Dec 20, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@skinny85 skinny85 changed the title fix(codedeploy): loadbalancer support imported application and network loadbalancer targetgroup fix(codedeploy): loadbalancer support for imported Target Groups Dec 20, 2021
@skinny85 skinny85 added the pr-linter/exempt-readme The PR linter will not require README changes label Dec 20, 2021
@skinny85 skinny85 changed the title fix(codedeploy): loadbalancer support for imported Target Groups feat(codedeploy): loadbalancer support for imported Target Groups Dec 20, 2021
@mergify
Copy link
Contributor

mergify bot commented Dec 20, 2021

Thank you for contributing! Your pull request will be updated from master 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: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 13fc16d
  • 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 32f1c80 into aws:master Dec 20, 2021
@mergify
Copy link
Contributor

mergify bot commented Dec 20, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this pull request Feb 21, 2022
…s#17848)

This PR fixes that imported alb and nlb target group be able to configure to loadBalancer property.

Fixes aws#9677.

example:

```TypeScript
import * as cdk from '@aws-cdk/core';
import * as codedeploy from '@aws-cdk/aws-codedeploy';
import * as elbv2 from '@aws-cdk/aws-elasticloadbalancingv2';

const deploymentGroup = new codedeploy.ServerDeploymentGroup(this, 'deploymentGroup', {
    ...

    // configurable imported application loadbalancer targetgroup
    loadBalancer: codedeploy.LoadBalancer.application(
        elbv2.ApplicationTargetGroup.fromTargetGroupAttributes(this, 'importedAlbTg', {
            targetGroupArn: 'arn:aws:elasticloadbalancing:ap-northeast-2:111111111111:targetgroup/myAlbTargetgroup/abcd12345678efgf'
        })
    ),

    // also network loadbalancer targetgroup
    loadBalancer: codedeploy.LoadBalancer.network(
        elbv2.NetworkTargetGroup.fromTargetGroupAttributes(this, 'importedNlbTg', {
            targetGroupArn: 'arn:aws:elasticloadbalancing:ap-northeast-2:111111111111:targetgroup/myNlbTargetgroup/wxyz09876543opqr'
        })
    ),
});
```

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-codedeploy Related to AWS CodeDeploy pr-linter/exempt-readme The PR linter will not require README changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

software.amazon.awscdk.services.codedeploy.LoadBalancer.application construct seems to be wrong
4 participants