From 1c60898bf5fc41c6a28af44cbb2ee7827a9e9393 Mon Sep 17 00:00:00 2001 From: Yang Guo Date: Thu, 19 Oct 2017 14:07:59 -0700 Subject: [PATCH] Allow absent Weight if PrioritizeVerb is empty --- plugin/pkg/scheduler/api/validation/validation.go | 2 +- .../pkg/scheduler/api/validation/validation_test.go | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/plugin/pkg/scheduler/api/validation/validation.go b/plugin/pkg/scheduler/api/validation/validation.go index 620a0343ed7..cec33b1955b 100644 --- a/plugin/pkg/scheduler/api/validation/validation.go +++ b/plugin/pkg/scheduler/api/validation/validation.go @@ -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 != "" { diff --git a/plugin/pkg/scheduler/api/validation/validation_test.go b/plugin/pkg/scheduler/api/validation/validation_test.go index b7a6cd2ca9a..b0b01a8573b 100644 --- a/plugin/pkg/scheduler/api/validation/validation_test.go +++ b/plugin/pkg/scheduler/api/validation/validation_test.go @@ -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"), },