Skip to content

Commit bc3c070

Browse files
carlorysanposhiho
andauthored
Fix a bug where the target pod doesn't become schedulable within 5 minutes when a deleted pod uses the same PVC with the ReadWriteOncePod access mode. (kubernetes#126263)
Co-authored-by: Kensei Nakada <[email protected]>
1 parent 00d03ec commit bc3c070

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

pkg/scheduler/framework/plugins/volumerestrictions/volume_restrictions.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,6 @@ func (pl *VolumeRestrictions) isSchedulableAfterPersistentVolumeClaimAdded(logge
362362

363363
// isSchedulableAfterPodDeleted is invoked whenever a pod deleted,
364364
// It checks whether the deleted pod will conflict with volumes of other pods on the same node
365-
// TODO If we observe good throughput, we will add a check for conflicts between the deleted Pod and the readWriteOncePodPVC of the current Pod.
366365
func (pl *VolumeRestrictions) isSchedulableAfterPodDeleted(logger klog.Logger, pod *v1.Pod, oldObj, newObj interface{}) (framework.QueueingHint, error) {
367366
deletedPod, _, err := util.As[*v1.Pod](oldObj, newObj)
368367
if err != nil {
@@ -375,9 +374,30 @@ func (pl *VolumeRestrictions) isSchedulableAfterPodDeleted(logger klog.Logger, p
375374

376375
nodeInfo := framework.NewNodeInfo(deletedPod)
377376
if !satisfyVolumeConflicts(pod, nodeInfo) {
377+
logger.V(5).Info("Pod with the volume that the target pod requires was deleted, which might make this pod schedulable", "pod", klog.KObj(pod), "deletedPod", klog.KObj(deletedPod))
378378
return framework.Queue, nil
379379
}
380380

381+
// Return Queue if a deleted pod uses the same PVC since the pod may be unschedulable due to the ReadWriteOncePod access mode of the PVC.
382+
//
383+
// For now, we don't actually fetch PVC and check the access mode because that operation could be expensive.
384+
// Once the observability around QHint is established,
385+
// we may want to do that depending on how much the operation would impact the QHint latency negatively.
386+
// https://github.com/kubernetes/kubernetes/issues/124566
387+
claims := sets.New[string]()
388+
for _, volume := range pod.Spec.Volumes {
389+
if volume.PersistentVolumeClaim != nil {
390+
claims.Insert(volume.PersistentVolumeClaim.ClaimName)
391+
}
392+
}
393+
for _, volume := range deletedPod.Spec.Volumes {
394+
if volume.PersistentVolumeClaim != nil && claims.Has(volume.PersistentVolumeClaim.ClaimName) {
395+
logger.V(5).Info("Pod with the same PVC that the target pod requires was deleted, which might make this pod schedulable", "pod", klog.KObj(pod), "deletedPod", klog.KObj(deletedPod))
396+
return framework.Queue, nil
397+
}
398+
}
399+
400+
logger.V(5).Info("An irrelevant Pod was deleted, which doesn't make this pod schedulable", "pod", klog.KObj(pod), "deletedPod", klog.KObj(deletedPod))
381401
return framework.QueueSkip, nil
382402
}
383403

pkg/scheduler/framework/plugins/volumerestrictions/volume_restrictions_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,22 @@ func Test_isSchedulableAfterPodDeleted(t *testing.T) {
640640
expectedHint: framework.QueueSkip,
641641
expectedErr: false,
642642
},
643+
"queue-has-same-claim": {
644+
pod: st.MakePod().Name("pod1").PVC("claim-rwop").Obj(),
645+
oldObj: st.MakePod().Name("pod2").PVC("claim-rwop").Obj(),
646+
existingPods: []*v1.Pod{},
647+
existingPVC: &v1.PersistentVolumeClaim{},
648+
expectedHint: framework.Queue,
649+
expectedErr: false,
650+
},
651+
"skip-no-same-claim": {
652+
pod: st.MakePod().Name("pod1").PVC("claim-1-rwop").Obj(),
653+
oldObj: st.MakePod().Name("pod2").PVC("claim-2-rwop").Obj(),
654+
existingPods: []*v1.Pod{},
655+
existingPVC: &v1.PersistentVolumeClaim{},
656+
expectedHint: framework.QueueSkip,
657+
expectedErr: false,
658+
},
643659
}
644660

645661
for name, tc := range testcases {

0 commit comments

Comments
 (0)