Skip to content

Commit

Permalink
Allow absent Weight if PrioritizeVerb is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
yguo0905 committed Oct 19, 2017
1 parent f07b359 commit 1c60898
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion plugin/pkg/scheduler/api/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func ValidatePolicy(policy schedulerapi.Policy) error {

binders := 0
for _, extender := range policy.ExtenderConfigs {
if extender.Weight <= 0 {
if len(extender.PrioritizeVerb) > 0 && extender.Weight <= 0 {
validationErrors = append(validationErrors, fmt.Errorf("Priority for extender %s should have a positive weight applied to it", extender.URLPrefix))
}
if extender.BindVerb != "" {
Expand Down
12 changes: 8 additions & 4 deletions plugin/pkg/scheduler/api/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,22 @@ func TestValidatePolicy(t *testing.T) {
expected: errors.New("Priority WeightPriority should have a positive weight applied to it or it has overflown"),
},
{
policy: api.Policy{ExtenderConfigs: []api.ExtenderConfig{{URLPrefix: "http://127.0.0.1:8081/extender", FilterVerb: "filter", Weight: 2}}},
policy: api.Policy{ExtenderConfigs: []api.ExtenderConfig{{URLPrefix: "http://127.0.0.1:8081/extender", PrioritizeVerb: "prioritize", Weight: 2}}},
expected: nil,
},
{
policy: api.Policy{ExtenderConfigs: []api.ExtenderConfig{{URLPrefix: "http://127.0.0.1:8081/extender", FilterVerb: "filter", Weight: -2}}},
policy: api.Policy{ExtenderConfigs: []api.ExtenderConfig{{URLPrefix: "http://127.0.0.1:8081/extender", PrioritizeVerb: "prioritize", Weight: -2}}},
expected: errors.New("Priority for extender http://127.0.0.1:8081/extender should have a positive weight applied to it"),
},
{
policy: api.Policy{ExtenderConfigs: []api.ExtenderConfig{{URLPrefix: "http://127.0.0.1:8081/extender", FilterVerb: "filter"}}},
expected: nil,
},
{
policy: api.Policy{
ExtenderConfigs: []api.ExtenderConfig{
{URLPrefix: "http://127.0.0.1:8081/extender", BindVerb: "bind", Weight: 2},
{URLPrefix: "http://127.0.0.1:8082/extender", BindVerb: "bind", Weight: 2},
{URLPrefix: "http://127.0.0.1:8081/extender", BindVerb: "bind"},
{URLPrefix: "http://127.0.0.1:8082/extender", BindVerb: "bind"},
}},
expected: errors.New("Only one extender can implement bind, found 2"),
},
Expand Down

0 comments on commit 1c60898

Please sign in to comment.