Skip to content

Commit 1be9e66

Browse files
authored
Merge pull request #275 from kerthcet/automated-cherry-pick-of-#248-upstream-release-0.1
Automated cherry pick of #248: fix: forget to cleanup inadmissibleWorkloads when
2 parents 3b6f8df + ddfc1c5 commit 1be9e66

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

CHANGELOG/CHANGELOG-0.1.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ Changes since `v0.1.0`:
66
- Fixed bug in a BestEffortFIFO ClusterQueue where a workload might not be
77
retried after a transient error.
88
- Fixed requeuing an out-of-date workload when failed to admit it.
9+
- Fixed bug in a BestEffortFIFO ClusterQueue where unadmissible workloads
10+
were not removed from the ClusterQueue when removing the corresponding Queue.

pkg/queue/cluster_queue_best_effort_fifo.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ func (cq *ClusterQueueBestEffortFIFO) Delete(w *kueue.Workload) {
7575
cq.ClusterQueueImpl.Delete(w)
7676
}
7777

78+
func (cq *ClusterQueueBestEffortFIFO) DeleteFromQueue(q *Queue) {
79+
for _, w := range q.items {
80+
key := workload.Key(w.Obj)
81+
if wl := cq.inadmissibleWorkloads[key]; wl != nil {
82+
delete(cq.inadmissibleWorkloads, key)
83+
}
84+
}
85+
cq.ClusterQueueImpl.DeleteFromQueue(q)
86+
}
87+
7888
// RequeueIfNotPresent inserts a workload that cannot be admitted into
7989
// ClusterQueue, unless it is already in the queue. If immediate is true,
8090
// the workload will be pushed back to heap directly. If not,

pkg/queue/cluster_queue_best_effort_fifo_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,43 @@ func TestClusterQueueBestEffortFIFO(t *testing.T) {
136136
})
137137
}
138138
}
139+
140+
func TestDeleteFromQueue(t *testing.T) {
141+
cq := utiltesting.MakeClusterQueue("cq").Obj()
142+
cqImpl, err := newClusterQueueBestEffortFIFO(cq)
143+
if err != nil {
144+
t.Fatalf("Failed creating ClusterQueue %v", err)
145+
}
146+
q := utiltesting.MakeQueue("foo", "").ClusterQueue(cq.Name).Obj()
147+
qImpl := newQueue(q)
148+
wl1 := utiltesting.MakeWorkload("wl1", "").Queue(q.Name).Obj()
149+
wl2 := utiltesting.MakeWorkload("wl2", "").Queue(q.Name).Obj()
150+
wl3 := utiltesting.MakeWorkload("wl3", "").Queue(q.Name).Obj()
151+
wl4 := utiltesting.MakeWorkload("wl4", "").Queue(q.Name).Obj()
152+
admissibleworkloads := []*kueue.Workload{wl1, wl2}
153+
inadmissibleWorkloads := []*kueue.Workload{wl3, wl4}
154+
155+
for _, w := range admissibleworkloads {
156+
cqImpl.PushOrUpdate(w)
157+
qImpl.AddOrUpdate(w)
158+
}
159+
160+
for _, w := range inadmissibleWorkloads {
161+
cqImpl.RequeueIfNotPresent(workload.NewInfo(w), false)
162+
qImpl.AddOrUpdate(w)
163+
}
164+
165+
wantPending := len(admissibleworkloads) + len(inadmissibleWorkloads)
166+
if pending := cqImpl.Pending(); pending != int32(wantPending) {
167+
t.Errorf("clusterQueue's workload number not right, want %v, got %v", wantPending, pending)
168+
}
169+
fifo := cqImpl.(*ClusterQueueBestEffortFIFO)
170+
if len(fifo.inadmissibleWorkloads) != len(inadmissibleWorkloads) {
171+
t.Errorf("clusterQueue's workload number in inadmissibleWorkloads not right, want %v, got %v", len(inadmissibleWorkloads), len(fifo.inadmissibleWorkloads))
172+
}
173+
174+
cqImpl.DeleteFromQueue(qImpl)
175+
if cqImpl.Pending() != 0 {
176+
t.Error("clusterQueue should be empty")
177+
}
178+
}

0 commit comments

Comments
 (0)