Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
rifelpet committed Jun 9, 2020
1 parent 807cbcb commit 95b6a3f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/releases/1.19-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Significant changes

* Clusters using the Amazon VPC CNI provider now perform an `ec2.DescribeInstanceTypes` call at instance launch time. In large clusters or AWS accounts this may lead to API throttling which could delay node readiness. If this becomes a problem please open a GitHub issue.
* Clusters using the Amazon VPC CNI provider now perform an `ec2.DescribeInstanceTypes` call at instance launch time. In large clusters or AWS accounts this may lead to API throttling which could delay node readiness. If this becomes a problem please open a GitHub issue.

# Breaking changes

Expand Down
15 changes: 6 additions & 9 deletions pkg/apis/kops/validation/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ func awsValidateInstanceGroup(ig *kops.InstanceGroup, cloud awsup.AWSCloud) fiel

allErrs = append(allErrs, awsValidateAdditionalSecurityGroups(field.NewPath("spec", "additionalSecurityGroups"), ig.Spec.AdditionalSecurityGroups)...)

if cloud != nil {
allErrs = append(allErrs, awsValidateInstanceType(field.NewPath(ig.GetName(), "spec", "machineType"), ig.Spec.MachineType, cloud)...)
}
allErrs = append(allErrs, awsValidateInstanceType(field.NewPath(ig.GetName(), "spec", "machineType"), ig.Spec.MachineType, cloud)...)

allErrs = append(allErrs, awsValidateSpotDurationInMinute(field.NewPath(ig.GetName(), "spec", "spotDurationInMinutes"), ig)...)

Expand Down Expand Up @@ -82,7 +80,7 @@ func awsValidateAdditionalSecurityGroups(fieldPath *field.Path, groups []string)

func awsValidateInstanceType(fieldPath *field.Path, instanceType string, cloud awsup.AWSCloud) field.ErrorList {
allErrs := field.ErrorList{}
if instanceType != "" {
if instanceType != "" && cloud != nil {
for _, typ := range strings.Split(instanceType, ",") {
if _, err := cloud.DescribeInstanceType(typ); err != nil {
allErrs = append(allErrs, field.Invalid(fieldPath, typ, "machine type specified is invalid"))
Expand Down Expand Up @@ -117,12 +115,11 @@ func awsValidateInstanceInterruptionBehavior(fieldPath *field.Path, ig *kops.Ins
func awsValidateMixedInstancesPolicy(path *field.Path, spec *kops.MixedInstancesPolicySpec, ig *kops.InstanceGroup, cloud awsup.AWSCloud) field.ErrorList {
var errs field.ErrorList

// @step: check the instances are validate
if cloud != nil {
for i, x := range spec.Instances {
errs = append(errs, awsValidateInstanceType(path.Child("instances").Index(i).Child("instanceType"), x, cloud)...)
}
// @step: check the instance types are valid
for i, x := range spec.Instances {
errs = append(errs, awsValidateInstanceType(path.Child("instances").Index(i), x, cloud)...)
}

if spec.OnDemandBase != nil {
if fi.Int64Value(spec.OnDemandBase) < 0 {
errs = append(errs, field.Invalid(path.Child("onDemandBase"), spec.OnDemandBase, "cannot be less than zero"))
Expand Down
6 changes: 5 additions & 1 deletion upup/pkg/fi/cloudup/awsup/aws_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ type awsCloudImplementation struct {

regionDelayers *RegionDelayers

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

type RegionDelayers struct {
Expand Down Expand Up @@ -1549,6 +1550,9 @@ func (c *awsCloudImplementation) DescribeInstanceType(instanceType string) (*ec2
if info, ok := c.instanceTypes[instanceType]; ok {
return info, nil
}
c.instanceTypesMutex.Lock()
defer c.instanceTypesMutex.Unlock()

info, err := describeInstanceType(c, instanceType)
if err != nil {
return nil, err
Expand Down

0 comments on commit 95b6a3f

Please sign in to comment.