Skip to content

Commit

Permalink
a few fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bwagner5 committed Mar 9, 2022
1 parent d869be8 commit 4c5dc1a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
9 changes: 7 additions & 2 deletions pkg/cloudprovider/aws/launchtemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (p *LaunchTemplateProvider) Get(ctx context.Context, constraints *v1alpha1.
if err != nil {
return nil, err
}
resolvedLaunchTemplates := p.ltResolver.Resolve(constraints, instanceTypes, &ltresolver.Options{
resolvedLaunchTemplates, err := p.ltResolver.Resolve(ctx, constraints, instanceTypes, &ltresolver.Options{
ClusterName: injection.GetOptions(ctx).ClusterName,
ClusterEndpoint: injection.GetOptions(ctx).ClusterEndpoint,
AWSENILimitedPodDensity: injection.GetOptions(ctx).AWSENILimitedPodDensity,
Expand All @@ -108,7 +108,9 @@ func (p *LaunchTemplateProvider) Get(ctx context.Context, constraints *v1alpha1.
CABundle: p.caBundle,
KubernetesVersion: kubeServerVersion,
})

if err != nil {
return nil, err
}
launchTemplates := map[string][]cloudprovider.InstanceType{}
for _, resolvedLaunchTemplate := range resolvedLaunchTemplates {
// Ensure the launch template exists, or create it
Expand Down Expand Up @@ -223,6 +225,9 @@ func (p *LaunchTemplateProvider) hydrateCache(ctx context.Context) {
}

func (p *LaunchTemplateProvider) onCacheEvicted(key string, lt interface{}) {
if key == kubernetesVersionCacheKey {
return
}
p.Lock()
defer p.Unlock()
if _, expiration, _ := p.cache.GetWithExpiration(key); expiration.After(time.Now()) {
Expand Down
11 changes: 8 additions & 3 deletions pkg/cloudprovider/aws/ltresolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ limitations under the License.
package ltresolver

import (
"context"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/ssm/ssmiface"
Expand Down Expand Up @@ -83,11 +85,14 @@ func New(ssm ssmiface.SSMAPI, c *cache.Cache) *Resolver {

// Resolve generates launch templates using the static options and dynamically generates launch template parameters.
// Multiple ResolvedTemplates are returned based on the instanceTypes passed in to support special AMIs for certain instance types like GPUs.
func (r Resolver) Resolve(constraints *v1alpha1.Constraints, instanceTypes []cloudprovider.InstanceType, options *Options) []*ResolvedTemplate {
func (r Resolver) Resolve(ctx context.Context, constraints *v1alpha1.Constraints, instanceTypes []cloudprovider.InstanceType, options *Options) ([]*ResolvedTemplate, error) {
amiFamily := r.getAMIFamily(constraints.AMIFamily, options)
amiIDs := map[string][]cloudprovider.InstanceType{}
for _, instanceType := range instanceTypes {
amiID := amiFamily.SSMAlias(options.KubernetesVersion, instanceType)
amiID, err := r.amiProvider.Get(ctx, instanceType, amiFamily.SSMAlias(options.KubernetesVersion, instanceType))
if err != nil {
return nil, err
}
amiIDs[amiID] = append(amiIDs[amiID], instanceType)
}
var resolvedTemplates []*ResolvedTemplate
Expand All @@ -108,7 +113,7 @@ func (r Resolver) Resolve(constraints *v1alpha1.Constraints, instanceTypes []clo
}
resolvedTemplates = append(resolvedTemplates, resolved)
}
return resolvedTemplates
return resolvedTemplates, nil
}

func (r Resolver) getAMIFamily(amiFamily *string, options *Options) AMIFamily {
Expand Down

0 comments on commit 4c5dc1a

Please sign in to comment.