Merge pull request #111206 from SataQiu/scheduler-20220718

scheduler: include supported ScoringStrategyType list in error message for NodeResourcesFit plugin
This commit is contained in:
Kubernetes Prow Robot 2022-07-30 01:40:29 -07:00 committed by GitHub
commit 2ae27c89ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 25 deletions

View File

@ -31,6 +31,12 @@ import (
"k8s.io/kubernetes/pkg/scheduler/apis/config"
)
var supportedScoringStrategyTypes = sets.NewString(
string(config.LeastAllocated),
string(config.MostAllocated),
string(config.RequestedToCapacityRatio),
)
// ValidateDefaultPreemptionArgs validates that DefaultPreemptionArgs are correct.
func ValidateDefaultPreemptionArgs(path *field.Path, args *config.DefaultPreemptionArgs) error {
var allErrs field.ErrorList
@ -304,10 +310,14 @@ func ValidateNodeResourcesFitArgs(path *field.Path, args *config.NodeResourcesFi
}
}
strategyPath := path.Child("scoringStrategy")
if args.ScoringStrategy != nil {
allErrs = append(allErrs, validateResources(args.ScoringStrategy.Resources, path.Child("resources"))...)
if !supportedScoringStrategyTypes.Has(string(args.ScoringStrategy.Type)) {
allErrs = append(allErrs, field.NotSupported(strategyPath.Child("type"), args.ScoringStrategy.Type, supportedScoringStrategyTypes.List()))
}
allErrs = append(allErrs, validateResources(args.ScoringStrategy.Resources, strategyPath.Child("resources"))...)
if args.ScoringStrategy.RequestedToCapacityRatio != nil {
allErrs = append(allErrs, validateFunctionShape(args.ScoringStrategy.RequestedToCapacityRatio.Shape, path.Child("shape"))...)
allErrs = append(allErrs, validateFunctionShape(args.ScoringStrategy.RequestedToCapacityRatio.Shape, strategyPath.Child("shape"))...)
}
}

View File

@ -745,6 +745,15 @@ func TestValidateFitArgs(t *testing.T) {
args: config.NodeResourcesFitArgs{},
expect: "ScoringStrategy field is required",
},
{
name: "ScoringStrategy: type is unsupported",
args: config.NodeResourcesFitArgs{
ScoringStrategy: &config.ScoringStrategy{
Type: "Invalid",
},
},
expect: `Unsupported value: "Invalid"`,
},
}
for _, test := range argsTest {
@ -791,7 +800,7 @@ func TestValidateLeastAllocatedScoringStrategy(t *testing.T) {
wantErrs: field.ErrorList{
{
Type: field.ErrorTypeInvalid,
Field: "resources[0].weight",
Field: "scoringStrategy.resources[0].weight",
},
},
},
@ -806,7 +815,7 @@ func TestValidateLeastAllocatedScoringStrategy(t *testing.T) {
wantErrs: field.ErrorList{
{
Type: field.ErrorTypeInvalid,
Field: "resources[0].weight",
Field: "scoringStrategy.resources[0].weight",
},
},
},
@ -825,11 +834,11 @@ func TestValidateLeastAllocatedScoringStrategy(t *testing.T) {
wantErrs: field.ErrorList{
{
Type: field.ErrorTypeInvalid,
Field: "resources[0].weight",
Field: "scoringStrategy.resources[0].weight",
},
{
Type: field.ErrorTypeInvalid,
Field: "resources[1].weight",
Field: "scoringStrategy.resources[1].weight",
},
},
},
@ -886,7 +895,7 @@ func TestValidateMostAllocatedScoringStrategy(t *testing.T) {
wantErrs: field.ErrorList{
{
Type: field.ErrorTypeInvalid,
Field: "resources[0].weight",
Field: "scoringStrategy.resources[0].weight",
},
},
},
@ -901,7 +910,7 @@ func TestValidateMostAllocatedScoringStrategy(t *testing.T) {
wantErrs: field.ErrorList{
{
Type: field.ErrorTypeInvalid,
Field: "resources[0].weight",
Field: "scoringStrategy.resources[0].weight",
},
},
},
@ -920,11 +929,11 @@ func TestValidateMostAllocatedScoringStrategy(t *testing.T) {
wantErrs: field.ErrorList{
{
Type: field.ErrorTypeInvalid,
Field: "resources[0].weight",
Field: "scoringStrategy.resources[0].weight",
},
{
Type: field.ErrorTypeInvalid,
Field: "resources[1].weight",
Field: "scoringStrategy.resources[1].weight",
},
},
},
@ -965,7 +974,7 @@ func TestValidateRequestedToCapacityRatioScoringStrategy(t *testing.T) {
wantErrs: field.ErrorList{
{
Type: field.ErrorTypeRequired,
Field: "shape",
Field: "scoringStrategy.shape",
},
},
},
@ -981,7 +990,7 @@ func TestValidateRequestedToCapacityRatioScoringStrategy(t *testing.T) {
wantErrs: field.ErrorList{
{
Type: field.ErrorTypeInvalid,
Field: "resources[0].weight",
Field: "scoringStrategy.resources[0].weight",
},
},
},
@ -997,7 +1006,7 @@ func TestValidateRequestedToCapacityRatioScoringStrategy(t *testing.T) {
wantErrs: field.ErrorList{
{
Type: field.ErrorTypeInvalid,
Field: "resources[0].weight",
Field: "scoringStrategy.resources[0].weight",
},
},
},
@ -1017,7 +1026,7 @@ func TestValidateRequestedToCapacityRatioScoringStrategy(t *testing.T) {
wantErrs: field.ErrorList{
{
Type: field.ErrorTypeInvalid,
Field: "shape[0].utilization",
Field: "scoringStrategy.shape[0].utilization",
},
},
},
@ -1032,7 +1041,7 @@ func TestValidateRequestedToCapacityRatioScoringStrategy(t *testing.T) {
wantErrs: field.ErrorList{
{
Type: field.ErrorTypeInvalid,
Field: "shape[0].utilization",
Field: "scoringStrategy.shape[0].utilization",
},
},
},
@ -1051,7 +1060,7 @@ func TestValidateRequestedToCapacityRatioScoringStrategy(t *testing.T) {
wantErrs: field.ErrorList{
{
Type: field.ErrorTypeInvalid,
Field: "shape[1].utilization",
Field: "scoringStrategy.shape[1].utilization",
},
},
},
@ -1092,7 +1101,7 @@ func TestValidateRequestedToCapacityRatioScoringStrategy(t *testing.T) {
wantErrs: field.ErrorList{
{
Type: field.ErrorTypeInvalid,
Field: "shape[2].utilization",
Field: "scoringStrategy.shape[2].utilization",
},
},
},
@ -1107,7 +1116,7 @@ func TestValidateRequestedToCapacityRatioScoringStrategy(t *testing.T) {
wantErrs: field.ErrorList{
{
Type: field.ErrorTypeInvalid,
Field: "shape[0].score",
Field: "scoringStrategy.shape[0].score",
},
},
},
@ -1122,7 +1131,7 @@ func TestValidateRequestedToCapacityRatioScoringStrategy(t *testing.T) {
wantErrs: field.ErrorList{
{
Type: field.ErrorTypeInvalid,
Field: "shape[0].score",
Field: "scoringStrategy.shape[0].score",
},
},
},

View File

@ -283,7 +283,7 @@ func TestLeastAllocatedScoringStrategy(t *testing.T) {
wantErrs: field.ErrorList{
&field.Error{
Type: field.ErrorTypeInvalid,
Field: "resources[0].weight",
Field: "scoringStrategy.resources[0].weight",
},
},
},
@ -306,7 +306,7 @@ func TestLeastAllocatedScoringStrategy(t *testing.T) {
wantErrs: field.ErrorList{
&field.Error{
Type: field.ErrorTypeInvalid,
Field: "resources[1].weight",
Field: "scoringStrategy.resources[1].weight",
},
},
},
@ -327,7 +327,7 @@ func TestLeastAllocatedScoringStrategy(t *testing.T) {
wantErrs: field.ErrorList{
&field.Error{
Type: field.ErrorTypeInvalid,
Field: "resources[1].weight",
Field: "scoringStrategy.resources[1].weight",
},
},
},

View File

@ -241,7 +241,7 @@ func TestMostAllocatedScoringStrategy(t *testing.T) {
wantErrs: field.ErrorList{
&field.Error{
Type: field.ErrorTypeInvalid,
Field: "resources[0].weight",
Field: "scoringStrategy.resources[0].weight",
},
},
},
@ -262,7 +262,7 @@ func TestMostAllocatedScoringStrategy(t *testing.T) {
wantErrs: field.ErrorList{
&field.Error{
Type: field.ErrorTypeInvalid,
Field: "resources[1].weight",
Field: "scoringStrategy.resources[1].weight",
},
},
},
@ -282,7 +282,7 @@ func TestMostAllocatedScoringStrategy(t *testing.T) {
wantErrs: field.ErrorList{
&field.Error{
Type: field.ErrorTypeInvalid,
Field: "resources[0].weight",
Field: "scoringStrategy.resources[0].weight",
},
},
},