diff --git a/pkg/types/clusterconfig/availability_zones.go b/pkg/types/clusterconfig/availability_zones.go index fa67259613..b1f2077ada 100644 --- a/pkg/types/clusterconfig/availability_zones.go +++ b/pkg/types/clusterconfig/availability_zones.go @@ -24,23 +24,14 @@ import ( var _azBlacklist = strset.New("us-east-1e") func (cc *Config) validateAvailabilityZones(awsClient *aws.Client) error { - var extraInstances []string - if cc.Spot != nil && *cc.Spot && len(cc.SpotConfig.InstanceDistribution) >= 0 { - for _, instanceType := range cc.SpotConfig.InstanceDistribution { - if instanceType != *cc.InstanceType { - extraInstances = append(extraInstances, instanceType) - } - } - } - if len(cc.AvailabilityZones) == 0 { - if err := cc.setDefaultAvailabilityZones(awsClient, extraInstances...); err != nil { + if err := cc.setDefaultAvailabilityZones(awsClient); err != nil { return err } return nil } - if err := cc.validateUserAvailabilityZones(awsClient, extraInstances...); err != nil { + if err := cc.validateUserAvailabilityZones(awsClient); err != nil { return err } diff --git a/pkg/types/clusterconfig/clusterconfig.go b/pkg/types/clusterconfig/clusterconfig.go index 21a6a19131..fa715a2a73 100644 --- a/pkg/types/clusterconfig/clusterconfig.go +++ b/pkg/types/clusterconfig/clusterconfig.go @@ -497,24 +497,12 @@ func (cc *Config) Validate(awsClient *aws.Client) error { } } - // instance_distribution cleanup must be performed before availability_zone cleanup - if cc.Spot != nil && *cc.Spot && len(cc.SpotConfig.InstanceDistribution) >= 0 { - cleanedDistribution := []string{*cc.InstanceType} - for _, instanceType := range cc.SpotConfig.InstanceDistribution { - if instanceType != *cc.InstanceType { - cleanedDistribution = append(cleanedDistribution, instanceType) - } - } - cc.SpotConfig.InstanceDistribution = cleanedDistribution - } - if err := cc.validateAvailabilityZones(awsClient); err != nil { return errors.Wrap(err, AvailabilityZonesKey) } if cc.Spot != nil && *cc.Spot { cc.AutoFillSpot(awsClient) - chosenInstance := aws.InstanceMetadatas[*cc.Region][*cc.InstanceType] compatibleSpots := CompatibleSpotInstances(awsClient, chosenInstance, cc.SpotConfig.MaxPrice, _spotInstanceDistributionLength) if len(compatibleSpots) == 0 { @@ -654,6 +642,14 @@ func CompatibleSpotInstances(awsClient *aws.Client, targetInstance aws.InstanceM func AutoGenerateSpotConfig(awsClient *aws.Client, spotConfig *SpotConfig, region string, instanceType string) error { chosenInstance := aws.InstanceMetadatas[region][instanceType] + cleanedDistribution := []string{instanceType} + for _, spotInstance := range spotConfig.InstanceDistribution { + if spotInstance != instanceType { + cleanedDistribution = append(cleanedDistribution, spotInstance) + } + } + spotConfig.InstanceDistribution = cleanedDistribution + if len(spotConfig.InstanceDistribution) == 1 { compatibleSpots := CompatibleSpotInstances(awsClient, chosenInstance, spotConfig.MaxPrice, _spotInstanceDistributionLength) if len(compatibleSpots) == 0 {