This repository has been archived by the owner on Jan 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 328
Allow bringing your own alb listener #4453
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:bug | ||
plugin/aws-ecs: Fix bringing your own alb listener to ecs deployments. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,14 @@ message Deployment { | |
string task_arn = 2; | ||
string service_arn = 3; | ||
string target_group_arn = 4; | ||
string load_balancer_arn = 5; | ||
|
||
// Reference to the load balancer. Either the LB itself (if we created it), | ||
// or the lb listener if the user specified it. | ||
oneof lb_reference { | ||
string load_balancer_arn = 5; | ||
string listener_arn = 8; | ||
} | ||
Comment on lines
+17
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like it could be a breaking protobuf change, but I don't think it is! It's not changing field numbers. I also tried releasing a deployment made with the previous compiled protobufs, and it worked. |
||
|
||
string cluster = 6; | ||
opaqueany.Any resource_state = 7; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ import ( | |
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/elbv2" | ||
"github.com/hashicorp/go-hclog" | ||
"github.com/pkg/errors" | ||
|
||
"github.com/hashicorp/waypoint-plugin-sdk/component" | ||
"github.com/hashicorp/waypoint-plugin-sdk/docs" | ||
"github.com/hashicorp/waypoint-plugin-sdk/terminal" | ||
|
@@ -37,8 +39,9 @@ func (r *Releaser) Release( | |
ui terminal.UI, | ||
target *Deployment, | ||
) (*Release, error) { | ||
if target.LoadBalancerArn == "" && target.TargetGroupArn == "" { | ||
log.Info("No load-balancer configured") | ||
|
||
if target.TargetGroupArn == "" { | ||
log.Info("No target group configured, skipping release") | ||
return &Release{}, nil | ||
} | ||
|
||
|
@@ -51,43 +54,119 @@ func (r *Releaser) Release( | |
} | ||
elbsrv := elbv2.New(sess) | ||
|
||
dlb, err := elbsrv.DescribeLoadBalancers(&elbv2.DescribeLoadBalancersInput{ | ||
LoadBalancerArns: []*string{&target.LoadBalancerArn}, | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's the bug. If you specify your own target group arn, |
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var lb *elbv2.LoadBalancer | ||
|
||
if len(dlb.LoadBalancers) == 0 { | ||
return nil, fmt.Errorf("No load balancers returned by DescribeLoadBalancers") | ||
} | ||
|
||
lb = dlb.LoadBalancers[0] | ||
|
||
listeners, err := elbsrv.DescribeListeners(&elbv2.DescribeListenersInput{ | ||
LoadBalancerArn: lb.LoadBalancerArn, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
var hostname string | ||
if r.p.config.ALB != nil && r.p.config.ALB.FQDN != "" { | ||
hostname = r.p.config.ALB.FQDN | ||
} | ||
|
||
var listener *elbv2.Listener | ||
|
||
tgs := []*elbv2.TargetGroupTuple{ | ||
{ | ||
TargetGroupArn: &target.TargetGroupArn, | ||
Weight: aws.Int64(100), | ||
}, | ||
} | ||
|
||
log.Debug("configuring weight 100 for target group", "arn", target.TargetGroupArn) | ||
// existingListener, if discovered, will be modified to introduce the new target group. | ||
var existingListener *elbv2.Listener | ||
var lbArn string | ||
|
||
switch lbRef := target.LbReference.(type) { | ||
case *Deployment_LoadBalancerArn: | ||
// We have a load balancer. Either discover the existing listener, or create a new one. | ||
lbArn = lbRef.LoadBalancerArn | ||
|
||
dlb, err := elbsrv.DescribeLoadBalancers(&elbv2.DescribeLoadBalancersInput{ | ||
LoadBalancerArns: []*string{&lbRef.LoadBalancerArn}, | ||
}) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "failed to describe load balancer %q", lbRef.LoadBalancerArn) | ||
} | ||
|
||
var lb *elbv2.LoadBalancer | ||
|
||
if len(dlb.LoadBalancers) == 0 { | ||
return nil, fmt.Errorf("no load balancers returned by DescribeLoadBalancers") | ||
} | ||
|
||
if len(listeners.Listeners) > 0 { | ||
listener = listeners.Listeners[0] | ||
lb = dlb.LoadBalancers[0] | ||
|
||
def := listener.DefaultActions | ||
// Now that we have the LB, set the hostname if necessary | ||
if hostname == "" { | ||
hostname = *lb.DNSName | ||
} | ||
|
||
listeners, err := elbsrv.DescribeListeners(&elbv2.DescribeListenersInput{ | ||
LoadBalancerArn: lb.LoadBalancerArn, | ||
}) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "failed to describe listener for lb %q", lb.LoadBalancerArn) | ||
} | ||
|
||
if len(listeners.Listeners) > 0 { | ||
if len(listeners.Listeners) > 1 { | ||
log.Warn("ALB has multiple listeners - only modifying the first listaner and ignoring all others") | ||
} | ||
existingListener = listeners.Listeners[0] | ||
} else { | ||
log.Info("load-balancer defined", "dns-name", *lb.DNSName) | ||
|
||
_, err := elbsrv.CreateListener(&elbv2.CreateListenerInput{ | ||
LoadBalancerArn: lb.LoadBalancerArn, | ||
Port: aws.Int64(80), | ||
Protocol: aws.String("HTTP"), | ||
DefaultActions: []*elbv2.Action{ | ||
{ | ||
ForwardConfig: &elbv2.ForwardActionConfig{ | ||
TargetGroups: tgs, | ||
}, | ||
Type: aws.String("forward"), | ||
}, | ||
}, | ||
}) | ||
|
||
if err != nil { | ||
return nil, errors.Wrapf(err, "failed to create listener") | ||
} | ||
|
||
// Do not set existingListener | ||
} | ||
|
||
case *Deployment_ListenerArn: | ||
lo, err := elbsrv.DescribeListeners(&elbv2.DescribeListenersInput{ | ||
ListenerArns: []*string{&lbRef.ListenerArn}, | ||
}) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "failed to describe listener %q", lbRef.ListenerArn) | ||
} | ||
if len(lo.Listeners) == 0 { | ||
return nil, errors.Errorf("listener %q not found", lbRef.ListenerArn) | ||
} | ||
existingListener = lo.Listeners[0] | ||
lbArn = *existingListener.LoadBalancerArn | ||
|
||
if hostname == "" { | ||
// We need to get the hostname from the existing alb | ||
|
||
dlb, err := elbsrv.DescribeLoadBalancers(&elbv2.DescribeLoadBalancersInput{ | ||
LoadBalancerArns: []*string{existingListener.LoadBalancerArn}, | ||
}) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "failed to describe load balancer for listener %q", *existingListener.LoadBalancerArn) | ||
} | ||
|
||
if len(dlb.LoadBalancers) == 0 { | ||
return nil, fmt.Errorf("no load balancers returned by DescribeLoadBalancers") | ||
} | ||
|
||
hostname = *dlb.LoadBalancers[0].DNSName | ||
} | ||
|
||
} | ||
|
||
if existingListener != nil { | ||
log.Debug("configuring weight 100 for target group", "arn", target.TargetGroupArn) | ||
|
||
def := existingListener.DefaultActions | ||
|
||
if len(def) > 0 && def[0].ForwardConfig != nil { | ||
for _, tg := range def[0].ForwardConfig.TargetGroups { | ||
|
@@ -104,9 +183,9 @@ func (r *Releaser) Release( | |
|
||
log.Debug("modifying load balancer", "tgs", len(tgs)) | ||
_, err = elbsrv.ModifyListener(&elbv2.ModifyListenerInput{ | ||
ListenerArn: listener.ListenerArn, | ||
Port: listener.Port, | ||
Protocol: listener.Protocol, | ||
ListenerArn: existingListener.ListenerArn, | ||
Port: existingListener.Port, | ||
Protocol: existingListener.Protocol, | ||
DefaultActions: []*elbv2.Action{ | ||
{ | ||
ForwardConfig: &elbv2.ForwardActionConfig{ | ||
|
@@ -117,41 +196,13 @@ func (r *Releaser) Release( | |
}, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
return nil, errors.Wrapf(err, "failed to modify listener %q to introduce new target group", existingListener.ListenerArn) | ||
} | ||
} else { | ||
log.Info("load-balancer defined", "dns-name", *lb.DNSName) | ||
|
||
lo, err := elbsrv.CreateListener(&elbv2.CreateListenerInput{ | ||
LoadBalancerArn: lb.LoadBalancerArn, | ||
Port: aws.Int64(80), | ||
Protocol: aws.String("HTTP"), | ||
DefaultActions: []*elbv2.Action{ | ||
{ | ||
ForwardConfig: &elbv2.ForwardActionConfig{ | ||
TargetGroups: tgs, | ||
}, | ||
Type: aws.String("forward"), | ||
}, | ||
}, | ||
}) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
listener = lo.Listeners[0] | ||
} | ||
|
||
hostname := *lb.DNSName | ||
|
||
if r.p.config.ALB != nil && r.p.config.ALB.FQDN != "" { | ||
hostname = r.p.config.ALB.FQDN | ||
} | ||
|
||
return &Release{ | ||
Url: "http://" + hostname, | ||
LoadBalancerArn: *lb.LoadBalancerArn, | ||
LoadBalancerArn: lbArn, | ||
}, nil | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
In the existing logic, a user could specify a listener arn in the platform config, but we weren't making that available to the releaser.