Skip to content

Commit

Permalink
chore: remove ModifyListenerRules
Browse files Browse the repository at this point in the history
  • Loading branch information
moko-poi committed Nov 2, 2023
1 parent 0122ebb commit 2f76fa8
Showing 1 changed file with 23 additions and 59 deletions.
82 changes: 23 additions & 59 deletions pkg/app/piped/platformprovider/ecs/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,74 +495,38 @@ func (c *client) ModifyListenerOrRule(ctx context.Context, listenerArns []string
return nil
}

modifyListener := func(ctx context.Context, listenerArn string) error {
input := &elasticloadbalancingv2.ModifyListenerInput{
ListenerArn: aws.String(listenerArn),
DefaultActions: []elbtypes.Action{
{
Type: elbtypes.ActionTypeEnumForward,
ForwardConfig: &elbtypes.ForwardActionConfig{
TargetGroups: []elbtypes.TargetGroupTuple{
{
TargetGroupArn: aws.String(routingTrafficCfg[0].TargetGroupArn),
Weight: aws.Int32(int32(routingTrafficCfg[0].Weight)),
},
{
TargetGroupArn: aws.String(routingTrafficCfg[1].TargetGroupArn),
Weight: aws.Int32(int32(routingTrafficCfg[1].Weight)),
if len(listenerRuleArns) == 0 {
modifyListener := func(ctx context.Context, listenerArn string) error {
input := &elasticloadbalancingv2.ModifyListenerInput{
ListenerArn: aws.String(listenerArn),
DefaultActions: []elbtypes.Action{
{
Type: elbtypes.ActionTypeEnumForward,
ForwardConfig: &elbtypes.ForwardActionConfig{
TargetGroups: []elbtypes.TargetGroupTuple{
{
TargetGroupArn: aws.String(routingTrafficCfg[0].TargetGroupArn),
Weight: aws.Int32(int32(routingTrafficCfg[0].Weight)),
},
{
TargetGroupArn: aws.String(routingTrafficCfg[1].TargetGroupArn),
Weight: aws.Int32(int32(routingTrafficCfg[1].Weight)),
},
},
},
},
},
},
}
_, err := c.elbClient.ModifyListener(ctx, input)
return err
}

for _, listener := range listenerArns {
if err := modifyListener(ctx, listener); err != nil {
}
_, err := c.elbClient.ModifyListener(ctx, input)
return err
}
}
return nil
}

func (c *client) ModifyListenerRules(ctx context.Context, listenerRuleArns []string, routingTrafficCfg RoutingTrafficConfig) error {
if len(routingTrafficCfg) != 2 {
return fmt.Errorf("invalid listener configuration: requires 2 target groups")
}

modifyListenerRule := func(ctx context.Context, listenerRuleArn string) error {
input := &elasticloadbalancingv2.ModifyRuleInput{
RuleArn: aws.String(listenerRuleArn),
Actions: []elbtypes.Action{
{
Type: elbtypes.ActionTypeEnumForward,
ForwardConfig: &elbtypes.ForwardActionConfig{
TargetGroups: []elbtypes.TargetGroupTuple{
{
TargetGroupArn: aws.String(routingTrafficCfg[0].TargetGroupArn),
Weight: aws.Int32(int32(routingTrafficCfg[0].Weight)),
},
{
TargetGroupArn: aws.String(routingTrafficCfg[1].TargetGroupArn),
Weight: aws.Int32(int32(routingTrafficCfg[1].Weight)),
},
},
},
},
},
for _, listener := range listenerArns {
if err := modifyListener(ctx, listener); err != nil {
return err
}
}
_, err := c.elbClient.ModifyRule(ctx, input)
return err
}

for _, listener := range listenerRuleArns {
if err := modifyListenerRule(ctx, listener); err != nil {
return err
}
}
return nil
}

Expand Down

0 comments on commit 2f76fa8

Please sign in to comment.