Skip to content

Commit

Permalink
scheduler: fix monitor terminating pod (#2331)
Browse files Browse the repository at this point in the history
Signed-off-by: saintube <[email protected]>
Co-authored-by: shenxin <[email protected]>
  • Loading branch information
saintube and shenxin authored Feb 10, 2025
1 parent cc55177 commit 96ff411
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/scheduler/frameworkext/scheduler_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ func (m *SchedulerMonitor) RecordNextPod(podInfo *framework.QueuedPodInfo) {
return
}
pod := podInfo.Pod

// clean up from the cache when the pod is terminating
if pod.DeletionTimestamp != nil {
m.lock.Lock()
delete(m.schedulingPods, pod.UID)
m.lock.Unlock()
return
}

now := time.Now()
scheduleState := podScheduleState{
namespace: pod.Namespace,
Expand Down
13 changes: 13 additions & 0 deletions pkg/scheduler/frameworkext/scheduler_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,17 @@ func TestSchedulerMonitor_StartAndCompleteMonitoring(t *testing.T) {
if _, exists := monitor.schedulingPods[pod.UID]; exists {
t.Errorf("Pod should be removed from schedulingPods after Complete")
}

terminatingPod := podInfo.DeepCopy()
deleted := metav1.Now()
terminatingPod.Pod.DeletionTimestamp = &deleted
queuePodInfo = &framework.QueuedPodInfo{
Timestamp: time.Now(),
PodInfo: terminatingPod,
}
monitor.RecordNextPod(queuePodInfo)
_, ok = monitor.schedulingPods[pod.UID]
if ok {
t.Fatal("Pod should be removed in schedulingPods when terminating")
}
}

0 comments on commit 96ff411

Please sign in to comment.