1
0
mirror of https://github.com/kubernetes-sigs/descheduler.git synced 2026-01-26 13:29:11 +01:00

removepodsviolatingtopologyspreadconstraint: implement explicit constraints

This commit is contained in:
Amir Alavi
2023-06-03 18:58:18 -04:00
parent 5f0edb5f93
commit 7f2f6f2b16
14 changed files with 254 additions and 27 deletions

View File

@@ -19,23 +19,37 @@ package removepodsviolatingtopologyspreadconstraint
import (
"fmt"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/sets"
)
// ValidateRemovePodsViolatingTopologySpreadConstraintArgs validates RemovePodsViolatingTopologySpreadConstraint arguments
func ValidateRemovePodsViolatingTopologySpreadConstraintArgs(obj runtime.Object) error {
var errs []error
args := obj.(*RemovePodsViolatingTopologySpreadConstraintArgs)
// At most one of include/exclude can be set
if args.Namespaces != nil && len(args.Namespaces.Include) > 0 && len(args.Namespaces.Exclude) > 0 {
return fmt.Errorf("only one of Include/Exclude namespaces can be set")
errs = append(errs, fmt.Errorf("only one of Include/Exclude namespaces can be set"))
}
if args.LabelSelector != nil {
if _, err := metav1.LabelSelectorAsSelector(args.LabelSelector); err != nil {
return fmt.Errorf("failed to get label selectors from strategy's params: %+v", err)
errs = append(errs, fmt.Errorf("failed to get label selectors from strategy's params: %+v", err))
}
}
return nil
if len(args.Constraints) > 0 {
supportedConstraints := sets.New(v1.DoNotSchedule, v1.ScheduleAnyway)
for _, constraint := range args.Constraints {
if !supportedConstraints.Has(constraint) {
errs = append(errs, fmt.Errorf("constraint %s is not one of %v", constraint, supportedConstraints))
}
}
}
return errors.NewAggregate(errs)
}