@@ -23,18 +23,16 @@ func AveragePlan(infos []Info, need, total, limit int) (map[string]int, error) {
23
23
return nil , errors .WithStack (types .NewDetailedErr (types .ErrInsufficientRes ,
24
24
fmt .Sprintf ("node len %d < limit, cannot alloc an average node plan" , scheduleInfosLength )))
25
25
}
26
- strategyInfos := make ([]Info , scheduleInfosLength )
27
- copy (strategyInfos , infos )
28
- sort .Slice (strategyInfos , func (i , j int ) bool { return strategyInfos [i ].Capacity > strategyInfos [j ].Capacity })
29
- p := sort .Search (scheduleInfosLength , func (i int ) bool { return strategyInfos [i ].Capacity < need })
26
+ sort .Slice (infos , func (i , j int ) bool { return infos [i ].Capacity > infos [j ].Capacity })
27
+ p := sort .Search (scheduleInfosLength , func (i int ) bool { return infos [i ].Capacity < need })
30
28
if p == 0 {
31
29
return nil , errors .WithStack (types .NewDetailedErr (types .ErrInsufficientCap , "insufficient nodes, at least 1 needed" ))
32
30
}
33
31
if p < limit {
34
32
return nil , types .NewDetailedErr (types .ErrInsufficientRes , fmt .Sprintf ("insufficient nodes, %d more needed" , limit - p ))
35
33
}
36
34
deployMap := map [string ]int {}
37
- for _ , strategyInfo := range strategyInfos [:limit ] {
35
+ for _ , strategyInfo := range infos [:limit ] {
38
36
deployMap [strategyInfo .Nodename ] += need
39
37
}
40
38
0 commit comments