Add Extenders to scheduler v1alpha2 component config

This commit is contained in:
Mike Dame
2020-03-05 09:35:16 -05:00
parent 06b798781a
commit 1d7006c38d
14 changed files with 169 additions and 57 deletions

View File

@@ -71,6 +71,8 @@ func ValidateKubeSchedulerConfiguration(cc *config.KubeSchedulerConfiguration) f
allErrs = append(allErrs, field.Invalid(field.NewPath("podMaxBackoffSeconds"),
cc.PodMaxBackoffSeconds, "must be greater than or equal to PodInitialBackoffSeconds"))
}
allErrs = append(allErrs, validateExtenders(field.NewPath("extenders"), cc.Extenders)...)
return allErrs
}
@@ -123,28 +125,8 @@ func ValidatePolicy(policy config.Policy) error {
validationErrors = append(validationErrors, validateCustomPriorities(priorities, priority))
}
binders := 0
extenderManagedResources := sets.NewString()
for _, extender := range policy.Extenders {
if len(extender.PrioritizeVerb) > 0 && extender.Weight <= 0 {
validationErrors = append(validationErrors, fmt.Errorf("Priority for extender %s should have a positive weight applied to it", extender.URLPrefix))
}
if extender.BindVerb != "" {
binders++
}
for _, resource := range extender.ManagedResources {
errs := validateExtendedResourceName(v1.ResourceName(resource.Name))
if len(errs) != 0 {
validationErrors = append(validationErrors, errs...)
}
if extenderManagedResources.Has(resource.Name) {
validationErrors = append(validationErrors, fmt.Errorf("Duplicate extender managed resource name %s", string(resource.Name)))
}
extenderManagedResources.Insert(resource.Name)
}
}
if binders > 1 {
validationErrors = append(validationErrors, fmt.Errorf("Only one extender can implement bind, found %v", binders))
if extenderErrs := validateExtenders(field.NewPath("extenders"), policy.Extenders); len(extenderErrs) > 0 {
validationErrors = append(validationErrors, extenderErrs.ToAggregate().Errors()...)
}
if policy.HardPodAffinitySymmetricWeight < 0 || policy.HardPodAffinitySymmetricWeight > 100 {
@@ -153,6 +135,40 @@ func ValidatePolicy(policy config.Policy) error {
return utilerrors.NewAggregate(validationErrors)
}
// validateExtenders validates the configured extenders for the Scheduler
func validateExtenders(fldPath *field.Path, extenders []config.Extender) field.ErrorList {
allErrs := field.ErrorList{}
binders := 0
extenderManagedResources := sets.NewString()
for i, extender := range extenders {
path := fldPath.Index(i)
if len(extender.PrioritizeVerb) > 0 && extender.Weight <= 0 {
allErrs = append(allErrs, field.Invalid(path.Child("weight"),
extender.Weight, "must have a positive weight applied to it"))
}
if extender.BindVerb != "" {
binders++
}
for j, resource := range extender.ManagedResources {
managedResourcesPath := path.Child("managedResources").Index(j)
errs := validateExtendedResourceName(v1.ResourceName(resource.Name))
for _, err := range errs {
allErrs = append(allErrs, field.Invalid(managedResourcesPath.Child("name"),
resource.Name, fmt.Sprintf("%+v", err)))
}
if extenderManagedResources.Has(resource.Name) {
allErrs = append(allErrs, field.Invalid(managedResourcesPath.Child("name"),
resource.Name, "duplicate extender managed resource name"))
}
extenderManagedResources.Insert(resource.Name)
}
}
if binders > 1 {
allErrs = append(allErrs, field.Invalid(fldPath, fmt.Sprintf("found %d extenders implementing bind", binders), "only one extender can implement bind"))
}
return allErrs
}
// validateCustomPriorities validates that:
// 1. RequestedToCapacityRatioRedeclared custom priority cannot be declared multiple times,
// 2. LabelPreference/ServiceAntiAffinity custom priorities can be declared multiple times,