Change:
Weight is an int (see ). Priority can take the range 1-10. Total priority for a node is sum of weight  priority for each priority function, and the sum is accumulated into an int (see ). So obviously the total priority can overflow if someone sets the weight(s) too high. The weights of all priority functions are compiled in (or specified in config file), so we can check to make sure maximum total priority can't overflow an int (take sum over all priority functions of 10  weight of that priority function, and make sure that's smaller than int(MaxUint 1) which according to StackOverflow is the way to find out what is max int (math package has max Int32, Int64, etc. but not max Int). Note that scheduler extender is OK because although the policy runs in a separate process, the weight is specified in scheduler config file (ExtenderConfig struct) and the priority is bounded 1-10 as usual.
We really should also make "score" be an abstract datatype rather than a raw int that is manipulated directly, so we can do things like make sure it is in the range 1-10 (or 0-10 if that's what we want); today the range is inconistent (we say 1-10, but sometimes use 0; probably we should change it to 0-9..).
I volunteer myself to do this.
I think we can check weight overflow in after we get all PriorityConfig. what do you think about this?
As for "score" I think we can use
Fixed by - closing.
Tim that PR was closed, not merged. I don't think this is fixed yet.
whoops, good catch, just removing milestone then. There was a shift that happened yesterday where a bunch of items suddenly came into the 1.6 query.
do we still want this fixed? I can re-pick this.
AFAIK it's still broken. cc/
Ok, I will open a PR tomorrow.

Discussion:
"k8s.io/kubernetes/pkg/api/v1" ) <ins> const ( MaxUint          = ^uint(0) MaxInt           = int(MaxUint >> 1) MaxTotalPriority = MaxInt MaxPriority      = 10 MaxWeight        = MaxInt / MaxPriority ) </ins> type Policy struct { metav1.TypeMeta // Holds the information to configure the fit predicate functions

var validationErrors []error for _, priority := range policy.Priorities { <del> if priority.Weight <= 0 { validationErrors = append(validationErrors, fmt.Errorf("Priority %s should have a positive weight applied to it", priority.Name)) </del> <ins> if priority.Weight <= 0 || priority.Weight >= schedulerapi.MaxWeight { validationErrors = append(validationErrors, fmt.Errorf("Priority %s should have a positive weight applied to it or it has overflown", priority.Name)) </ins> } }

} } <ins> func TestValidatePriorityWithOverFlowWeight(t *testing.T) { policy := api.Policy{Priorities: []api.PriorityPolicy{{Name: "WeightPriority", Weight: api.MaxWeight}}} if ValidatePolicy(policy) == nil { t.Errorf("Expected error about priority weight not being overflown.") } } </ins> func TestValidateExtenderWithNonNegativeWeight(t *testing.T) { extenderPolicy := api.Policy{ExtenderConfigs: []api.ExtenderConfig{{URLPrefix: "http://127.0.0.1:8081/extender", FilterVerb: "filter", Weight: 2}}} errs := ValidatePolicy(extenderPolicy)

"strings" "sync" <ins> "github.com/golang/glog" </ins> "k8s.io/apimachinery/pkg/util/sets" "k8s.io/kubernetes/plugin/pkg/scheduler/algorithm" "k8s.io/kubernetes/plugin/pkg/scheduler/algorithm/predicates" "k8s.io/kubernetes/plugin/pkg/scheduler/algorithm/priorities" schedulerapi "k8s.io/kubernetes/plugin/pkg/scheduler/api" <del> "github.com/golang/glog" </del> ) // PluginFactoryArgs are passed to all plugin factory functions.

}) } } <ins> if err := validateSelectedConfigs(configs); err != nil { return nil, err } </ins> return configs, nil } <ins> // validateSelectedConfigs validates the config weights to avoid the overflow. func validateSelectedConfigs(configs []algorithm.PriorityConfig) error { var totalPriority int for _, config := range configs { // Checks totalPriority against MaxTotalPriority to avoid overflow if config.Weight*schedulerapi.MaxPriority > schedulerapi.MaxTotalPriority-totalPriority { return fmt.Errorf("Total priority of priority functions has overflown") } totalPriority += config.Weight * schedulerapi.MaxPriority } return nil } </ins> var validName = regexp.MustCompile("^[a-zA-Z0-9]([-a-zA-Z0-9]*[a-zA-Z0-9])$") func validateAlgorithmNameOrDie(name string) {

package factory <del> import "testing" </del> <ins> import ( "k8s.io/kubernetes/plugin/pkg/scheduler/algorithm" "k8s.io/kubernetes/plugin/pkg/scheduler/api" "testing" ) </ins> func TestAlgorithmNameValidation(t *testing.T) { algorithmNamesShouldValidate := []string{

} } } <ins> func TestValidatePriorityConfigOverFlow(t *testing.T) { tests := []struct { description string configs     []algorithm.PriorityConfig expected    bool }{ { description: "one of the weights is MaxInt", configs:     []algorithm.PriorityConfig{{Weight: api.MaxInt}, {Weight: 5}}, expected:    true, }, { description: "after multiplication with MaxPriority the weight is larger than MaxWeight", configs:     []algorithm.PriorityConfig{{Weight: api.MaxInt/api.MaxPriority + api.MaxPriority}, {Weight: 5}}, expected:    true, }, { description: "normal weights", configs:     []algorithm.PriorityConfig{{Weight: 10000}, {Weight: 5}}, expected:    false, }, } for _, test := range tests { err := validateSelectedConfigs(test.configs) if test.expected { if err == nil { t.Errorf("Expected Overflow for %s", test.description) } } else { if err != nil { t.Errorf("Did not expect an overflow for %s", test.description) } } } } </ins>