Skip to content

Commit ddb8f9b

Browse files
committed
fix: Setting spot using compute sizes failed if len was less than 8
Previously there was a fixed value to 8 on spot calculations, now if computeSizes are pass as param and the number of sizes is less than 8 it will use the len of compute sizes. This means now we will be able to use any number of compute sizes. Fix #622 Signed-off-by: Adrian Riobo <[email protected]>
1 parent 48a16aa commit ddb8f9b

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

pkg/provider/aws/data/spot.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ var placementScores = []placementScoreSpec{
5454
// While calculating the spot price and the types of machines
5555
// to be requested we use the first n number of types per Az
5656
// to control how many types will be used this var is used
57-
var numberOfTypesForSpot = 8
57+
var maxNumberOfTypesForSpot = 8
5858

5959
func minPlacementScore(spotTolerance spot.Tolerance) int32 {
6060
idx := slices.IndexFunc(placementScores,
@@ -199,11 +199,16 @@ func SpotInfo(mCtx *mc.Context, args *SpotInfoArgs) (*spot.SpotResults, error) {
199199
if err != nil {
200200
return nil, err
201201
}
202+
numberOfTypesForSpot := util.If(
203+
len(args.InstaceTypes) < maxNumberOfTypesForSpot,
204+
len(args.InstaceTypes),
205+
maxNumberOfTypesForSpot)
202206
c, err := selectSpotChoice(
203207
&spotChoiceArgs{
204208
placementScores: placementScores,
205209
spotPricing: spotPricing,
206-
})
210+
},
211+
numberOfTypesForSpot)
207212
if err != nil {
208213
return nil, err
209214
}
@@ -239,7 +244,7 @@ type spotChoiceArgs struct {
239244
// # Also function take cares to transfrom from AzID to AZName
240245
//
241246
// first option matching the requirements will be returned
242-
func selectSpotChoice(args *spotChoiceArgs) (*SpotInfoResult, error) {
247+
func selectSpotChoice(args *spotChoiceArgs, numberOfTypesForSpot int) (*SpotInfoResult, error) {
243248
result := make(map[string]*SpotInfoResult)
244249
// This can bexecuted async
245250
for r, pss := range args.spotPricing {
@@ -260,7 +265,7 @@ func selectSpotChoice(args *spotChoiceArgs) (*SpotInfoResult, error) {
260265
})
261266
}
262267
if len(resultByAZ[ps.AvailabilityZone]) == numberOfTypesForSpot {
263-
result[r] = aggregateSpotChoice(resultByAZ[ps.AvailabilityZone])
268+
result[r] = aggregateSpotChoice(resultByAZ[ps.AvailabilityZone], numberOfTypesForSpot)
264269
break
265270
}
266271
}
@@ -277,7 +282,7 @@ func selectSpotChoice(args *spotChoiceArgs) (*SpotInfoResult, error) {
277282
}
278283

279284
// previously we pick 3 values per Az we aggregate its data
280-
func aggregateSpotChoice(s []*SpotInfoResult) *SpotInfoResult {
285+
func aggregateSpotChoice(s []*SpotInfoResult, numberOfTypesForSpot int) *SpotInfoResult {
281286
return &SpotInfoResult{
282287
Region: s[0].Region,
283288
AvailabilityZone: s[0].AvailabilityZone,

0 commit comments

Comments
 (0)