in projects/gke-optimization/binpacker/api/pkg/domain/service/binpacking/binpacking.go [177:215]
func findRecommendationsByCPU(maxLimit node.CPU, cpuRequests []node.CPU, minNumNodes int) ([]Recommendation, error) {
var totalCPURequest node.CPU
for _, v := range cpuRequests {
totalCPURequest += v
}
requiredCPU := totalCPURequest
if maxLimit > totalCPURequest {
requiredCPU = maxLimit
}
recommendationMap := make(map[int]node.CPU, 0)
for cpu := node.CPU(node.MinCPUPerNode); cpu <= node.MinRequiredCPU(requiredCPU); cpu += node.CPUUnit {
// Memory size is not used at this moment
nodes, err := node.NewNodesByCPU(cpu, minNumNodes)
if err != nil {
return nil, err
}
if !nodes.SchedulableCPU(maxLimit) {
continue
}
// FirstFitDecreasingByCPU returns error if the biggest request is not schedulable
numNodes, err := nodes.FirstFitDecreasingByCPU(cpuRequests)
if err != nil {
continue
}
// Only put smallest one
if _, exists := recommendationMap[numNodes]; exists {
continue
}
recommendationMap[numNodes] = cpu
}
recommendations := make([]Recommendation, 0)
for numNodes, cpu := range recommendationMap {
recommendations = append(recommendations, Recommendation{CPU: cpu, MemoryInGiB: 0, NumNodes: numNodes})
}
return recommendations, nil
}