Skip to content

Commit 6e1c46e

Browse files
authored
Autofill availability zones based on primary instance (#901)
1 parent 23eb519 commit 6e1c46e

File tree

2 files changed

+10
-23
lines changed

2 files changed

+10
-23
lines changed

pkg/types/clusterconfig/availability_zones.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,14 @@ import (
2424
var _azBlacklist = strset.New("us-east-1e")
2525

2626
func (cc *Config) validateAvailabilityZones(awsClient *aws.Client) error {
27-
var extraInstances []string
28-
if cc.Spot != nil && *cc.Spot && len(cc.SpotConfig.InstanceDistribution) >= 0 {
29-
for _, instanceType := range cc.SpotConfig.InstanceDistribution {
30-
if instanceType != *cc.InstanceType {
31-
extraInstances = append(extraInstances, instanceType)
32-
}
33-
}
34-
}
35-
3627
if len(cc.AvailabilityZones) == 0 {
37-
if err := cc.setDefaultAvailabilityZones(awsClient, extraInstances...); err != nil {
28+
if err := cc.setDefaultAvailabilityZones(awsClient); err != nil {
3829
return err
3930
}
4031
return nil
4132
}
4233

43-
if err := cc.validateUserAvailabilityZones(awsClient, extraInstances...); err != nil {
34+
if err := cc.validateUserAvailabilityZones(awsClient); err != nil {
4435
return err
4536
}
4637

pkg/types/clusterconfig/clusterconfig.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -497,24 +497,12 @@ func (cc *Config) Validate(awsClient *aws.Client) error {
497497
}
498498
}
499499

500-
// instance_distribution cleanup must be performed before availability_zone cleanup
501-
if cc.Spot != nil && *cc.Spot && len(cc.SpotConfig.InstanceDistribution) >= 0 {
502-
cleanedDistribution := []string{*cc.InstanceType}
503-
for _, instanceType := range cc.SpotConfig.InstanceDistribution {
504-
if instanceType != *cc.InstanceType {
505-
cleanedDistribution = append(cleanedDistribution, instanceType)
506-
}
507-
}
508-
cc.SpotConfig.InstanceDistribution = cleanedDistribution
509-
}
510-
511500
if err := cc.validateAvailabilityZones(awsClient); err != nil {
512501
return errors.Wrap(err, AvailabilityZonesKey)
513502
}
514503

515504
if cc.Spot != nil && *cc.Spot {
516505
cc.AutoFillSpot(awsClient)
517-
518506
chosenInstance := aws.InstanceMetadatas[*cc.Region][*cc.InstanceType]
519507
compatibleSpots := CompatibleSpotInstances(awsClient, chosenInstance, cc.SpotConfig.MaxPrice, _spotInstanceDistributionLength)
520508
if len(compatibleSpots) == 0 {
@@ -654,6 +642,14 @@ func CompatibleSpotInstances(awsClient *aws.Client, targetInstance aws.InstanceM
654642

655643
func AutoGenerateSpotConfig(awsClient *aws.Client, spotConfig *SpotConfig, region string, instanceType string) error {
656644
chosenInstance := aws.InstanceMetadatas[region][instanceType]
645+
cleanedDistribution := []string{instanceType}
646+
for _, spotInstance := range spotConfig.InstanceDistribution {
647+
if spotInstance != instanceType {
648+
cleanedDistribution = append(cleanedDistribution, spotInstance)
649+
}
650+
}
651+
spotConfig.InstanceDistribution = cleanedDistribution
652+
657653
if len(spotConfig.InstanceDistribution) == 1 {
658654
compatibleSpots := CompatibleSpotInstances(awsClient, chosenInstance, spotConfig.MaxPrice, _spotInstanceDistributionLength)
659655
if len(compatibleSpots) == 0 {

0 commit comments

Comments
 (0)