X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/5836e576fe0b78c50383cf56e1c4fb4521daeca1..73ad2ee9af3b97c46293bdfc9e2925a67726b786:/lib/dispatchcloud/node_size.go diff --git a/lib/dispatchcloud/node_size.go b/lib/dispatchcloud/node_size.go index f145901c32..b5fd0262a8 100644 --- a/lib/dispatchcloud/node_size.go +++ b/lib/dispatchcloud/node_size.go @@ -8,6 +8,7 @@ import ( "errors" "log" "os/exec" + "sort" "strings" "time" @@ -15,11 +16,17 @@ import ( ) var ( - ErrConstraintsNotSatisfiable = errors.New("constraints not satisfiable by any configured instance type") ErrInstanceTypesNotConfigured = errors.New("site configuration does not list any instance types") discountConfiguredRAMPercent = 5 ) +// ConstraintsNotSatisfiableError includes a list of available instance types +// to be reported back to the user. +type ConstraintsNotSatisfiableError struct { + error + AvailableTypes []arvados.InstanceType +} + // ChooseInstanceType returns the cheapest available // arvados.InstanceType big enough to run ctr. func ChooseInstanceType(cc *arvados.Cluster, ctr *arvados.Container) (best arvados.InstanceType, err error) { @@ -40,7 +47,15 @@ func ChooseInstanceType(cc *arvados.Cluster, ctr *arvados.Container) (best arvad needRAM := ctr.RuntimeConstraints.RAM + ctr.RuntimeConstraints.KeepCacheRAM needRAM = (needRAM * 100) / int64(100-discountConfiguredRAMPercent) - err = ErrConstraintsNotSatisfiable + availableTypes := make([]arvados.InstanceType, len(cc.InstanceTypes)) + copy(availableTypes, cc.InstanceTypes) + sort.Slice(availableTypes, func(a, b int) bool { + return availableTypes[a].Price < availableTypes[b].Price + }) + err = ConstraintsNotSatisfiableError{ + errors.New("constraints not satisfiable by any configured instance type"), + availableTypes, + } for _, it := range cc.InstanceTypes { switch { case err == nil && it.Price > best.Price: