mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 07:20:13 +00:00
Validating against negative weights for priority functions
This commit is contained in:
parent
25724f7e31
commit
8deedf8e1f
@ -29,8 +29,8 @@ func ValidatePolicy(policy schedulerapi.Policy) error {
|
||||
validationErrors := make([]error, 0)
|
||||
|
||||
for _, priority := range policy.Priorities {
|
||||
if priority.Weight == 0 {
|
||||
validationErrors = append(validationErrors, fmt.Errorf("Priority %s should have a non-zero weight applied to it", priority.Name))
|
||||
if priority.Weight <= 0 {
|
||||
validationErrors = append(validationErrors, fmt.Errorf("Priority %s should have a positive weight applied to it", priority.Name))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,29 +25,28 @@ import (
|
||||
func TestValidatePriorityWithNoWeight(t *testing.T) {
|
||||
policy := api.Policy{Priorities: []api.PriorityPolicy{{Name: "NoWeightPriority"}}}
|
||||
if ValidatePolicy(policy) == nil {
|
||||
t.Errorf("Expected error about priority weight being zero")
|
||||
t.Errorf("Expected error about priority weight not being positive")
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidatePriorityWithZeroWeight(t *testing.T) {
|
||||
policy := api.Policy{Priorities: []api.PriorityPolicy{{Name: "NoWeightPriority", Weight: 0}}}
|
||||
if ValidatePolicy(policy) == nil {
|
||||
t.Errorf("Expected error about priority weight being zero")
|
||||
t.Errorf("Expected error about priority weight not being positive")
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidatePriorityWithNonZeroWeight(t *testing.T) {
|
||||
policy := api.Policy{Priorities: []api.PriorityPolicy{{Name: "WeightPriority", Weight: 2}}}
|
||||
errs := ValidatePolicy(policy)
|
||||
if ValidatePolicy(policy) != nil {
|
||||
if errs != nil {
|
||||
t.Errorf("Unexpected errors %v", errs)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidatePriorityWithNegativeWeight(t *testing.T) {
|
||||
policy := api.Policy{Priorities: []api.PriorityPolicy{{Name: "WeightPriority", Weight: -2}}}
|
||||
errs := ValidatePolicy(policy)
|
||||
if ValidatePolicy(policy) != nil {
|
||||
t.Errorf("Unexpected errors %v", errs)
|
||||
if ValidatePolicy(policy) == nil {
|
||||
t.Errorf("Expected error about priority weight not being positive")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user