Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ellistarn committed Jun 24, 2021
1 parent 46a02ba commit d34ed52
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
9 changes: 7 additions & 2 deletions pkg/cloudprovider/aws/cloudprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@ import (
)

const (
// CacheTTL restricts QPS to AWS APIs to this interval for verifying setup resources.
CacheTTL = 5 * time.Minute
// CacheTTL restricts QPS to AWS APIs to this interval for verifying setup
// resources. This value represents the maximum eventual consistency between
// AWS actual state and the controller's ability to provision those
// resources. Cache hits enable faster provisioning and reduced API load on
// AWS APIs, which can have a serious import on performance and scalability.
// DO NOT CHANGE THIS VALUE WITHOUT DUE CONSIDERATION
CacheTTL = 60 * time.Second
// CacheCleanupInterval triggers cache cleanup (lazy eviction) at this interval.
CacheCleanupInterval = 10 * time.Minute
// ClusterTagKeyFormat is set on all Kubernetes owned resources.
Expand Down
11 changes: 9 additions & 2 deletions pkg/cloudprovider/aws/launchtemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,18 @@ func (p *LaunchTemplateProvider) Get(ctx context.Context, provisioner *v1alpha1.
}

func (p *LaunchTemplateProvider) ensureLaunchTemplate(ctx context.Context, options *launchTemplateOptions) (*ec2.LaunchTemplate, error) {
var launchTemplate *ec2.LaunchTemplate
name := launchTemplateName(options)
// 1. Read from cache
if launchTemplate, ok := p.cache.Get(name); ok {
return launchTemplate.(*ec2.LaunchTemplate), nil
}
// 2. Attempt to find an existing LT.
output, err := p.ec2api.DescribeLaunchTemplatesWithContext(ctx, &ec2.DescribeLaunchTemplatesInput{
LaunchTemplateNames: []*string{aws.String(name)},
})
var launchTemplate *ec2.LaunchTemplate
if aerr, ok := err.(awserr.Error); ok && aerr.Code() == "InvalidLaunchTemplateName.NotFoundException" {
// 3. Create LT if one doesn't exist
launchTemplate, err = p.createLaunchTemplate(ctx, options)
if err != nil {
return nil, fmt.Errorf("creating launch template, %w", err)
Expand All @@ -134,9 +140,10 @@ func (p *LaunchTemplateProvider) ensureLaunchTemplate(ctx context.Context, optio
} else if len(output.LaunchTemplates) != 1 {
return nil, fmt.Errorf("expected to find one launch template, but found %d", len(output.LaunchTemplates))
} else {
zap.S().Debugf("Successfully discovered launch template %s", name)
zap.S().Debugf("Discovered launch template %s", name)
launchTemplate = output.LaunchTemplates[0]
}
// 4. Populate cache
p.cache.Set(name, launchTemplate, CacheTTL)
return launchTemplate, nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloudprovider/aws/utils/predicates/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func HasNameTag(name string) func([]*ec2.Tag) bool {
}
}

// HasNameTag returns a func that returns true if tag exists with tagKey
// HasTagKey returns a func that returns true if tag exists with tagKey
func HasTagKey(tagKey string) func([]*ec2.Tag) bool {
return func(tags []*ec2.Tag) bool {
for _, tag := range tags {
Expand Down

0 comments on commit d34ed52

Please sign in to comment.