Skip to content

Commit

Permalink
Update AllocatableResourceGeneration (kubernetes-sigs#2984)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabesaba authored and kannon92 committed Nov 19, 2024
1 parent 99aaf27 commit 3db32cf
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 180 deletions.
40 changes: 20 additions & 20 deletions pkg/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
wantClusterQueues: map[string]*clusterQueue{
"a": {
Name: "a",
AllocatableResourceGeneration: 1,
AllocatableResourceGeneration: 2,
NamespaceSelector: labels.Nothing(),
FlavorFungibility: defaultFlavorFungibility,
Status: active,
Expand All @@ -126,7 +126,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
},
"c": {
Name: "c",
AllocatableResourceGeneration: 1,
AllocatableResourceGeneration: 3,
NamespaceSelector: labels.Nothing(),
FlavorFungibility: defaultFlavorFungibility,
Status: active,
Expand All @@ -144,7 +144,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
},
"e": {
Name: "e",
AllocatableResourceGeneration: 1,
AllocatableResourceGeneration: 2,
NamespaceSelector: labels.Nothing(),
FlavorFungibility: defaultFlavorFungibility,
Status: pending,
Expand Down Expand Up @@ -234,7 +234,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
wantClusterQueues: map[string]*clusterQueue{
"a": {
Name: "a",
AllocatableResourceGeneration: 1,
AllocatableResourceGeneration: 2,
FlavorFungibility: defaultFlavorFungibility,
NamespaceSelector: labels.Nothing(),
Status: active,
Expand All @@ -252,7 +252,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
},
"c": {
Name: "c",
AllocatableResourceGeneration: 1,
AllocatableResourceGeneration: 3,
NamespaceSelector: labels.Nothing(),
FlavorFungibility: defaultFlavorFungibility,
Status: active,
Expand All @@ -270,7 +270,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
},
"e": {
Name: "e",
AllocatableResourceGeneration: 1,
AllocatableResourceGeneration: 2,
NamespaceSelector: labels.Nothing(),
FlavorFungibility: defaultFlavorFungibility,
Status: pending,
Expand Down Expand Up @@ -335,7 +335,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
wantClusterQueues: map[string]*clusterQueue{
"a": {
Name: "a",
AllocatableResourceGeneration: 2,
AllocatableResourceGeneration: 4,
NamespaceSelector: labels.Nothing(),
FlavorFungibility: defaultFlavorFungibility,
Status: active,
Expand All @@ -344,7 +344,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
},
"b": {
Name: "b",
AllocatableResourceGeneration: 2,
AllocatableResourceGeneration: 3,
NamespaceSelector: labels.Everything(),
FlavorFungibility: defaultFlavorFungibility,
Status: active,
Expand All @@ -353,7 +353,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
},
"c": {
Name: "c",
AllocatableResourceGeneration: 1,
AllocatableResourceGeneration: 5,
NamespaceSelector: labels.Nothing(),
FlavorFungibility: defaultFlavorFungibility,
Status: active,
Expand All @@ -371,7 +371,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
},
"e": {
Name: "e",
AllocatableResourceGeneration: 2,
AllocatableResourceGeneration: 4,
NamespaceSelector: labels.Nothing(),
FlavorFungibility: defaultFlavorFungibility,
Status: active,
Expand All @@ -380,7 +380,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
},
"f": {
Name: "f",
AllocatableResourceGeneration: 1,
AllocatableResourceGeneration: 3,
NamespaceSelector: labels.Nothing(),
Status: active,
Preemption: defaultPreemption,
Expand Down Expand Up @@ -509,7 +509,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
wantClusterQueues: map[string]*clusterQueue{
"a": {
Name: "a",
AllocatableResourceGeneration: 2,
AllocatableResourceGeneration: 4,
FlavorFungibility: defaultFlavorFungibility,
Status: active,
Preemption: defaultPreemption,
Expand All @@ -518,7 +518,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
},
"b": {
Name: "b",
AllocatableResourceGeneration: 2,
AllocatableResourceGeneration: 3,
FlavorFungibility: defaultFlavorFungibility,
Status: active,
Preemption: defaultPreemption,
Expand All @@ -527,7 +527,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
},
"c": {
Name: "c",
AllocatableResourceGeneration: 2,
AllocatableResourceGeneration: 4,
FlavorFungibility: defaultFlavorFungibility,
Status: active,
Preemption: defaultPreemption,
Expand Down Expand Up @@ -567,7 +567,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
},
"c": {
Name: "c",
AllocatableResourceGeneration: 1,
AllocatableResourceGeneration: 3,
NamespaceSelector: labels.Nothing(),
FlavorFungibility: defaultFlavorFungibility,
Status: active,
Expand All @@ -576,7 +576,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
},
"e": {
Name: "e",
AllocatableResourceGeneration: 1,
AllocatableResourceGeneration: 2,
NamespaceSelector: labels.Nothing(),
FlavorFungibility: defaultFlavorFungibility,
Status: pending,
Expand Down Expand Up @@ -616,7 +616,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
wantClusterQueues: map[string]*clusterQueue{
"a": {
Name: "a",
AllocatableResourceGeneration: 1,
AllocatableResourceGeneration: 2,
NamespaceSelector: labels.Nothing(),
FlavorFungibility: defaultFlavorFungibility,
Status: active,
Expand All @@ -634,7 +634,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
},
"c": {
Name: "c",
AllocatableResourceGeneration: 1,
AllocatableResourceGeneration: 3,
NamespaceSelector: labels.Nothing(),
FlavorFungibility: defaultFlavorFungibility,
Status: active,
Expand All @@ -652,7 +652,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
},
"e": {
Name: "e",
AllocatableResourceGeneration: 1,
AllocatableResourceGeneration: 2,
NamespaceSelector: labels.Nothing(),
FlavorFungibility: defaultFlavorFungibility,
Status: active,
Expand Down Expand Up @@ -1089,7 +1089,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
NamespaceSelector: labels.Everything(),
Status: active,
Preemption: defaultPreemption,
AllocatableResourceGeneration: 1,
AllocatableResourceGeneration: 2,
FlavorFungibility: defaultFlavorFungibility,
FairWeight: oneQuantity,
},
Expand Down
1 change: 0 additions & 1 deletion pkg/cache/clusterqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ var defaultFlavorFungibility = kueue.FlavorFungibility{WhenCanBorrow: kueue.Borr

func (c *clusterQueue) updateClusterQueue(in *kueue.ClusterQueue, resourceFlavors map[kueue.ResourceFlavorReference]*kueue.ResourceFlavor, admissionChecks map[string]AdmissionCheck, oldParent *cohort) error {
if c.updateQuotasAndResourceGroups(in.Spec.ResourceGroups) || oldParent != c.Parent() {
c.AllocatableResourceGeneration += 1
if oldParent != nil && oldParent != c.Parent() {
updateCohortResourceNode(oldParent)
}
Expand Down
4 changes: 0 additions & 4 deletions pkg/cache/cohort_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ type CohortSnapshot struct {
Members sets.Set[*ClusterQueueSnapshot]

ResourceNode ResourceNode

// AllocatableResourceGeneration equals to
// the sum of allocatable generation among its members.
AllocatableResourceGeneration int64
}

// The methods below implement hierarchicalResourceNode interface.
Expand Down
1 change: 1 addition & 0 deletions pkg/cache/resource_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ func (r ResourceNode) calculateLendable() map[corev1.ResourceName]int64 {
}

func updateClusterQueueResourceNode(cq *clusterQueue) {
cq.AllocatableResourceGeneration += 1
cq.resourceNode.SubtreeQuota = make(resources.FlavorResourceQuantities, len(cq.resourceNode.Quotas))
for fr, quota := range cq.resourceNode.Quotas {
cq.resourceNode.SubtreeQuota[fr] = quota.Nominal
Expand Down
2 changes: 0 additions & 2 deletions pkg/cache/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,11 @@ func (c *cohort) snapshotInto(cqs map[string]*ClusterQueueSnapshot) {
Members: make(sets.Set[*ClusterQueueSnapshot], len(c.ChildCQs())),
ResourceNode: c.resourceNode.Clone(),
}
cohortSnap.AllocatableResourceGeneration = 0
for _, cq := range c.ChildCQs() {
if cq.Active() {
cqSnap := cqs[cq.Name]
cqSnap.Cohort = cohortSnap
cohortSnap.Members.Insert(cqSnap)
cohortSnap.AllocatableResourceGeneration += cqSnap.AllocatableResourceGeneration
}
}
}
Loading

0 comments on commit 3db32cf

Please sign in to comment.