Skip to content

Commit

Permalink
fix sabakan integration to handle role that is not exist in sabakan
Browse files Browse the repository at this point in the history
  • Loading branch information
YZ775 committed Dec 13, 2024
1 parent af5b033 commit 34334e7
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion sabakan/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sabakan

import (
"errors"
"math"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -178,12 +179,25 @@ func (g *Generator) clearIntermediateData() {
g.countWorkerByRole = make(map[string]int)
}

func (g *Generator) countSabakanMachineByRole(role string) int {
count := 0
for _, m := range g.machineMap {
if m.Spec.Role == role {
count++
}
}
return count
}

func (g *Generator) chooseWorkerTmpl() nodeTemplate {
count := g.countWorkerByRole

least := float64(count[g.workerTmpls[0].Role]) / g.workerTmpls[0].Weight
least := math.MaxFloat64
leastIndex := 0
for i, tmpl := range g.workerTmpls {
if g.countSabakanMachineByRole(tmpl.Role) == 0 {
continue
}
w := float64(count[tmpl.Role]) / tmpl.Weight
if w < least {
least = w
Expand Down

0 comments on commit 34334e7

Please sign in to comment.