Skip to content

Commit

Permalink
pref: Reduce the number of DescribeImages calls (#6126)
Browse files Browse the repository at this point in the history
  • Loading branch information
engedaam authored and jonathan-innis committed May 15, 2024
1 parent fb4d75f commit 073f35a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion pkg/providers/amifamily/ami.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"sort"
"strings"
"sync"
"time"

"github.com/aws/aws-sdk-go/aws"
Expand All @@ -45,6 +46,7 @@ type Provider interface {
}

type DefaultProvider struct {
sync.Mutex
cache *cache.Cache
ssm ssmiface.SSMAPI
ec2api ec2iface.EC2API
Expand Down Expand Up @@ -117,6 +119,9 @@ func NewDefaultProvider(versionProvider version.Provider, ssm ssmiface.SSMAPI, e

// Get Returning a list of AMIs with its associated requirements
func (p *DefaultProvider) Get(ctx context.Context, nodeClass *v1beta1.EC2NodeClass, options *Options) (AMIs, error) {
p.Lock()
defer p.Unlock()

var err error
var amis AMIs
if len(nodeClass.Spec.AMISelectorTerms) == 0 {
Expand Down Expand Up @@ -199,7 +204,7 @@ func (p *DefaultProvider) getAMIs(ctx context.Context, terms []v1beta1.AMISelect
// Don't include filters in the Describe Images call as EC2 API doesn't allow empty filters.
Filters: lo.Ternary(len(filtersAndOwners.Filters) > 0, filtersAndOwners.Filters, nil),
Owners: lo.Ternary(len(filtersAndOwners.Owners) > 0, aws.StringSlice(filtersAndOwners.Owners), nil),
MaxResults: aws.Int64(500),
MaxResults: aws.Int64(1000),
}, func(page *ec2.DescribeImagesOutput, _ bool) bool {
for i := range page.Images {
reqs := p.getRequirementsFromImage(page.Images[i])
Expand Down
2 changes: 1 addition & 1 deletion pkg/providers/subnet/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type Provider interface {
}

type DefaultProvider struct {
sync.RWMutex
sync.Mutex
ec2api ec2iface.EC2API
cache *cache.Cache
cm *pretty.ChangeMonitor
Expand Down

0 comments on commit 073f35a

Please sign in to comment.