Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix sabakan integration to handle role that is not exist in sabakan #784

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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