From 6fd76dc13947c07f8d1c76b5c3fb54daa42d874c Mon Sep 17 00:00:00 2001 From: tanshanshan Date: Fri, 3 Feb 2017 10:01:03 +0800 Subject: [PATCH] fix --- hack/.linted_packages | 1 + plugin/pkg/scheduler/api/validation/validation.go | 4 ++-- .../scheduler/api/validation/validation_test.go | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/hack/.linted_packages b/hack/.linted_packages index cf4f5ea9be..e56b49f354 100644 --- a/hack/.linted_packages +++ b/hack/.linted_packages @@ -257,6 +257,7 @@ plugin/pkg/admission/securitycontext/scdeny plugin/pkg/auth plugin/pkg/auth/authorizer plugin/pkg/auth/authorizer/rbac/bootstrappolicy +plugin/pkg/scheduler/api/validation staging/src/k8s.io/apimachinery/pkg/api/equality staging/src/k8s.io/apimachinery/pkg/api/errors staging/src/k8s.io/apimachinery/pkg/api/resource diff --git a/plugin/pkg/scheduler/api/validation/validation.go b/plugin/pkg/scheduler/api/validation/validation.go index 74e58538fe..7f8f36c210 100644 --- a/plugin/pkg/scheduler/api/validation/validation.go +++ b/plugin/pkg/scheduler/api/validation/validation.go @@ -23,10 +23,10 @@ import ( schedulerapi "k8s.io/kubernetes/plugin/pkg/scheduler/api" ) -// Validate checks for errors in the Config +// ValidatePolicy checks for errors in the Config // It does not return early so that it can find as many errors as possible func ValidatePolicy(policy schedulerapi.Policy) error { - validationErrors := make([]error, 0) + var validationErrors []error for _, priority := range policy.Priorities { if priority.Weight <= 0 { diff --git a/plugin/pkg/scheduler/api/validation/validation_test.go b/plugin/pkg/scheduler/api/validation/validation_test.go index 6cc3da4e18..4ddd44aa25 100644 --- a/plugin/pkg/scheduler/api/validation/validation_test.go +++ b/plugin/pkg/scheduler/api/validation/validation_test.go @@ -50,3 +50,18 @@ func TestValidatePriorityWithNegativeWeight(t *testing.T) { t.Errorf("Expected error about priority weight not being positive") } } + +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) + if errs != nil { + t.Errorf("Unexpected errors %v", errs) + } +} + +func TestValidateExtenderWithNegativeWeight(t *testing.T) { + extenderPolicy := api.Policy{ExtenderConfigs: []api.ExtenderConfig{{URLPrefix: "http://127.0.0.1:8081/extender", FilterVerb: "filter", Weight: -2}}} + if ValidatePolicy(extenderPolicy) == nil { + t.Errorf("Expected error about priority weight for extender not being positive") + } +}