Skip to content

Commit 6fd76dc

Browse files
author
tanshanshan
committed
fix
1 parent 3ce4934 commit 6fd76dc

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

hack/.linted_packages

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ plugin/pkg/admission/securitycontext/scdeny
257257
plugin/pkg/auth
258258
plugin/pkg/auth/authorizer
259259
plugin/pkg/auth/authorizer/rbac/bootstrappolicy
260+
plugin/pkg/scheduler/api/validation
260261
staging/src/k8s.io/apimachinery/pkg/api/equality
261262
staging/src/k8s.io/apimachinery/pkg/api/errors
262263
staging/src/k8s.io/apimachinery/pkg/api/resource

plugin/pkg/scheduler/api/validation/validation.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ import (
2323
schedulerapi "k8s.io/kubernetes/plugin/pkg/scheduler/api"
2424
)
2525

26-
// Validate checks for errors in the Config
26+
// ValidatePolicy checks for errors in the Config
2727
// It does not return early so that it can find as many errors as possible
2828
func ValidatePolicy(policy schedulerapi.Policy) error {
29-
validationErrors := make([]error, 0)
29+
var validationErrors []error
3030

3131
for _, priority := range policy.Priorities {
3232
if priority.Weight <= 0 {

plugin/pkg/scheduler/api/validation/validation_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,18 @@ func TestValidatePriorityWithNegativeWeight(t *testing.T) {
5050
t.Errorf("Expected error about priority weight not being positive")
5151
}
5252
}
53+
54+
func TestValidateExtenderWithNonNegativeWeight(t *testing.T) {
55+
extenderPolicy := api.Policy{ExtenderConfigs: []api.ExtenderConfig{{URLPrefix: "http://127.0.0.1:8081/extender", FilterVerb: "filter", Weight: 2}}}
56+
errs := ValidatePolicy(extenderPolicy)
57+
if errs != nil {
58+
t.Errorf("Unexpected errors %v", errs)
59+
}
60+
}
61+
62+
func TestValidateExtenderWithNegativeWeight(t *testing.T) {
63+
extenderPolicy := api.Policy{ExtenderConfigs: []api.ExtenderConfig{{URLPrefix: "http://127.0.0.1:8081/extender", FilterVerb: "filter", Weight: -2}}}
64+
if ValidatePolicy(extenderPolicy) == nil {
65+
t.Errorf("Expected error about priority weight for extender not being positive")
66+
}
67+
}

0 commit comments

Comments
 (0)