@@ -557,27 +557,30 @@ func (p *PriorityQueue) moveToActiveQ(logger klog.Logger, pInfo *framework.Queue
557
557
p .activeQ .underLock (func (unlockedActiveQ unlockedActiveQueuer ) {
558
558
if pInfo .Gated {
559
559
// Add the Pod to unschedulablePods if it's not passing PreEnqueuePlugins.
560
- if unlockedActiveQ .Has (pInfo ) {
560
+ if unlockedActiveQ .has (pInfo ) {
561
561
return
562
562
}
563
563
if p .backoffQ .has (pInfo ) {
564
564
return
565
565
}
566
- p .unschedulablePods .addOrUpdate (pInfo )
566
+ if p .unschedulablePods .get (pInfo .Pod ) != nil {
567
+ return
568
+ }
569
+ p .unschedulablePods .addOrUpdate (pInfo , event )
570
+ logger .V (5 ).Info ("Pod moved to an internal scheduling queue, because the pod is gated" , "pod" , klog .KObj (pInfo .Pod ), "event" , event , "queue" , unschedulablePods )
567
571
return
568
572
}
569
573
if pInfo .InitialAttemptTimestamp == nil {
570
574
now := p .clock .Now ()
571
575
pInfo .InitialAttemptTimestamp = & now
572
576
}
573
577
574
- unlockedActiveQ .AddOrUpdate (pInfo )
578
+ unlockedActiveQ .add (pInfo , event )
575
579
added = true
576
580
577
581
p .unschedulablePods .delete (pInfo .Pod , gatedBefore )
578
582
p .backoffQ .delete (pInfo )
579
583
logger .V (5 ).Info ("Pod moved to an internal scheduling queue" , "pod" , klog .KObj (pInfo .Pod ), "event" , event , "queue" , activeQ )
580
- metrics .SchedulerQueueIncomingPods .WithLabelValues ("active" , event ).Inc ()
581
584
if event == framework .EventUnscheduledPodAdd .Label () || event == framework .EventUnscheduledPodUpdate .Label () {
582
585
p .AddNominatedPod (logger , pInfo .PodInfo , nil )
583
586
}
@@ -721,13 +724,11 @@ func (p *PriorityQueue) addUnschedulableWithoutQueueingHint(logger klog.Logger,
721
724
// - No unschedulable plugins are associated with this Pod,
722
725
// meaning something unusual (a temporal failure on kube-apiserver, etc) happened and this Pod gets moved back to the queue.
723
726
// In this case, we should retry scheduling it because this Pod may not be retried until the next flush.
724
- p .backoffQ .add (logger , pInfo )
727
+ p .backoffQ .add (logger , pInfo , framework . ScheduleAttemptFailure )
725
728
logger .V (5 ).Info ("Pod moved to an internal scheduling queue" , "pod" , klog .KObj (pod ), "event" , framework .ScheduleAttemptFailure , "queue" , backoffQ )
726
- metrics .SchedulerQueueIncomingPods .WithLabelValues ("backoff" , framework .ScheduleAttemptFailure ).Inc ()
727
729
} else {
728
- p .unschedulablePods .addOrUpdate (pInfo )
730
+ p .unschedulablePods .addOrUpdate (pInfo , framework . ScheduleAttemptFailure )
729
731
logger .V (5 ).Info ("Pod moved to an internal scheduling queue" , "pod" , klog .KObj (pod ), "event" , framework .ScheduleAttemptFailure , "queue" , unschedulablePods )
730
- metrics .SchedulerQueueIncomingPods .WithLabelValues ("unschedulable" , framework .ScheduleAttemptFailure ).Inc ()
731
732
}
732
733
733
734
return nil
@@ -933,7 +934,7 @@ func (p *PriorityQueue) Update(logger klog.Logger, oldPod, newPod *v1.Pod) {
933
934
// Pod might have completed its backoff time while being in unschedulablePods,
934
935
// so we should check isPodBackingoff before moving the pod to backoffQ.
935
936
if p .backoffQ .isPodBackingoff (pInfo ) {
936
- p .backoffQ .add (logger , pInfo )
937
+ p .backoffQ .add (logger , pInfo , framework . EventUnscheduledPodUpdate . Label () )
937
938
p .unschedulablePods .delete (pInfo .Pod , gated )
938
939
logger .V (5 ).Info ("Pod moved to an internal scheduling queue" , "pod" , klog .KObj (pInfo .Pod ), "event" , framework .EventUnscheduledPodUpdate .Label (), "queue" , backoffQ )
939
940
return
@@ -946,7 +947,7 @@ func (p *PriorityQueue) Update(logger klog.Logger, oldPod, newPod *v1.Pod) {
946
947
}
947
948
948
949
// Pod update didn't make it schedulable, keep it in the unschedulable queue.
949
- p .unschedulablePods .addOrUpdate (pInfo )
950
+ p .unschedulablePods .addOrUpdate (pInfo , framework . EventUnscheduledPodUpdate . Label () )
950
951
return
951
952
}
952
953
// If pod is not in any of the queues, we put it in the active queue.
@@ -1036,30 +1037,22 @@ func (p *PriorityQueue) MoveAllToActiveOrBackoffQueue(logger klog.Logger, event
1036
1037
// NOTE: this function assumes lock has been acquired in caller
1037
1038
func (p * PriorityQueue ) requeuePodViaQueueingHint (logger klog.Logger , pInfo * framework.QueuedPodInfo , strategy queueingStrategy , event string ) string {
1038
1039
if strategy == queueSkip {
1039
- p .unschedulablePods .addOrUpdate (pInfo )
1040
- metrics .SchedulerQueueIncomingPods .WithLabelValues ("unschedulable" , event ).Inc ()
1040
+ p .unschedulablePods .addOrUpdate (pInfo , event )
1041
1041
return unschedulablePods
1042
1042
}
1043
1043
1044
1044
// Pod might have completed its backoff time while being in unschedulablePods,
1045
1045
// so we should check isPodBackingoff before moving the pod to backoffQ.
1046
1046
if strategy == queueAfterBackoff && p .backoffQ .isPodBackingoff (pInfo ) {
1047
- p .backoffQ .add (logger , pInfo )
1048
- metrics .SchedulerQueueIncomingPods .WithLabelValues ("backoff" , event ).Inc ()
1047
+ p .backoffQ .add (logger , pInfo , event )
1049
1048
return backoffQ
1050
1049
}
1051
1050
1052
1051
// Reach here if schedulingHint is QueueImmediately, or schedulingHint is Queue but the pod is not backing off.
1053
1052
if added := p .moveToActiveQ (logger , pInfo , event ); added {
1054
1053
return activeQ
1055
1054
}
1056
- if pInfo .Gated {
1057
- // In case the pod is gated, the Pod is pushed back to unschedulable Pods pool in moveToActiveQ.
1058
- return unschedulablePods
1059
- }
1060
-
1061
- p .unschedulablePods .addOrUpdate (pInfo )
1062
- metrics .SchedulerQueueIncomingPods .WithLabelValues ("unschedulable" , framework .ScheduleAttemptFailure ).Inc ()
1055
+ // Pod is gated. We don't have to push it back to unschedulable queue, because moveToActiveQ should already have done that.
1063
1056
return unschedulablePods
1064
1057
}
1065
1058
@@ -1178,7 +1171,7 @@ func (p *PriorityQueue) GetPod(name, namespace string) (pInfo *framework.QueuedP
1178
1171
}
1179
1172
1180
1173
p .activeQ .underRLock (func (unlockedActiveQ unlockedActiveQueueReader ) {
1181
- pInfo , ok = unlockedActiveQ .Get (pInfoLookup )
1174
+ pInfo , ok = unlockedActiveQ .get (pInfoLookup )
1182
1175
})
1183
1176
return
1184
1177
}
@@ -1205,7 +1198,7 @@ func (p *PriorityQueue) nominatedPodToInfo(np podRef, unlockedActiveQ unlockedAc
1205
1198
pod := np .toPod ()
1206
1199
pInfoLookup := newQueuedPodInfoForLookup (pod )
1207
1200
1208
- queuedPodInfo , exists := unlockedActiveQ .Get (pInfoLookup )
1201
+ queuedPodInfo , exists := unlockedActiveQ .get (pInfoLookup )
1209
1202
if exists {
1210
1203
return queuedPodInfo .PodInfo
1211
1204
}
@@ -1275,14 +1268,16 @@ type UnschedulablePods struct {
1275
1268
}
1276
1269
1277
1270
// addOrUpdate adds a pod to the unschedulable podInfoMap.
1278
- func (u * UnschedulablePods ) addOrUpdate (pInfo * framework.QueuedPodInfo ) {
1271
+ // The event should show which event triggered the addition and is used for the metric recording.
1272
+ func (u * UnschedulablePods ) addOrUpdate (pInfo * framework.QueuedPodInfo , event string ) {
1279
1273
podID := u .keyFunc (pInfo .Pod )
1280
1274
if _ , exists := u .podInfoMap [podID ]; ! exists {
1281
1275
if pInfo .Gated && u .gatedRecorder != nil {
1282
1276
u .gatedRecorder .Inc ()
1283
1277
} else if ! pInfo .Gated && u .unschedulableRecorder != nil {
1284
1278
u .unschedulableRecorder .Inc ()
1285
1279
}
1280
+ metrics .SchedulerQueueIncomingPods .WithLabelValues ("unschedulable" , event ).Inc ()
1286
1281
}
1287
1282
u .podInfoMap [podID ] = pInfo
1288
1283
}
0 commit comments