generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 71
Fix target group leaking and e2etest #510
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
Merged
Changes from all commits
Commits
Show all changes
6 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 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
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 |
|---|---|---|
|
|
@@ -248,26 +248,27 @@ type tgListOutput struct { | |
| func (s *defaultTargetGroupManager) List(ctx context.Context) ([]tgListOutput, error) { | ||
| lattice := s.cloud.Lattice() | ||
| var tgList []tgListOutput | ||
| targetGroupListInput := vpclattice.ListTargetGroupsInput{ | ||
| VpcIdentifier: aws.String(config.VpcID), | ||
| TargetGroupType: aws.String(vpclattice.TargetGroupTypeIp), | ||
| } | ||
| targetGroupListInput := vpclattice.ListTargetGroupsInput{} | ||
| resp, err := lattice.ListTargetGroupsAsList(ctx, &targetGroupListInput) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if len(resp) == 0 { | ||
| return nil, nil | ||
| } | ||
| tgArns := utils.SliceMap(resp, func(tg *vpclattice.TargetGroupSummary) string { | ||
| validTgs := utils.SliceFilter(resp, func(tg *vpclattice.TargetGroupSummary) bool { | ||
| return aws.StringValue(tg.VpcIdentifier) == config.VpcID && | ||
| aws.StringValue(tg.Type) == vpclattice.TargetGroupTypeIp | ||
| }) | ||
| tgArns := utils.SliceMap(validTgs, func(tg *vpclattice.TargetGroupSummary) string { | ||
| return aws.StringValue(tg.Arn) | ||
| }) | ||
| tgArnToTagsMap, err := s.cloud.Tagging().GetTagsForArns(ctx, tgArns) | ||
|
|
||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| for _, tg := range resp { | ||
| for _, tg := range validTgs { | ||
| tgList = append(tgList, tgListOutput{ | ||
| tgSummary: tg, | ||
| tags: tgArnToTagsMap[*tg.Arn], | ||
|
|
@@ -288,44 +289,43 @@ func (s *defaultTargetGroupManager) findTargetGroup( | |
| if len(arns) == 0 { | ||
| return nil, nil | ||
| } | ||
| // Tag fields guarantee one result, as there can be only one target group for one service/route combination. | ||
| // We move forward but log this situation to help troubleshooting | ||
| if len(arns) > 1 { | ||
| s.log.Warnw("Target groups with conflicting tags found", "arns", arns) | ||
| } | ||
| arn := arns[0] | ||
|
|
||
| latticeTg, err := s.cloud.Lattice().GetTargetGroupWithContext(ctx, &vpclattice.GetTargetGroupInput{ | ||
| TargetGroupIdentifier: &arn, | ||
| }) | ||
| if err != nil { | ||
| return nil, services.IgnoreNotFound(err) | ||
| } | ||
| for _, arn := range arns { | ||
| latticeTg, err := s.cloud.Lattice().GetTargetGroupWithContext(ctx, &vpclattice.GetTargetGroupInput{ | ||
| TargetGroupIdentifier: &arn, | ||
| }) | ||
| if err != nil { | ||
| if services.IsNotFoundError(err) { | ||
| continue | ||
| } | ||
| return nil, err | ||
| } | ||
|
|
||
| // we ignore create failed status, so may as well check for it first | ||
| status := aws.StringValue(latticeTg.Status) | ||
| if status == vpclattice.TargetGroupStatusCreateFailed { | ||
| return nil, nil | ||
| } | ||
| // we ignore create failed status, so may as well check for it first | ||
| status := aws.StringValue(latticeTg.Status) | ||
| if status == vpclattice.TargetGroupStatusCreateFailed { | ||
| continue | ||
| } | ||
|
|
||
| // Double-check the immutable fields to ensure TG is valid | ||
| match, err := s.IsTargetGroupMatch(ctx, modelTargetGroup, &vpclattice.TargetGroupSummary{ | ||
| Arn: latticeTg.Arn, | ||
| Port: latticeTg.Config.Port, | ||
| Protocol: latticeTg.Config.Protocol, | ||
| IpAddressType: latticeTg.Config.IpAddressType, | ||
| Type: latticeTg.Type, | ||
| VpcIdentifier: latticeTg.Config.VpcIdentifier, | ||
| }, nil) // we already know that tags match | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if match { | ||
| switch status { | ||
| case vpclattice.TargetGroupStatusCreateInProgress, vpclattice.TargetGroupStatusDeleteInProgress: | ||
| return nil, errors.New(LATTICE_RETRY) | ||
| case vpclattice.TargetGroupStatusDeleteFailed, vpclattice.TargetGroupStatusActive: | ||
| return latticeTg, nil | ||
| // Check the immutable fields to ensure TG is valid | ||
| match, err := s.IsTargetGroupMatch(ctx, modelTargetGroup, &vpclattice.TargetGroupSummary{ | ||
| Arn: latticeTg.Arn, | ||
| Port: latticeTg.Config.Port, | ||
| Protocol: latticeTg.Config.Protocol, | ||
| IpAddressType: latticeTg.Config.IpAddressType, | ||
| Type: latticeTg.Type, | ||
| VpcIdentifier: latticeTg.Config.VpcIdentifier, | ||
| }, nil) // we already know that tags match | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if match { | ||
| switch status { | ||
| case vpclattice.TargetGroupStatusCreateInProgress, vpclattice.TargetGroupStatusDeleteInProgress: | ||
| return nil, errors.New(LATTICE_RETRY) | ||
| case vpclattice.TargetGroupStatusDeleteFailed, vpclattice.TargetGroupStatusActive: | ||
|
Contributor
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. Do we need to return err for
Contributor
Author
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. I don't think so, they do exist. |
||
| return latticeTg, nil | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
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
Oops, something went wrong.
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.
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.
Just wondering should we add a
Protocol(or other tg fields) tags for TargetGroup?So that to make sure one
FindResourcesByTags()api call could definitely exactly match one TG?(not in this PR)
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.
Not sure if it is necessary. Actually.. I wanted to remove as many tags as possible. I "had to" add protocolVersion in the tag because it is not available in TGSummary, so it needed extra Get() call to be figured out. Ideally VPC Lattice should just return protocolVersion in the summary instead.