From 2c948242265b2be8598a0018ebfb397310aaf468 Mon Sep 17 00:00:00 2001 From: Khanh Tran <32532742+khanhtc1202@users.noreply.github.com> Date: Tue, 28 Nov 2023 21:00:32 +0700 Subject: [PATCH] Cherry-pick #4668 #4688 (#4689) * feat(ECS): enable selection of listener rules (#4668) * feat(ECS): enable selection of listener rules Signed-off-by: moko-poi * Update pkg/app/piped/platformprovider/ecs/client.go Signed-off-by: moko-poi * Make actions plan preview handle timeout option (#4648) * Format and make tests pass in tool/actions-plan-preview Signed-off-by: mi11km * Use --piped-handle-timeout to make the timeout arg activate Signed-off-by: mi11km * Add tests to model/notificationevent (#4631) * Add tests to model/notificationevent Signed-off-by: Kenta Kozuka * Add Parallel() Signed-off-by: Kenta Kozuka --------- Signed-off-by: Kenta Kozuka Signed-off-by: mi11km * add piped-handle-timeout(input args) Signed-off-by: mi11km --------- Signed-off-by: mi11km Signed-off-by: Kenta Kozuka Co-authored-by: Kenta Kozuka Co-authored-by: Khanh Tran <32532742+khanhtc1202@users.noreply.github.com> Signed-off-by: moko-poi * Increase limit of stale action operations (#4671) Signed-off-by: moko-poi * Add docs for k8s annotations (#4673) Signed-off-by: Yoshiki Fujikane Signed-off-by: moko-poi * feat: add modifylisner and modifyrule Signed-off-by: moko-poi * fix: ModifyRules Signed-off-by: moko-poi * fix: rollback Signed-off-by: moko-poi * fix: routing Signed-off-by: moko-poi * fix: action.Type == elbtypes.ActionTypeEnumForward Signed-off-by: moko-poi * fix: Update ModifyListeners and ModifyRules for Selective Action Modification Signed-off-by: moko-poi --------- Signed-off-by: moko-poi Signed-off-by: mi11km Signed-off-by: Kenta Kozuka Signed-off-by: Yoshiki Fujikane Co-authored-by: Khanh Tran <32532742+khanhtc1202@users.noreply.github.com> Co-authored-by: Masafumi Ikeyama <54844746+mi11km@users.noreply.github.com> Co-authored-by: Kenta Kozuka Co-authored-by: Yoshiki Fujikane <40124947+ffjlabo@users.noreply.github.com> * Remove ModifyRules interface (#4688) --------- Signed-off-by: moko-poi Signed-off-by: mi11km Signed-off-by: Kenta Kozuka Signed-off-by: Yoshiki Fujikane Co-authored-by: Shun Takahashi Co-authored-by: Masafumi Ikeyama <54844746+mi11km@users.noreply.github.com> Co-authored-by: Kenta Kozuka Co-authored-by: Yoshiki Fujikane <40124947+ffjlabo@users.noreply.github.com> --- pkg/app/piped/executor/ecs/rollback.go | 2 +- pkg/app/piped/platformprovider/ecs/client.go | 41 +++++++++++++------- pkg/app/piped/platformprovider/ecs/ecs.go | 2 + 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/pkg/app/piped/executor/ecs/rollback.go b/pkg/app/piped/executor/ecs/rollback.go index 87c76306ff..daee023996 100644 --- a/pkg/app/piped/executor/ecs/rollback.go +++ b/pkg/app/piped/executor/ecs/rollback.go @@ -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 } } diff --git a/pkg/app/piped/platformprovider/ecs/client.go b/pkg/app/piped/platformprovider/ecs/client.go index 3b16819f80..e466991e1a 100644 --- a/pkg/app/piped/platformprovider/ecs/client.go +++ b/pkg/app/piped/platformprovider/ecs/client.go @@ -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{ @@ -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 diff --git a/pkg/app/piped/platformprovider/ecs/ecs.go b/pkg/app/piped/platformprovider/ecs/ecs.go index 692f50fb24..6d88f660a6 100644 --- a/pkg/app/piped/platformprovider/ecs/ecs.go +++ b/pkg/app/piped/platformprovider/ecs/ecs.go @@ -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 }