Skip to content

Commit

Permalink
[release-0.7] [fix] update assignedFlavorIdx at the beginning of loop (
Browse files Browse the repository at this point in the history
…#2440)

* update assignedFlavorIdx at the beginning of loop

Signed-off-by: KunWuLuan <kunwuluan@gmail.com>

* add unit tests

---------

Signed-off-by: KunWuLuan <kunwuluan@gmail.com>
Co-authored-by: KunWuLuan <kunwuluan@gmail.com>
  • Loading branch information
k8s-infra-cherrypick-robot and KunWuLuan authored Jun 19, 2024
1 parent 74284aa commit 8950342
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 61 deletions.
9 changes: 4 additions & 5 deletions pkg/scheduler/flavorassigner/flavorassigner.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,10 @@ func (a *FlavorAssigner) findFlavorForPodSetResource(

// We will only check against the flavors' labels for the resource.
selector := flavorSelector(podSpec, resourceGroup.LabelKeys)
assignedFlavorIdx := -1
attemptedFlavorIdx := -1
idx := a.wl.LastAssignment.NextFlavorToTryForPodSetResource(psID, resName)
for ; idx < len(resourceGroup.Flavors); idx++ {
attemptedFlavorIdx = idx
flvQuotas := resourceGroup.Flavors[idx]
flavor, exist := a.resourceFlavors[flvQuotas.Name]
if !exist {
Expand All @@ -426,8 +427,6 @@ func (a *FlavorAssigner) findFlavorForPodSetResource(
status.append(fmt.Sprintf("flavor %s doesn't match node affinity", flvQuotas.Name))
continue
}

assignedFlavorIdx = idx
needsBorrowing := false
assignments := make(ResourceAssignment, len(requests))
// Calculate representativeMode for this assignment as the worst mode among all requests.
Expand Down Expand Up @@ -477,11 +476,11 @@ func (a *FlavorAssigner) findFlavorForPodSetResource(

if features.Enabled(features.FlavorFungibility) {
for _, assignment := range bestAssignment {
if assignedFlavorIdx == len(resourceGroup.Flavors)-1 {
if attemptedFlavorIdx == len(resourceGroup.Flavors)-1 {
// we have reach the last flavor, try from the first flavor next time
assignment.TriedFlavorIdx = -1
} else {
assignment.TriedFlavorIdx = assignedFlavorIdx
assignment.TriedFlavorIdx = attemptedFlavorIdx
}
}
if bestAssignmentMode == Fit {
Expand Down
Loading

0 comments on commit 8950342

Please sign in to comment.