Skip to content

Commit

Permalink
Merge pull request #6056 from KierranM/batch-asg-requests
Browse files Browse the repository at this point in the history
Request AWS ASGs in batches
  • Loading branch information
k8s-ci-robot authored Nov 17, 2018
2 parents ea97194 + 0be767a commit 4094e89
Showing 1 changed file with 29 additions and 18 deletions.
47 changes: 29 additions & 18 deletions upup/pkg/fi/cloudup/awsup/aws_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,33 +491,44 @@ func FindAutoscalingGroups(c AWSCloud, tags map[string]string) ([]*autoscaling.G
}

if len(asgNames) != 0 {
request := &autoscaling.DescribeAutoScalingGroupsInput{
AutoScalingGroupNames: asgNames,
}
err := c.Autoscaling().DescribeAutoScalingGroupsPages(request, func(p *autoscaling.DescribeAutoScalingGroupsOutput, lastPage bool) bool {
for _, asg := range p.AutoScalingGroups {
if !matchesAsgTags(tags, asg.Tags) {
// We used an inexact filter above
continue
}
// Check for "Delete in progress" (the only use of .Status)
if asg.Status != nil {
glog.Warningf("Skipping ASG %v (which matches tags): %v", *asg.AutoScalingGroupARN, *asg.Status)
continue
for i := 0; i < len(asgNames); i += 50 {
batch := asgNames[i:minInt(i+50, len(asgNames))]
request := &autoscaling.DescribeAutoScalingGroupsInput{
AutoScalingGroupNames: batch,
}
err := c.Autoscaling().DescribeAutoScalingGroupsPages(request, func(p *autoscaling.DescribeAutoScalingGroupsOutput, lastPage bool) bool {
for _, asg := range p.AutoScalingGroups {
if !matchesAsgTags(tags, asg.Tags) {
// We used an inexact filter above
continue
}
// Check for "Delete in progress" (the only use of .Status)
if asg.Status != nil {
glog.Warningf("Skipping ASG %v (which matches tags): %v", *asg.AutoScalingGroupARN, *asg.Status)
continue
}
asgs = append(asgs, asg)
}
asgs = append(asgs, asg)
return true
})
if err != nil {
return nil, fmt.Errorf("error listing autoscaling groups: %v", err)
}
return true
})
if err != nil {
return nil, fmt.Errorf("error listing autoscaling groups: %v", err)
}

}

return asgs, nil
}

// Returns the minimum of two ints
func minInt(a int, b int) int {
if a < b {
return a
}
return b
}

// matchesAsgTags is used to filter an asg by tags
func matchesAsgTags(tags map[string]string, actual []*autoscaling.TagDescription) bool {
for k, v := range tags {
Expand Down

0 comments on commit 4094e89

Please sign in to comment.