Skip to content
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
33 changes: 22 additions & 11 deletions pkg/cache/tas_flavor_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -775,27 +775,38 @@ func isSliceTopologyOnlyRequest(tr *kueue.PodSetTopologyRequest) bool {

// findBestFitDomain finds an index of the first domain with the lowest
// value of state, higher or equal than count.
// If such a domain doesn't exist, it returns 0 as it's an index of the domain with the
// If such a domain doesn't exist, it returns first domain as it's the domain with the
// most available resources
func findBestFitDomain(domains []*domain, count int32) *domain {
bestDomain := domains[0]
for _, domain := range domains {
if domain.state >= count && domain.state < bestDomain.state {
// choose the first occurrence of fitting domains
// to make it consecutive with other podSet's
bestDomain = domain
}
}
return bestDomain
return findBestFitDomainBy(domains, count, func(d *domain) int32 {
return d.state
})
}

// findBestFitDomainForSlices finds an index of the first domain with the lowest
// value of sliceState, higher or equal than sliceCount.
// If such a domain doesn't exist, it returns first domain as it's the domain with the
// most available resources
func findBestFitDomainForSlices(domains []*domain, sliceCount int32) *domain {
return findBestFitDomainBy(domains, sliceCount, func(d *domain) int32 {
return d.sliceState
})
}

type domainState func(d *domain) int32

func findBestFitDomainBy(domains []*domain, needed int32, state domainState) *domain {
bestDomain := domains[0]
bestDomainState := state(bestDomain)

for _, domain := range domains {
if domain.sliceState >= sliceCount && domain.sliceState < bestDomain.sliceState {
domainState := state(domain)

if domainState >= needed && domainState < bestDomainState {
// choose the first occurrence of fitting domains
// to make it consecutive with other podSet's
bestDomain = domain
bestDomainState = state(bestDomain)
}
}
return bestDomain
Expand Down