-
Notifications
You must be signed in to change notification settings - Fork 597
Fix second-pass queue cleanup when workload no longer needs retry #8431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a7f4086
0791c91
4a14fc8
2130ed9
afdbbb2
3ab949e
2ad6079
4c1698c
ec5c3b4
2802960
b5a2694
3cce572
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -815,16 +815,22 @@ func (m *Manager) DeleteSecondPassWithoutLock(wl *kueue.Workload) { | |||||||
| // QueueSecondPassIfNeeded queues for the second pass of scheduling with exponential | ||||||||
| // delay. | ||||||||
| func (m *Manager) QueueSecondPassIfNeeded(ctx context.Context, w *kueue.Workload, iteration int) bool { | ||||||||
| log := ctrl.LoggerFrom(ctx) | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| if workload.NeedsSecondPass(w) { | ||||||||
| iteration++ | ||||||||
| delay := m.secondPassQueue.nextDelay(iteration) | ||||||||
| log := ctrl.LoggerFrom(ctx) | ||||||||
| log.V(3).Info("Workload pre-queued for second pass (with backoff)", "workload", workload.Key(w), "delay", delay) | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| m.secondPassQueue.prequeue(w) | ||||||||
| m.clock.AfterFunc(delay, func() { | ||||||||
| m.queueSecondPass(ctx, w, iteration) | ||||||||
| }) | ||||||||
| return true | ||||||||
| } else if iteration > 0 { | ||||||||
| // Remove the workload from the second-pass queue only after at least one | ||||||||
| // retry iteration, to avoid canceling the initial backoff window. | ||||||||
| // See #8357. | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Could you use a link for visibility? |
||||||||
| log.V(3).Info("Workload removed from second pass queue", "workload", workload.Key(w)) | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| m.secondPassQueue.deleteByKey(workload.Key(w)) | ||||||||
| } | ||||||||
| return false | ||||||||
| } | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1386,6 +1386,7 @@ func TestQueueSecondPassIfNeeded(t *testing.T) { | |||||||||||||||||
| RequiredTopologyRequest(corev1.LabelHostname). | ||||||||||||||||||
| Request(corev1.ResourceCPU, "1"). | ||||||||||||||||||
| Obj()) | ||||||||||||||||||
|
|
||||||||||||||||||
| baseWorkloadNeedingSecondPass := baseWorkloadBuilder.Clone(). | ||||||||||||||||||
| ReserveQuotaAt( | ||||||||||||||||||
| utiltestingapi.MakeAdmission("tas-main"). | ||||||||||||||||||
|
|
@@ -1395,22 +1396,26 @@ func TestQueueSecondPassIfNeeded(t *testing.T) { | |||||||||||||||||
| DelayedTopologyRequest(kueue.DelayedTopologyRequestStatePending). | ||||||||||||||||||
| Obj(), | ||||||||||||||||||
| ). | ||||||||||||||||||
| Obj(), now, | ||||||||||||||||||
| Obj(), | ||||||||||||||||||
| now, | ||||||||||||||||||
| ). | ||||||||||||||||||
| AdmissionCheck(kueue.AdmissionCheckState{ | ||||||||||||||||||
| Name: "prov-check", | ||||||||||||||||||
| State: kueue.CheckStateReady, | ||||||||||||||||||
| }) | ||||||||||||||||||
|
|
||||||||||||||||||
| baseWorkloadNotNeedingSecondPass := baseWorkloadBuilder.Clone() | ||||||||||||||||||
|
|
||||||||||||||||||
| cases := map[string]struct { | ||||||||||||||||||
| workloads []*kueue.Workload | ||||||||||||||||||
| deleted sets.Set[workload.Reference] | ||||||||||||||||||
| update func(*kueue.Workload) | ||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Such dynamic modification while UT should be avoided as much as possible.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1, current implementation sets status.admission=nil to make the workload not needing the second pass, but I'm not sure we have a helper for that. We can alternatively Evict the workload for example (eg. using EvictedAt), which would also be more realistic case, because workload is first evicted, and only then the admission is removed.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I opened the potentially related issue #8633 |
||||||||||||||||||
| passTime time.Duration | ||||||||||||||||||
| wantReady sets.Set[workload.Reference] | ||||||||||||||||||
| }{ | ||||||||||||||||||
| "single queued workload checked immediately": { | ||||||||||||||||||
| workloads: []*kueue.Workload{baseWorkloadNeedingSecondPass.Obj()}, | ||||||||||||||||||
| workloads: []*kueue.Workload{ | ||||||||||||||||||
| baseWorkloadNeedingSecondPass.Obj(), | ||||||||||||||||||
| }, | ||||||||||||||||||
| }, | ||||||||||||||||||
| "single queued workload checked after 1s": { | ||||||||||||||||||
| workloads: []*kueue.Workload{ | ||||||||||||||||||
|
|
@@ -1420,43 +1425,57 @@ func TestQueueSecondPassIfNeeded(t *testing.T) { | |||||||||||||||||
| passTime: time.Second, | ||||||||||||||||||
| wantReady: sets.New(workload.Key(baseWorkloadNeedingSecondPass.Obj())), | ||||||||||||||||||
| }, | ||||||||||||||||||
| "single queued workload deleted in the meanwhile": { | ||||||||||||||||||
| "workload stops needing second pass after being queued": { | ||||||||||||||||||
| workloads: []*kueue.Workload{ | ||||||||||||||||||
| baseWorkloadNeedingSecondPass.DeepCopy(), | ||||||||||||||||||
| baseWorkloadNotNeedingSecondPass.DeepCopy(), | ||||||||||||||||||
| }, | ||||||||||||||||||
| deleted: sets.New(workload.Key(baseWorkloadNeedingSecondPass.Obj())), | ||||||||||||||||||
| passTime: time.Second, | ||||||||||||||||||
| update: func(wl *kueue.Workload) { | ||||||||||||||||||
| wl.Status.Admission = nil | ||||||||||||||||||
| }, | ||||||||||||||||||
| passTime: time.Second, | ||||||||||||||||||
| wantReady: nil, | ||||||||||||||||||
| }, | ||||||||||||||||||
| "two queued workloads, one deleted in the meanwhile": { | ||||||||||||||||||
| "two queued workloads, one updated to no longer need second pass": { | ||||||||||||||||||
| workloads: []*kueue.Workload{ | ||||||||||||||||||
| baseWorkloadNeedingSecondPass.Clone().Name("first").Obj(), | ||||||||||||||||||
| baseWorkloadNeedingSecondPass.Clone().Name("second").Obj(), | ||||||||||||||||||
| }, | ||||||||||||||||||
| deleted: sets.New(workload.Key(baseWorkloadNeedingSecondPass.Obj())), | ||||||||||||||||||
| update: func(wl *kueue.Workload) { | ||||||||||||||||||
| wl.Status.Admission = nil | ||||||||||||||||||
| }, | ||||||||||||||||||
| passTime: time.Second, | ||||||||||||||||||
| wantReady: sets.New(workload.NewReference("default", "second")), | ||||||||||||||||||
| }, | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| for name, tc := range cases { | ||||||||||||||||||
| t.Run(name, func(t *testing.T) { | ||||||||||||||||||
| ctx, _ := utiltesting.ContextWithLog(t) | ||||||||||||||||||
|
|
||||||||||||||||||
| fakeClock := testingclock.NewFakeClock(now) | ||||||||||||||||||
| opts := []Option{ | ||||||||||||||||||
| manager := NewManager( | ||||||||||||||||||
| utiltesting.NewFakeClient(), | ||||||||||||||||||
| nil, | ||||||||||||||||||
| WithClock(fakeClock), | ||||||||||||||||||
| } | ||||||||||||||||||
| manager := NewManager(utiltesting.NewFakeClient(), nil, opts...) | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
| for _, wl := range tc.workloads { | ||||||||||||||||||
| manager.QueueSecondPassIfNeeded(ctx, wl, 0) | ||||||||||||||||||
| } | ||||||||||||||||||
| for _, wl := range tc.deleted.UnsortedList() { | ||||||||||||||||||
| manager.secondPassQueue.deleteByKey(wl) | ||||||||||||||||||
|
|
||||||||||||||||||
| if tc.update != nil { | ||||||||||||||||||
| wl := tc.workloads[0] | ||||||||||||||||||
| tc.update(wl) | ||||||||||||||||||
| manager.QueueSecondPassIfNeeded(ctx, wl, 1) | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+1466
to
1470
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
|
|
||||||||||||||||||
| fakeClock.Step(tc.passTime) | ||||||||||||||||||
|
|
||||||||||||||||||
| gotReady := sets.New[workload.Reference]() | ||||||||||||||||||
| for _, wlInfo := range manager.secondPassQueue.takeAllReady() { | ||||||||||||||||||
| gotReady.Insert(workload.Key(wlInfo.Obj)) | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| if diff := cmp.Diff(tc.wantReady, gotReady); diff != "" { | ||||||||||||||||||
| t.Errorf("Unexpected ready workloads returned (-want,+got):\n%s", diff) | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add some unit test for that changes in, probably in TestQueueSecondPassIfNeeded?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I’ll add unit coverage for this case and update the PR.