fix RequestedToCapacityRatioParam's shape can be empty

Signed-off-by: kerthcet <kerthcet@gmail.com>
This commit is contained in:
kerthcet
2021-11-04 16:45:43 +08:00
parent 3b76c75831
commit 371eb83065
2 changed files with 23 additions and 10 deletions

View File

@@ -306,7 +306,7 @@ func ValidateNodeResourcesFitArgs(path *field.Path, args *config.NodeResourcesFi
if args.ScoringStrategy != nil {
allErrs = append(allErrs, validateResources(args.ScoringStrategy.Resources, path.Child("resources"))...)
if args.ScoringStrategy.RequestedToCapacityRatio != nil && len(args.ScoringStrategy.RequestedToCapacityRatio.Shape) > 0 {
if args.ScoringStrategy.RequestedToCapacityRatio != nil {
allErrs = append(allErrs, validateFunctionShape(args.ScoringStrategy.RequestedToCapacityRatio.Shape, path.Child("shape"))...)
}
}

View File

@@ -947,14 +947,31 @@ func TestValidateMostAllocatedScoringStrategy(t *testing.T) {
}
func TestValidateRequestedToCapacityRatioScoringStrategy(t *testing.T) {
defaultShape := []config.UtilizationShapePoint{
{
Utilization: 30,
Score: 3,
},
}
tests := []struct {
name string
resources []config.ResourceSpec
shapes []config.UtilizationShapePoint
wantErrs field.ErrorList
}{
{
name: "no shapes",
shapes: nil,
wantErrs: field.ErrorList{
{
Type: field.ErrorTypeRequired,
Field: "shape",
},
},
},
{
name: "weight greater than max",
shapes: defaultShape,
resources: []config.ResourceSpec{
{
Name: "cpu",
@@ -970,6 +987,7 @@ func TestValidateRequestedToCapacityRatioScoringStrategy(t *testing.T) {
},
{
name: "weight less than min",
shapes: defaultShape,
resources: []config.ResourceSpec{
{
Name: "cpu",
@@ -985,12 +1003,7 @@ func TestValidateRequestedToCapacityRatioScoringStrategy(t *testing.T) {
},
{
name: "valid shapes",
shapes: []config.UtilizationShapePoint{
{
Utilization: 30,
Score: 3,
},
},
shapes: defaultShape,
wantErrs: nil,
},
{