Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 1 addition & 6 deletions pkg/scheduler/flavorassigner/flavorassigner.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,6 @@ const (
fit
)

func preferToAvoidBorrowing(fungiblityConfig kueue.FlavorFungibility) bool {
return (fungiblityConfig.WhenCanBorrow == kueue.TryNextFlavor && fungiblityConfig.WhenCanPreempt == kueue.Preempt) ||
(fungiblityConfig.WhenCanBorrow == kueue.TryNextFlavor && fungiblityConfig.WhenCanPreempt == kueue.TryNextFlavor)
}

// isPreferred returns true if mode a is better than b according to the selected policy
func isPreferred(a, b granularMode, fungiblityConfig kueue.FlavorFungibility) bool {
if a.preemptionMode == noFit {
Expand All @@ -349,7 +344,7 @@ func isPreferred(a, b granularMode, fungiblityConfig kueue.FlavorFungibility) bo
}
}

if preferToAvoidBorrowing(fungiblityConfig) {
if fungiblityConfig.WhenCanBorrow == kueue.TryNextFlavor {
if a.needsBorrowing != b.needsBorrowing {
return !a.needsBorrowing
}
Expand Down
21 changes: 11 additions & 10 deletions pkg/scheduler/preemption/preemption_oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,19 @@ func (p *PreemptionOracle) SimulatePreemption(log logr.Logger, cq *cache.Cluster
workloadUsage: workload.Usage{Quota: resources.FlavorResourceQuantities{fr: quantity}},
})

if len(candidates) > 0 {
workloadsToPreempt := make([]*workload.Info, len(candidates))
for i, c := range candidates {
workloadsToPreempt[i] = c.WorkloadInfo
}
revertRemoval := cq.SimulateWorkloadRemoval(workloadsToPreempt)
defer revertRemoval()
}
borrowAfterPreemptions, _ := classical.FindHeightOfLowestSubtreeThatFits(cq, fr, quantity)
if len(candidates) == 0 {
return preemptioncommon.NoCandidates, borrowAfterPreemptions
borrow, _ := classical.FindHeightOfLowestSubtreeThatFits(cq, fr, quantity)
return preemptioncommon.NoCandidates, borrow
Copy link
Copy Markdown
Contributor Author

@pajakd pajakd Jul 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It actually matters what value of borrow we return with NoCandidates because it is later used to order entries in scheduling.

There are tests that were failing whenever I was trying to return some fixed value to this actually has to be correctly calculated. For that reason I can't think of any new testcase needed for this.

For example the new unit tests for capacity blocking (capacity blocked when lending clusterqueue not guaranteed to reclaim (ReclaimWithinCohort=Never)).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thank you for checking that we had unit tests already.

I like unit tests to be our first line of defense whenever possible (especially for scheduling), cause they are much easier to debug than integration or e2e.

}

workloadsToPreempt := make([]*workload.Info, len(candidates))
for i, c := range candidates {
workloadsToPreempt[i] = c.WorkloadInfo
}
revertRemoval := cq.SimulateWorkloadRemoval(workloadsToPreempt)
borrowAfterPreemptions, _ := classical.FindHeightOfLowestSubtreeThatFits(cq, fr, quantity)
revertRemoval()

for _, candidate := range candidates {
if candidate.WorkloadInfo.ClusterQueue == cq.Name {
return preemptioncommon.Preempt, borrowAfterPreemptions
Expand Down