Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/app/piped/executor/ecs/rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func rollback(ctx context.Context, in *executor.Input, platformProviderName stri
}

if err := client.ModifyListeners(ctx, currListenerArns, routingTrafficCfg); err != nil {
in.LogPersister.Errorf("Failed to routing traffic to PRIMARY variant: %v", err)
in.LogPersister.Errorf("Failed to routing traffic to PRIMARY/CANARY variants: %v", err)
return false
}
}
Expand Down
41 changes: 28 additions & 13 deletions pkg/app/piped/platformprovider/ecs/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,11 +437,21 @@ func (c *client) ModifyListeners(ctx context.Context, listenerArns []string, rou
return fmt.Errorf("invalid listener configuration: requires 2 target groups")
}

modifyListener := func(ctx context.Context, listenerArn string) error {
input := &elasticloadbalancingv2.ModifyListenerInput{
ListenerArn: aws.String(listenerArn),
DefaultActions: []elbtypes.Action{
{
for _, listenerArn := range listenerArns {
// Describe the listener to get the current actions
describeListenersOutput, err := c.elbClient.DescribeListeners(ctx, &elasticloadbalancingv2.DescribeListenersInput{
ListenerArns: []string{listenerArn},
})
if err != nil {
return fmt.Errorf("error describing listener %s: %w", listenerArn, err)
}

// Prepare the actions to be modified
var modifiedActions []elbtypes.Action
for _, action := range describeListenersOutput.Listeners[0].DefaultActions {
if action.Type == elbtypes.ActionTypeEnumForward {
// Modify only the forward action
modifiedAction := elbtypes.Action{
Type: elbtypes.ActionTypeEnumForward,
ForwardConfig: &elbtypes.ForwardActionConfig{
TargetGroups: []elbtypes.TargetGroupTuple{
Expand All @@ -455,16 +465,21 @@ func (c *client) ModifyListeners(ctx context.Context, listenerArns []string, rou
},
},
},
},
},
}
modifiedActions = append(modifiedActions, modifiedAction)
} else {
// Keep other actions unchanged
modifiedActions = append(modifiedActions, action)
}
}
_, err := c.elbClient.ModifyListener(ctx, input)
return err
}

for _, listener := range listenerArns {
if err := modifyListener(ctx, listener); err != nil {
return err
// Modify the listener
_, err = c.elbClient.ModifyListener(ctx, &elasticloadbalancingv2.ModifyListenerInput{
ListenerArn: aws.String(listenerArn),
DefaultActions: modifiedActions,
})
if err != nil {
return fmt.Errorf("error modifying listener %s: %w", listenerArn, err)
}
}
return nil
Expand Down
2 changes: 2 additions & 0 deletions pkg/app/piped/platformprovider/ecs/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ type ECS interface {

type ELB interface {
GetListenerArns(ctx context.Context, targetGroup types.LoadBalancer) ([]string, error)
// ModifyListeners modifies the actions of type ActionTypeEnumForward to perform routing traffic
// to the given target groups. Other actions won't be modified.
ModifyListeners(ctx context.Context, listenerArns []string, routingTrafficCfg RoutingTrafficConfig) error
}

Expand Down