mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-13 11:25:19 +00:00
optimise defaultpreemption: enumerate fewer candidates
Signed-off-by: Adhityaa Chandrasekar <adtac@google.com>
This commit is contained in:
@@ -26,6 +26,38 @@ import (
|
||||
"k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||
)
|
||||
|
||||
// ValidateDefaultPreemptionArgs validates that DefaultPreemptionArgs are correct.
|
||||
func ValidateDefaultPreemptionArgs(args config.DefaultPreemptionArgs) error {
|
||||
if err := validateMinCandidateNodesPercentage(args.MinCandidateNodesPercentage); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateMinCandidateNodesAbsolute(args.MinCandidateNodesAbsolute); err != nil {
|
||||
return err
|
||||
}
|
||||
if args.MinCandidateNodesPercentage == 0 && args.MinCandidateNodesAbsolute == 0 {
|
||||
return fmt.Errorf("both minCandidateNodesPercentage and minCandidateNodesAbsolute cannot be zero")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// validateMinCandidateNodesPercentage validates that
|
||||
// minCandidateNodesPercentage is within the allowed range.
|
||||
func validateMinCandidateNodesPercentage(minCandidateNodesPercentage int32) error {
|
||||
if minCandidateNodesPercentage < 0 || minCandidateNodesPercentage > 100 {
|
||||
return fmt.Errorf("minCandidateNodesPercentage is not in the range [0, 100]")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// validateMinCandidateNodesAbsolute validates that minCandidateNodesAbsolute
|
||||
// is within the allowed range.
|
||||
func validateMinCandidateNodesAbsolute(minCandidateNodesAbsolute int32) error {
|
||||
if minCandidateNodesAbsolute < 0 {
|
||||
return fmt.Errorf("minCandidateNodesAbsolute is not in the range [0, inf)")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ValidateInterPodAffinityArgs validates that InterPodAffinityArgs are correct.
|
||||
func ValidateInterPodAffinityArgs(args config.InterPodAffinityArgs) error {
|
||||
return ValidateHardPodAffinityWeight(field.NewPath("hardPodAffinityWeight"), args.HardPodAffinityWeight)
|
||||
|
||||
@@ -24,6 +24,55 @@ import (
|
||||
"k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||
)
|
||||
|
||||
func TestValidateDefaultPreemptionArgs(t *testing.T) {
|
||||
cases := map[string]struct {
|
||||
args config.DefaultPreemptionArgs
|
||||
wantErr string
|
||||
}{
|
||||
"valid args (default)": {
|
||||
args: config.DefaultPreemptionArgs{
|
||||
MinCandidateNodesPercentage: 10,
|
||||
MinCandidateNodesAbsolute: 100,
|
||||
},
|
||||
},
|
||||
"negative minCandidateNodesPercentage": {
|
||||
args: config.DefaultPreemptionArgs{
|
||||
MinCandidateNodesPercentage: -1,
|
||||
MinCandidateNodesAbsolute: 100,
|
||||
},
|
||||
wantErr: "minCandidateNodesPercentage is not in the range [0, 100]",
|
||||
},
|
||||
"minCandidateNodesPercentage over 100": {
|
||||
args: config.DefaultPreemptionArgs{
|
||||
MinCandidateNodesPercentage: 900,
|
||||
MinCandidateNodesAbsolute: 100,
|
||||
},
|
||||
wantErr: "minCandidateNodesPercentage is not in the range [0, 100]",
|
||||
},
|
||||
"negative minCandidateNodesAbsolute": {
|
||||
args: config.DefaultPreemptionArgs{
|
||||
MinCandidateNodesPercentage: 20,
|
||||
MinCandidateNodesAbsolute: -1,
|
||||
},
|
||||
wantErr: "minCandidateNodesAbsolute is not in the range [0, inf)",
|
||||
},
|
||||
"all zero": {
|
||||
args: config.DefaultPreemptionArgs{
|
||||
MinCandidateNodesPercentage: 0,
|
||||
MinCandidateNodesAbsolute: 0,
|
||||
},
|
||||
wantErr: "both minCandidateNodesPercentage and minCandidateNodesAbsolute cannot be zero",
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range cases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
err := ValidateDefaultPreemptionArgs(tc.args)
|
||||
assertErr(t, tc.wantErr, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateInterPodAffinityArgs(t *testing.T) {
|
||||
cases := map[string]struct {
|
||||
args config.InterPodAffinityArgs
|
||||
|
||||
Reference in New Issue
Block a user