Change the length of modelSortings array for panic of index error
If grade number of resourceModel less than rsName, the controller may panic with index error. The length of resource model grades array should equl the length of rsName array. Signed-off-by: NeilSun <sunbinnnnn@hotmail.com>
This commit is contained in:
parent
218a0b2400
commit
efb2ce0a67
|
@ -85,7 +85,7 @@ func InitSummary(resourceModels []clusterapis.ResourceModel) (ResourceSummary, e
|
|||
}
|
||||
rs = make(ResourceSummary, len(rsList))
|
||||
// generate a sorted array by first priority of ResourceName
|
||||
modelSortings = make([][]resource.Quantity, len(rsList))
|
||||
modelSortings = make([][]resource.Quantity, len(rsName))
|
||||
for index := 0; index < len(rsList); index++ {
|
||||
for i, name := range rsName {
|
||||
modelSortings[i] = append(modelSortings[i], rsList[index][name])
|
||||
|
|
|
@ -96,6 +96,35 @@ func TestInitSummaryError(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestInitSummaryWithOneGrade(t *testing.T) {
|
||||
rms := []clusterapis.ResourceModel{
|
||||
{
|
||||
Grade: 0,
|
||||
Ranges: []clusterapis.ResourceModelRange{
|
||||
{
|
||||
Name: clusterapis.ResourceCPU,
|
||||
Min: *resource.NewMilliQuantity(0, resource.DecimalSI),
|
||||
Max: *resource.NewQuantity(1, resource.DecimalSI),
|
||||
},
|
||||
{
|
||||
Name: clusterapis.ResourceMemory,
|
||||
Min: *resource.NewMilliQuantity(0, resource.DecimalSI),
|
||||
Max: *resource.NewQuantity(1024, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
rs, err := InitSummary(rms)
|
||||
if actualValue := len(rs); actualValue != 1 {
|
||||
t.Errorf("Got %v expected %v", actualValue, 1)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Got %v expected %v", err, nil)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSearchLastLessElement(t *testing.T) {
|
||||
nums, target := []resource.Quantity{
|
||||
*resource.NewMilliQuantity(1999, resource.DecimalSI),
|
||||
|
|
Loading…
Reference in New Issue