Skip to content

Commit a4b3ce8

Browse files
committed
simplify
1 parent 116665d commit a4b3ce8

File tree

2 files changed

+10
-31
lines changed

2 files changed

+10
-31
lines changed

pkg/scheduler/framework/plugins/volumezone/volume_zone.go

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -321,24 +321,18 @@ func (pl *VolumeZone) getPersistentVolumeClaimNameFromPod(pod *v1.Pod) []string
321321
// It checks whether the change of PVC has made a previously unschedulable pod schedulable.
322322
// A PVC becoming bound or using a WaitForFirstConsumer storageclass can cause the pod to become schedulable.
323323
func (pl *VolumeZone) isSchedulableAfterPersistentVolumeClaimChange(logger klog.Logger, pod *v1.Pod, oldObj, newObj interface{}) (framework.QueueingHint, error) {
324-
originalPVC, modifiedPVC, err := util.As[*v1.PersistentVolumeClaim](oldObj, newObj)
324+
_, modifiedPVC, err := util.As[*v1.PersistentVolumeClaim](oldObj, newObj)
325325
if err != nil {
326326
return framework.Queue, fmt.Errorf("unexpected objects in isSchedulableAfterPersistentVolumeClaimChange: %w", err)
327327
}
328328
isMatched := pl.checkPVCBindingToPodPV(logger, modifiedPVC, pod)
329329
// updated PVC is not schedulable because PVC doesn't match the pod's PVC
330330
if !isMatched {
331-
logger.V(5).Info("PVC was created or updated but it doesn't make this pod schedulable.", "pod", klog.KObj(pod), "PVC", klog.KObj(modifiedPVC))
331+
logger.V(5).Info("PVC was created or updated but it doesn't make this pod schedulable. PVC is not binding to the pod.", "pod", klog.KObj(pod), "PVC", klog.KObj(modifiedPVC))
332332
return framework.QueueSkip, nil
333333
}
334-
wasMatched := pl.checkPVCBindingToPodPV(logger, originalPVC, pod)
335-
// the PVC that didn't match the pod now matches the pod
336-
if isMatched && !wasMatched {
337-
logger.V(5).Info("PVC was created or updated, which might make the pod schedulable. The given PVC matches the pod's PVC", "pod", klog.KObj(pod), "PVC", klog.KObj(modifiedPVC))
338-
return framework.Queue, nil
339-
}
340-
logger.V(5).Info("PVC was created or updated but it doesn't make this pod schedulable. Nothing has changed about PV bound to PVC.", "pod", klog.KObj(pod), "PVC", klog.KObj(modifiedPVC))
341-
return framework.QueueSkip, nil
334+
logger.V(5).Info("PVC was created or updated and it might make this pod schedulable. PVC is binding to the pod.", "pod", klog.KObj(pod), "PVC", klog.KObj(modifiedPVC))
335+
return framework.Queue, nil
342336
}
343337

344338
// checkPVCBindingToPodPV verifies if the PVC is bound to PV of a given Pod.
@@ -348,26 +342,11 @@ func (pl *VolumeZone) checkPVCBindingToPodPV(logger klog.Logger, pvc *v1.Persist
348342
}
349343
pvcNames := pl.getPersistentVolumeClaimNameFromPod(pod)
350344
for _, pvcName := range pvcNames {
351-
if pvc.Name != pvcName {
352-
// pod's PVC doesn't match with the given PVC
353-
continue
345+
if pvc.Name == pvcName {
346+
logger.V(5).Info("PVC matches the pod's PVC", "pod", klog.KObj(pod), "PVC", klog.KObj(pvc))
347+
return true
354348
}
355-
logger.V(5).Info("PVC matches the pod's PVC", "pod", klog.KObj(pod), "PVC", klog.KObj(pvc))
356-
pvName := pvc.Spec.VolumeName
357-
if pvName == "" {
358-
scName := storagehelpers.GetPersistentVolumeClaimClass(pvc)
359-
if len(scName) == 0 {
360-
return false
361-
}
362-
isWait, _ := pl.isWaitForFirstConsumer(scName)
363-
if !isWait {
364-
logger.V(5).Info("PVC is bound to storageClass but the volumeBindingMode is not WaitForFirstConsumer", "storageClass", scName)
365-
return false
366-
}
367-
}
368-
return true
369349
}
370-
371350
logger.V(5).Info("PVC doesn't match the pod's PVC", "pod", klog.KObj(pod), "PVC", klog.KObj(pvc))
372351
return false
373352
}

pkg/scheduler/framework/plugins/volumezone/volume_zone_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ func TestIsSchedulableAfterPersistentVolumeClaimAdded(t *testing.T) {
624624
ObjectMeta: metav1.ObjectMeta{Name: "PVC_2", Namespace: "default"},
625625
Spec: v1.PersistentVolumeClaimSpec{StorageClassName: ptr.To("SC_1")},
626626
},
627-
expectedHint: framework.QueueSkip,
627+
expectedHint: framework.Queue,
628628
},
629629
"pvc-was-added-and-pod-was-bound-to-added-pvc, pvc-bound-to-storage-class-with-wait-mode": {
630630
pod: createPodWithVolume("pod_1", "PVC_3"),
@@ -656,10 +656,10 @@ func TestIsSchedulableAfterPersistentVolumeClaimAdded(t *testing.T) {
656656
ObjectMeta: metav1.ObjectMeta{Name: "PVC_1", Namespace: "default"},
657657
Spec: v1.PersistentVolumeClaimSpec{VolumeName: "Vol_1"},
658658
},
659-
expectedHint: framework.QueueSkip,
659+
expectedHint: framework.Queue,
660660
},
661661
"pvc-was-updated-but-pod-was-not-bound-to-pvc": {
662-
pod: createPodWithVolume("pod_1", "PVC_1"),
662+
pod: createPodWithVolume("pod_1", ""),
663663
oldObj: &v1.PersistentVolumeClaim{
664664
ObjectMeta: metav1.ObjectMeta{Name: "PVC_1", Namespace: "default"},
665665
Spec: v1.PersistentVolumeClaimSpec{VolumeName: ""},

0 commit comments

Comments
 (0)