Skip to content

Commit

Permalink
chore: When sorting the prices of instance types, prioritize newer g…
Browse files Browse the repository at this point in the history
…eneration

    instances over older when the are the same price

    chore: When comparing the cost of spot instances account on-demand instances,
    take into account a 28% compute savings plan discount
  • Loading branch information
craiglink committed Apr 11, 2024
1 parent e7e58c6 commit ce4658b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pkg/providers/instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,9 @@ func orderInstanceTypesByPrice(instanceTypes []*cloudprovider.InstanceType, requ
jPrice = instanceTypes[j].Offerings.Available().Requirements(requirements).Cheapest().Price
}
if iPrice == jPrice {
return instanceTypes[i].Name < instanceTypes[j].Name
// sort newer generation instance types before old when the price is the same
// e.g. c6i.large ( $0.085 ) before c5.large ( $0.085 )
return instanceTypes[i].Name > instanceTypes[j].Name
}
return iPrice < jPrice
})
Expand Down Expand Up @@ -473,7 +475,12 @@ func filterUnwantedSpot(instanceTypes []*cloudprovider.InstanceType) []*cloudpro
if len(available) == 0 {
return false
}
return available.Cheapest().Price <= cheapestOnDemand
cheapest := available.Cheapest()
if cheapest.CapacityType == v1alpha5.CapacityTypeOnDemand {
return cheapest.Price <= cheapestOnDemand
}
// if spot, compare to 28% Savings Plan discount
return cheapest.Price <= cheapestOnDemand * 0.72
})
return instanceTypes
}
Expand Down

0 comments on commit ce4658b

Please sign in to comment.