mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 23:37:01 +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)
|
validationErrors := make([]error, 0)
|
||||||
|
|
||||||
for _, priority := range policy.Priorities {
|
for _, priority := range policy.Priorities {
|
||||||
if priority.Weight == 0 {
|
if priority.Weight <= 0 {
|
||||||
validationErrors = append(validationErrors, fmt.Errorf("Priority %s should have a non-zero weight applied to it", priority.Name))
|
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) {
|
func TestValidatePriorityWithNoWeight(t *testing.T) {
|
||||||
policy := api.Policy{Priorities: []api.PriorityPolicy{{Name: "NoWeightPriority"}}}
|
policy := api.Policy{Priorities: []api.PriorityPolicy{{Name: "NoWeightPriority"}}}
|
||||||
if ValidatePolicy(policy) == nil {
|
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) {
|
func TestValidatePriorityWithZeroWeight(t *testing.T) {
|
||||||
policy := api.Policy{Priorities: []api.PriorityPolicy{{Name: "NoWeightPriority", Weight: 0}}}
|
policy := api.Policy{Priorities: []api.PriorityPolicy{{Name: "NoWeightPriority", Weight: 0}}}
|
||||||
if ValidatePolicy(policy) == nil {
|
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) {
|
func TestValidatePriorityWithNonZeroWeight(t *testing.T) {
|
||||||
policy := api.Policy{Priorities: []api.PriorityPolicy{{Name: "WeightPriority", Weight: 2}}}
|
policy := api.Policy{Priorities: []api.PriorityPolicy{{Name: "WeightPriority", Weight: 2}}}
|
||||||
errs := ValidatePolicy(policy)
|
errs := ValidatePolicy(policy)
|
||||||
if ValidatePolicy(policy) != nil {
|
if errs != nil {
|
||||||
t.Errorf("Unexpected errors %v", errs)
|
t.Errorf("Unexpected errors %v", errs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestValidatePriorityWithNegativeWeight(t *testing.T) {
|
func TestValidatePriorityWithNegativeWeight(t *testing.T) {
|
||||||
policy := api.Policy{Priorities: []api.PriorityPolicy{{Name: "WeightPriority", Weight: -2}}}
|
policy := api.Policy{Priorities: []api.PriorityPolicy{{Name: "WeightPriority", Weight: -2}}}
|
||||||
errs := ValidatePolicy(policy)
|
if ValidatePolicy(policy) == nil {
|
||||||
if ValidatePolicy(policy) != nil {
|
t.Errorf("Expected error about priority weight not being positive")
|
||||||
t.Errorf("Unexpected errors %v", errs)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user