Skip to content

Commit e97a053

Browse files
committed
Hide unchanged spot config (#612)
* Hide unchanged spot config * Update clusterconfig.go * Update clusterconfig.go (cherry picked from commit 409fab4)
1 parent 7a6dc1c commit e97a053

File tree

2 files changed

+43
-24
lines changed

2 files changed

+43
-24
lines changed

cli/cmd/lib_cluster_config.go

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
cr "github.com/cortexlabs/cortex/pkg/lib/configreader"
2525
"github.com/cortexlabs/cortex/pkg/lib/errors"
2626
"github.com/cortexlabs/cortex/pkg/lib/prompt"
27+
"github.com/cortexlabs/cortex/pkg/lib/sets/strset"
2728
"github.com/cortexlabs/cortex/pkg/lib/slices"
2829
s "github.com/cortexlabs/cortex/pkg/lib/strings"
2930
"github.com/cortexlabs/cortex/pkg/lib/table"
@@ -169,11 +170,31 @@ func confirmClusterConfig(clusterConfig *clusterconfig.ClusterConfig, awsCreds *
169170

170171
if clusterConfig.Spot != nil && *clusterConfig.Spot != *defaultConfig.Spot {
171172
items = append(items, table.KV{K: clusterconfig.SpotUserFacingKey, V: s.YesNo(clusterConfig.Spot != nil && *clusterConfig.Spot)})
172-
items = append(items, table.KV{K: clusterconfig.InstanceDistributionUserFacingKey, V: clusterConfig.SpotConfig.InstanceDistribution})
173-
items = append(items, table.KV{K: clusterconfig.OnDemandBaseCapacityUserFacingKey, V: *clusterConfig.SpotConfig.OnDemandBaseCapacity})
174-
items = append(items, table.KV{K: clusterconfig.OnDemandPercentageAboveBaseCapacityUserFacingKey, V: *clusterConfig.SpotConfig.OnDemandPercentageAboveBaseCapacity})
175-
items = append(items, table.KV{K: clusterconfig.MaxPriceUserFacingKey, V: *clusterConfig.SpotConfig.MaxPrice})
176-
items = append(items, table.KV{K: clusterconfig.InstancePoolsUserFacingKey, V: *clusterConfig.SpotConfig.InstancePools})
173+
174+
if clusterConfig.SpotConfig != nil {
175+
defaultSpotConfig := clusterconfig.SpotConfig{}
176+
clusterconfig.AutoGenerateSpotConfig(&defaultSpotConfig, *clusterConfig.Region, *clusterConfig.InstanceType)
177+
178+
if !strset.New(clusterConfig.SpotConfig.InstanceDistribution...).IsEqual(strset.New(defaultSpotConfig.InstanceDistribution...)) {
179+
items = append(items, table.KV{K: clusterconfig.InstanceDistributionUserFacingKey, V: clusterConfig.SpotConfig.InstanceDistribution})
180+
}
181+
182+
if *clusterConfig.SpotConfig.OnDemandBaseCapacity != *defaultSpotConfig.OnDemandBaseCapacity {
183+
items = append(items, table.KV{K: clusterconfig.OnDemandBaseCapacityUserFacingKey, V: *clusterConfig.SpotConfig.OnDemandBaseCapacity})
184+
}
185+
186+
if *clusterConfig.SpotConfig.OnDemandPercentageAboveBaseCapacity != *defaultSpotConfig.OnDemandPercentageAboveBaseCapacity {
187+
items = append(items, table.KV{K: clusterconfig.OnDemandPercentageAboveBaseCapacityUserFacingKey, V: *clusterConfig.SpotConfig.OnDemandPercentageAboveBaseCapacity})
188+
}
189+
190+
if *clusterConfig.SpotConfig.MaxPrice != *defaultSpotConfig.MaxPrice {
191+
items = append(items, table.KV{K: clusterconfig.MaxPriceUserFacingKey, V: *clusterConfig.SpotConfig.MaxPrice})
192+
}
193+
194+
if *clusterConfig.SpotConfig.InstancePools != *defaultSpotConfig.InstancePools {
195+
items = append(items, table.KV{K: clusterconfig.InstancePoolsUserFacingKey, V: *clusterConfig.SpotConfig.InstancePools})
196+
}
197+
}
177198
}
178199
if clusterConfig.InstanceVolumeSize != defaultConfig.InstanceVolumeSize {
179200
items = append(items, table.KV{K: clusterconfig.InstanceVolumeSizeUserFacingKey, V: clusterConfig.InstanceVolumeSize})

pkg/lib/clusterconfig/clusterconfig.go

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/cortexlabs/cortex/pkg/lib/hash"
2828
"github.com/cortexlabs/cortex/pkg/lib/pointer"
2929
"github.com/cortexlabs/cortex/pkg/lib/prompt"
30+
"github.com/cortexlabs/cortex/pkg/lib/sets/strset"
3031
s "github.com/cortexlabs/cortex/pkg/lib/strings"
3132
"github.com/cortexlabs/cortex/pkg/lib/table"
3233
)
@@ -437,12 +438,8 @@ func CompatibleSpotInstances(targetInstance aws.InstanceMetadata) []aws.Instance
437438
return compatibleInstances
438439
}
439440

440-
func (cc *ClusterConfig) AutoFillSpot() error {
441-
spotConfig := cc.SpotConfig
442-
if spotConfig == nil {
443-
spotConfig = &SpotConfig{}
444-
}
445-
chosenInstance := aws.InstanceMetadatas[*cc.Region][*cc.InstanceType]
441+
func AutoGenerateSpotConfig(spotConfig *SpotConfig, region string, instanceType string) error {
442+
chosenInstance := aws.InstanceMetadatas[region][instanceType]
446443
if len(spotConfig.InstanceDistribution) == 0 {
447444
spotConfig.InstanceDistribution = append(spotConfig.InstanceDistribution, chosenInstance.Type)
448445

@@ -458,19 +455,10 @@ func (cc *ClusterConfig) AutoFillSpot() error {
458455
}
459456
}
460457
} else {
461-
found := false
462-
for _, instanceType := range spotConfig.InstanceDistribution {
463-
if *cc.InstanceType == instanceType {
464-
found = true
465-
break
466-
}
467-
}
468-
469-
if !found {
470-
spotConfig.InstanceDistribution = append(spotConfig.InstanceDistribution, chosenInstance.Type)
471-
}
458+
instanceDistributionSet := strset.New(spotConfig.InstanceDistribution...)
459+
instanceDistributionSet.Remove(instanceType)
460+
spotConfig.InstanceDistribution = append([]string{instanceType}, instanceDistributionSet.Slice()...)
472461
}
473-
474462
if spotConfig.MaxPrice == nil {
475463
spotConfig.MaxPrice = &chosenInstance.Price
476464
}
@@ -487,7 +475,17 @@ func (cc *ClusterConfig) AutoFillSpot() error {
487475
spotConfig.InstancePools = pointer.Int64(2)
488476
}
489477

490-
cc.SpotConfig = spotConfig
478+
return nil
479+
}
480+
481+
func (cc *ClusterConfig) AutoFillSpot() error {
482+
if cc.SpotConfig == nil {
483+
cc.SpotConfig = &SpotConfig{}
484+
}
485+
err := AutoGenerateSpotConfig(cc.SpotConfig, *cc.Region, *cc.InstanceType)
486+
if err != nil {
487+
return err
488+
}
491489
return nil
492490
}
493491

0 commit comments

Comments
 (0)