Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions pkg/provider/aws/data/spot.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var placementScores = []placementScoreSpec{
// While calculating the spot price and the types of machines
// to be requested we use the first n number of types per Az
// to control how many types will be used this var is used
var numberOfTypesForSpot = 8
var maxNumberOfTypesForSpot = 8

func minPlacementScore(spotTolerance spot.Tolerance) int32 {
idx := slices.IndexFunc(placementScores,
Expand Down Expand Up @@ -199,11 +199,16 @@ func SpotInfo(mCtx *mc.Context, args *SpotInfoArgs) (*spot.SpotResults, error) {
if err != nil {
return nil, err
}
numberOfTypesForSpot := util.If(
len(args.InstaceTypes) < maxNumberOfTypesForSpot,
len(args.InstaceTypes),
maxNumberOfTypesForSpot)
c, err := selectSpotChoice(
&spotChoiceArgs{
placementScores: placementScores,
spotPricing: spotPricing,
})
},
numberOfTypesForSpot)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -239,7 +244,7 @@ type spotChoiceArgs struct {
// # Also function take cares to transfrom from AzID to AZName
//
// first option matching the requirements will be returned
func selectSpotChoice(args *spotChoiceArgs) (*SpotInfoResult, error) {
func selectSpotChoice(args *spotChoiceArgs, numberOfTypesForSpot int) (*SpotInfoResult, error) {
result := make(map[string]*SpotInfoResult)
// This can bexecuted async
for r, pss := range args.spotPricing {
Expand All @@ -260,7 +265,7 @@ func selectSpotChoice(args *spotChoiceArgs) (*SpotInfoResult, error) {
})
}
if len(resultByAZ[ps.AvailabilityZone]) == numberOfTypesForSpot {
result[r] = aggregateSpotChoice(resultByAZ[ps.AvailabilityZone])
result[r] = aggregateSpotChoice(resultByAZ[ps.AvailabilityZone], numberOfTypesForSpot)
break
}
}
Expand All @@ -277,7 +282,7 @@ func selectSpotChoice(args *spotChoiceArgs) (*SpotInfoResult, error) {
}

// previously we pick 3 values per Az we aggregate its data
func aggregateSpotChoice(s []*SpotInfoResult) *SpotInfoResult {
func aggregateSpotChoice(s []*SpotInfoResult, numberOfTypesForSpot int) *SpotInfoResult {
return &SpotInfoResult{
Region: s[0].Region,
AvailabilityZone: s[0].AvailabilityZone,
Expand Down