Skip to content
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

fix: Add pagination to FindLoadBalancerByDNSName #1971

Merged
merged 4 commits into from
Apr 13, 2022
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 go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/antonmedv/expr v1.9.0
github.com/argoproj/notifications-engine v0.3.1-0.20220129012210-32519f8f68ec
github.com/argoproj/pkg v0.9.0
github.com/aws/aws-sdk-go-v2 v1.13.0
github.com/aws/aws-sdk-go-v2/config v1.13.1
github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.15.0
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.16.0
Expand Down Expand Up @@ -66,7 +67,6 @@ require (
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/RocketChat/Rocket.Chat.Go.SDK v0.0.0-20210112200207-10ab4d695d60 // indirect
github.com/aws/aws-sdk-go-v2 v1.13.0 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.8.0 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.10.0 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.4 // indirect
Expand Down
21 changes: 14 additions & 7 deletions utils/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"fmt"
"strings"

"github.com/aws/aws-sdk-go-v2/aws"

"github.com/argoproj/argo-rollouts/utils/defaults"
"github.com/aws/aws-sdk-go-v2/config"
elbv2 "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2"
Expand Down Expand Up @@ -128,13 +130,18 @@ func FakeNewClientFunc(elbClient ELBv2APIClient) func() (Client, error) {
}

func (c *ClientAdapter) FindLoadBalancerByDNSName(ctx context.Context, dnsName string) (*elbv2types.LoadBalancer, error) {
lbOutput, err := c.ELBV2.DescribeLoadBalancers(ctx, &elbv2.DescribeLoadBalancersInput{})
if err != nil {
return nil, err
}
for _, lb := range lbOutput.LoadBalancers {
if lb.DNSName != nil && *lb.DNSName == dnsName {
return &lb, nil
paginator := elbv2.NewDescribeLoadBalancersPaginator(c.ELBV2, &elbv2.DescribeLoadBalancersInput{
PageSize: aws.Int32(defaults.DefaultAwsLoadBalancerPageSize),
})
for paginator.HasMorePages() {
output, err := paginator.NextPage(ctx)
if err != nil {
return nil, err
}
for _, lb := range output.LoadBalancers {
if lb.DNSName != nil && *lb.DNSName == dnsName {
return &lb, nil
}
}
}
return nil, nil
Expand Down
2 changes: 2 additions & 0 deletions utils/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const (
DefaultQPS float32 = 40.0
// DefaultBurst is the default value for Burst for client side throttling to the K8s API server
DefaultBurst int = 80
// DefaultAwsLoadBalancerPageSize is the default page size used when calling aws to get load balancers by DNS name
DefaultAwsLoadBalancerPageSize = int32(300)
)

const (
Expand Down