Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve code coverage for scheduler/api/validation #40404

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions hack/.linted_packages
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions plugin/pkg/scheduler/api/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validationErrors := make([]error, 0)
var validationErrors []error

for _, priority := range policy.Priorities {
if priority.Weight <= 0 {
Expand Down
15 changes: 15 additions & 0 deletions plugin/pkg/scheduler/api/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}