Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rifelpet committed Jun 9, 2020
1 parent 95b6a3f commit d923354
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions pkg/apis/kops/validation/instancegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ func ValidateInstanceGroup(g *kops.InstanceGroup, cloud fi.Cloud) field.ErrorLis
allErrs = append(allErrs, validateRollingUpdate(g.Spec.RollingUpdate, field.NewPath("spec", "rollingUpdate"), g.Spec.Role == kops.InstanceGroupRoleMaster)...)
}

if awsCloud, ok := cloud.(awsup.AWSCloud); ok {
allErrs = append(allErrs, awsValidateInstanceGroup(g, awsCloud)...)
if cloud != nil && cloud.ProviderID() == kops.CloudProviderAWS {
allErrs = append(allErrs, awsValidateInstanceGroup(g, cloud.(awsup.AWSCloud))...)
}

return allErrs
Expand Down
20 changes: 13 additions & 7 deletions upup/pkg/fi/cloudup/awsup/aws_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,19 @@ type awsCloudImplementation struct {

regionDelayers *RegionDelayers

instanceTypes map[string]*ec2.InstanceTypeInfo
instanceTypesMutex sync.Mutex
instanceTypes *instanceTypes
}

type RegionDelayers struct {
mutex sync.Mutex
delayerMap map[string]*k8s_aws.CrossRequestRetryDelay
}

type instanceTypes struct {
mutex sync.Mutex
typeMap map[string]*ec2.InstanceTypeInfo
}

var _ fi.Cloud = &awsCloudImplementation{}

func (c *awsCloudImplementation) ProviderID() kops.CloudProviderID {
Expand All @@ -207,6 +211,9 @@ func NewAWSCloud(region string, tags map[string]string) (AWSCloud, error) {
regionDelayers: &RegionDelayers{
delayerMap: make(map[string]*k8s_aws.CrossRequestRetryDelay),
},
instanceTypes: &instanceTypes{
typeMap: make(map[string]*ec2.InstanceTypeInfo),
},
}

config := aws.NewConfig().WithRegion(region)
Expand Down Expand Up @@ -288,7 +295,6 @@ func NewAWSCloud(region string, tags map[string]string) (AWSCloud, error) {
return c, err
}
}
c.instanceTypes = make(map[string]*ec2.InstanceTypeInfo)

awsCloudInstances[region] = c
raw = c
Expand Down Expand Up @@ -1547,17 +1553,17 @@ func (c *awsCloudImplementation) zonesWithInstanceType(instanceType string) (set

// DescribeInstanceType calls ec2.DescribeInstanceType to get information for a particular instance type
func (c *awsCloudImplementation) DescribeInstanceType(instanceType string) (*ec2.InstanceTypeInfo, error) {
if info, ok := c.instanceTypes[instanceType]; ok {
if info, ok := c.instanceTypes.typeMap[instanceType]; ok {
return info, nil
}
c.instanceTypesMutex.Lock()
defer c.instanceTypesMutex.Unlock()
c.instanceTypes.mutex.Lock()
defer c.instanceTypes.mutex.Unlock()

info, err := describeInstanceType(c, instanceType)
if err != nil {
return nil, err
}
c.instanceTypes[instanceType] = info
c.instanceTypes.typeMap[instanceType] = info
return info, nil
}

Expand Down

0 comments on commit d923354

Please sign in to comment.