-
Notifications
You must be signed in to change notification settings - Fork 208
feat(ECS): enable selection of listener rules #4668
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
Merged
khanhtc1202
merged 13 commits into
pipe-cd:master
from
moko-poi:feat/enable-selection-of-listener-rule
Nov 28, 2023
Merged
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9e78352
feat(ECS): enable selection of listener rules
moko-poi 41b67d6
Update pkg/app/piped/platformprovider/ecs/client.go
khanhtc1202 78de40b
Make actions plan preview handle timeout option (#4648)
mi11km 5ea306a
Increase limit of stale action operations (#4671)
kentakozuka 5b3ac3f
Add docs for k8s annotations (#4673)
ffjlabo e7cb581
Merge branch 'master' into feat/enable-selection-of-listener-rule
khanhtc1202 a25602c
Merge branch 'master' into feat/enable-selection-of-listener-rule
khanhtc1202 965ba41
feat: add modifylisner and modifyrule
moko-poi 3a4bea5
fix: ModifyRules
moko-poi 0b01246
fix: rollback
moko-poi abd12ca
fix: routing
moko-poi 38855ce
fix: action.Type == elbtypes.ActionTypeEnumForward
moko-poi 2650922
fix: Update ModifyListeners and ModifyRules for Selective Action Modi…
moko-poi 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -417,6 +417,30 @@ func (c *client) GetListenerArns(ctx context.Context, targetGroup types.LoadBala | |
| return arns, nil | ||
| } | ||
|
|
||
| func (c *client) GetListenerRuleArns(ctx context.Context, listenerArns []string) ([]string, error) { | ||
| var ruleArns []string | ||
|
|
||
| // Fetch all rules by listeners | ||
| for _, listenerArn := range listenerArns { | ||
| input := &elasticloadbalancingv2.DescribeRulesInput{ | ||
| ListenerArn: aws.String(listenerArn), | ||
| } | ||
| output, err := c.elbClient.DescribeRules(ctx, input) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| for _, rule := range output.Rules { | ||
| ruleArns = append(ruleArns, *rule.RuleArn) | ||
| } | ||
| } | ||
|
|
||
| if len(ruleArns) == 0 { | ||
| return nil, platformprovider.ErrNotFound | ||
| } | ||
|
|
||
| return ruleArns, nil | ||
| } | ||
|
|
||
| func (c *client) getLoadBalancerArn(ctx context.Context, targetGroupArn string) (string, error) { | ||
| input := &elasticloadbalancingv2.DescribeTargetGroupsInput{ | ||
| TargetGroupArns: []string{targetGroupArn}, | ||
|
|
@@ -470,6 +494,68 @@ func (c *client) ModifyListeners(ctx context.Context, listenerArns []string, rou | |
| return nil | ||
| } | ||
|
|
||
| func (c *client) ModifyListenerOrRule(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)), | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| _, err := c.elbClient.ModifyRule(ctx, input) | ||
| return err | ||
| } | ||
|
|
||
| for _, ruleArn := range listenerRuleArns { | ||
| // Describe the rule to get current actions | ||
| describeRulesOutput, err := c.elbClient.DescribeRules(ctx, &elasticloadbalancingv2.DescribeRulesInput{ | ||
| RuleArns: []string{ruleArn}, | ||
| }) | ||
| if err != nil { | ||
| return fmt.Errorf("error describing listener rule %v: %w", ruleArn, err) | ||
| } | ||
|
|
||
| // No rules found, nothing to modify | ||
| if len(describeRulesOutput.Rules) == 0 { | ||
| return fmt.Errorf("no rules found for ARN: %s", ruleArn) | ||
| } | ||
|
|
||
| // Check if the current action type is forward | ||
| for _, rule := range describeRulesOutput.Rules { | ||
| for _, action := range rule.Actions { | ||
| if action.Type == elbtypes.ActionTypeEnumForward { | ||
| // Call modifyListenerRule only if action type is forward | ||
| if err := modifyListenerRule(ctx, ruleArn); err != nil { | ||
| return err | ||
| } | ||
| // Break the loop once the modify function is called for the rule | ||
| break | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func (c *client) TagResource(ctx context.Context, resourceArn string, tags []types.Tag) error { | ||
| input := &ecs.TagResourceInput{ | ||
| ResourceArn: aws.String(resourceArn), | ||
|
|
||
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.