diff --git a/pkg/scheduler/apis/config/validation/validation_pluginargs.go b/pkg/scheduler/apis/config/validation/validation_pluginargs.go index 56304b3e8f1..325a6bc6779 100644 --- a/pkg/scheduler/apis/config/validation/validation_pluginargs.go +++ b/pkg/scheduler/apis/config/validation/validation_pluginargs.go @@ -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"))...) } } diff --git a/pkg/scheduler/apis/config/validation/validation_pluginargs_test.go b/pkg/scheduler/apis/config/validation/validation_pluginargs_test.go index 33a41ec7b6f..fea6000f193 100644 --- a/pkg/scheduler/apis/config/validation/validation_pluginargs_test.go +++ b/pkg/scheduler/apis/config/validation/validation_pluginargs_test.go @@ -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", }, }, }, diff --git a/pkg/scheduler/framework/plugins/noderesources/least_allocated_test.go b/pkg/scheduler/framework/plugins/noderesources/least_allocated_test.go index 28443f392a6..4306b8f1841 100644 --- a/pkg/scheduler/framework/plugins/noderesources/least_allocated_test.go +++ b/pkg/scheduler/framework/plugins/noderesources/least_allocated_test.go @@ -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", }, }, }, diff --git a/pkg/scheduler/framework/plugins/noderesources/most_allocated_test.go b/pkg/scheduler/framework/plugins/noderesources/most_allocated_test.go index 7f7ace6105a..211c397a5f6 100644 --- a/pkg/scheduler/framework/plugins/noderesources/most_allocated_test.go +++ b/pkg/scheduler/framework/plugins/noderesources/most_allocated_test.go @@ -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", }, }, },