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 656cf1e commit 8b08944
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 @@ -44,6 +45,7 @@ import (
)

type Provider struct {
sync.Mutex
cache *cache.Cache
ssm ssmiface.SSMAPI
ec2api ec2iface.EC2API
Expand Down Expand Up @@ -116,6 +118,9 @@ func NewProvider(versionProvider *version.Provider, ssm ssmiface.SSMAPI, ec2api

// Get Returning a list of AMIs with its associated requirements
func (p *Provider) 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 @@ -198,7 +203,7 @@ func (p *Provider) getAMIs(ctx context.Context, terms []v1beta1.AMISelectorTerm,
// 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], isNodeTemplate)
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 @@ -37,7 +37,7 @@ import (
)

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

0 comments on commit 8b08944

Please sign in to comment.