mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-07 03:03:59 +00:00
Add Scheduler validation check for redeclared plugin configs
This commit is contained in:
parent
cd274ff270
commit
5296650c1c
@ -34,10 +34,18 @@ import (
|
|||||||
func ValidatePolicy(policy schedulerapi.Policy) error {
|
func ValidatePolicy(policy schedulerapi.Policy) error {
|
||||||
var validationErrors []error
|
var validationErrors []error
|
||||||
|
|
||||||
|
priorities := make(map[string]schedulerapi.PriorityPolicy, len(policy.Priorities))
|
||||||
for _, priority := range policy.Priorities {
|
for _, priority := range policy.Priorities {
|
||||||
if priority.Weight <= 0 || priority.Weight >= framework.MaxWeight {
|
if priority.Weight <= 0 || priority.Weight >= framework.MaxWeight {
|
||||||
validationErrors = append(validationErrors, fmt.Errorf("Priority %s should have a positive weight applied to it or it has overflown", priority.Name))
|
validationErrors = append(validationErrors, fmt.Errorf("Priority %s should have a positive weight applied to it or it has overflown", priority.Name))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
validationErrors = append(validationErrors, validatePriorityRedeclared(priorities, priority))
|
||||||
|
}
|
||||||
|
|
||||||
|
predicates := make(map[string]schedulerapi.PredicatePolicy, len(policy.Predicates))
|
||||||
|
for _, predicate := range policy.Predicates {
|
||||||
|
validationErrors = append(validationErrors, validatePredicateRedeclared(predicates, predicate))
|
||||||
}
|
}
|
||||||
|
|
||||||
binders := 0
|
binders := 0
|
||||||
@ -66,6 +74,48 @@ func ValidatePolicy(policy schedulerapi.Policy) error {
|
|||||||
return utilerrors.NewAggregate(validationErrors)
|
return utilerrors.NewAggregate(validationErrors)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// validatePriorityRedeclared checks if any custom priorities have been declared multiple times in the policy config
|
||||||
|
// by examining the specified priority arguments
|
||||||
|
func validatePriorityRedeclared(priorities map[string]schedulerapi.PriorityPolicy, priority schedulerapi.PriorityPolicy) error {
|
||||||
|
var priorityType string
|
||||||
|
if priority.Argument != nil {
|
||||||
|
if priority.Argument.LabelPreference != nil {
|
||||||
|
priorityType = "LabelPreference"
|
||||||
|
} else if priority.Argument.RequestedToCapacityRatioArguments != nil {
|
||||||
|
priorityType = "RequestedToCapacityRatioArguments"
|
||||||
|
} else if priority.Argument.ServiceAntiAffinity != nil {
|
||||||
|
priorityType = "ServiceAntiAffinity"
|
||||||
|
} else {
|
||||||
|
return fmt.Errorf("No priority arguments set for priority %s", priority.Name)
|
||||||
|
}
|
||||||
|
if existing, alreadyDeclared := priorities[priorityType]; alreadyDeclared {
|
||||||
|
return fmt.Errorf("Priority %s is redeclared (was %+v)", priority.Name, existing)
|
||||||
|
}
|
||||||
|
priorities[priorityType] = priority
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// validatePredicateRedeclared checks if any custom predicates have been declared multiple times in the policy config
|
||||||
|
// by examining the specified predicate arguments
|
||||||
|
func validatePredicateRedeclared(predicates map[string]schedulerapi.PredicatePolicy, predicate schedulerapi.PredicatePolicy) error {
|
||||||
|
var predicateType string
|
||||||
|
if predicate.Argument != nil {
|
||||||
|
if predicate.Argument.LabelsPresence != nil {
|
||||||
|
predicateType = "LabelsPresence"
|
||||||
|
} else if predicate.Argument.ServiceAffinity != nil {
|
||||||
|
predicateType = "ServiceAffinity"
|
||||||
|
} else {
|
||||||
|
return fmt.Errorf("No priority arguments set for priority %s", predicate.Name)
|
||||||
|
}
|
||||||
|
if existing, alreadyDeclared := predicates[predicateType]; alreadyDeclared {
|
||||||
|
return fmt.Errorf("Priority %s is redeclared (was %+v)", predicate.Name, existing)
|
||||||
|
}
|
||||||
|
predicates[predicateType] = predicate
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// validateExtendedResourceName checks whether the specified name is a valid
|
// validateExtendedResourceName checks whether the specified name is a valid
|
||||||
// extended resource name.
|
// extended resource name.
|
||||||
func validateExtendedResourceName(name v1.ResourceName) []error {
|
func validateExtendedResourceName(name v1.ResourceName) []error {
|
||||||
|
Loading…
Reference in New Issue
Block a user