Skip to content

Commit

Permalink
Cleanup to use FlavorResourceQuantities.Add in cache (kubernetes-sigs…
Browse files Browse the repository at this point in the history
  • Loading branch information
gabesaba committed Aug 13, 2024
1 parent 0903547 commit b5a755e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 26 deletions.
11 changes: 3 additions & 8 deletions pkg/cache/clusterqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,10 @@ func (c *clusterQueue) update(in *kueue.ClusterQueue, resourceFlavors map[kueue.
for _, rg := range c.ResourceGroups {
for _, fName := range rg.Flavors {
for rName := range rg.CoveredResources {
rQuota := c.QuotaFor(resources.FlavorResource{Flavor: fName, Resource: rName})
fr := resources.FlavorResource{Flavor: fName, Resource: rName}
rQuota := c.QuotaFor(fr)
if rQuota.LendingLimit != nil {
if guaranteedQuota == nil {
guaranteedQuota = make(resources.FlavorResourceQuantities)
}
if guaranteedQuota[fName] == nil {
guaranteedQuota[fName] = make(map[corev1.ResourceName]int64)
}
guaranteedQuota[fName][rName] = rQuota.Nominal - *rQuota.LendingLimit
guaranteedQuota.Add(fr, rQuota.Nominal-*rQuota.LendingLimit)
}
}
}
Expand Down
23 changes: 5 additions & 18 deletions pkg/cache/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"maps"

"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/klog/v2"

Expand Down Expand Up @@ -168,34 +167,22 @@ func (c *ClusterQueueSnapshot) accumulateResources(cohort *CohortSnapshot) {
}
for _, rg := range c.ResourceGroups {
for _, fName := range rg.Flavors {
res := cohort.RequestableResources[fName]
if res == nil {
res = make(map[corev1.ResourceName]int64, len(rg.CoveredResources))
cohort.RequestableResources[fName] = res
}
for rName := range rg.CoveredResources {
rQuota := c.QuotaFor(resources.FlavorResource{Flavor: fName, Resource: rName})
fr := resources.FlavorResource{Flavor: fName, Resource: rName}
rQuota := c.QuotaFor(fr)
// When feature LendingLimit enabled, cohort.RequestableResources indicates
// the sum of cq.NominalQuota and other cqs' LendingLimit (if not nil).
// If LendingLimit is not nil, we should count the lendingLimit as the requestable
// resource because we can't borrow more quota than lendingLimit.
if features.Enabled(features.LendingLimit) && rQuota.LendingLimit != nil {
res[rName] += *rQuota.LendingLimit
cohort.RequestableResources.Add(fr, *rQuota.LendingLimit)
} else {
res[rName] += rQuota.Nominal
cohort.RequestableResources.Add(fr, rQuota.Nominal)
}
}
}
}
if cohort.Usage == nil {
cohort.Usage = make(resources.FlavorResourceQuantities, len(c.Usage))
}
for fName, resUsages := range c.Usage {
used := cohort.Usage[fName]
if used == nil {
used = make(map[corev1.ResourceName]int64, len(resUsages))
cohort.Usage[fName] = used
}
for res, val := range resUsages {
// Similar to cohort.RequestableResources, we accumulate the usage above the guaranteed resources,
// here we should remove the guaranteed quota as well for that part can not be borrowed.
Expand All @@ -204,7 +191,7 @@ func (c *ClusterQueueSnapshot) accumulateResources(cohort *CohortSnapshot) {
if val < 0 {
val = 0
}
used[res] += val
cohort.Usage.Add(resources.FlavorResource{Flavor: fName, Resource: res}, val)
}
}
}

0 comments on commit b5a755e

Please sign in to comment.