Skip to content

Commit 105f939

Browse files
committed
review_comment
1 parent a4b3ce8 commit 105f939

File tree

1 file changed

+21
-29
lines changed

1 file changed

+21
-29
lines changed

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

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -118,22 +118,6 @@ func (pl *VolumeZone) PreFilter(ctx context.Context, cs *framework.CycleState, p
118118
return nil, nil
119119
}
120120

121-
// isWaitForFirstConsumer confirms whether storageClass's volumeBindingMode is VolumeBindingWaitForFirstConsumer or not.
122-
func (pl *VolumeZone) isWaitForFirstConsumer(scName string) (bool, *framework.Status) {
123-
class, err := pl.scLister.Get(scName)
124-
if s := getErrorAsStatus(err); !s.IsSuccess() {
125-
return false, s
126-
}
127-
if class.VolumeBindingMode == nil {
128-
return false, framework.NewStatus(framework.UnschedulableAndUnresolvable, fmt.Sprintf("VolumeBindingMode not set for StorageClass %q", scName))
129-
}
130-
if *class.VolumeBindingMode == storage.VolumeBindingWaitForFirstConsumer {
131-
// Return true because volumeBindingMode of storageClass is VolumeBindingWaitForFirstConsumer.
132-
return true, nil
133-
}
134-
return false, framework.NewStatus(framework.UnschedulableAndUnresolvable, "PersistentVolume had no name")
135-
}
136-
137121
// getPVbyPod gets PVTopology from pod
138122
func (pl *VolumeZone) getPVbyPod(logger klog.Logger, pod *v1.Pod) ([]pvTopology, *framework.Status) {
139123
podPVTopologies := make([]pvTopology, 0)
@@ -154,11 +138,20 @@ func (pl *VolumeZone) getPVbyPod(logger klog.Logger, pod *v1.Pod) ([]pvTopology,
154138
if len(scName) == 0 {
155139
return nil, framework.NewStatus(framework.UnschedulableAndUnresolvable, "PersistentVolumeClaim had no pv name and storageClass name")
156140
}
157-
isWait, status := pl.isWaitForFirstConsumer(scName)
158-
if !isWait {
159-
return nil, status
141+
142+
class, err := pl.scLister.Get(scName)
143+
if s := getErrorAsStatus(err); !s.IsSuccess() {
144+
return nil, s
160145
}
161-
continue
146+
if class.VolumeBindingMode == nil {
147+
return nil, framework.NewStatus(framework.UnschedulableAndUnresolvable, fmt.Sprintf("VolumeBindingMode not set for StorageClass %q", scName))
148+
}
149+
if *class.VolumeBindingMode == storage.VolumeBindingWaitForFirstConsumer {
150+
// Skip unbound volumes
151+
continue
152+
}
153+
154+
return nil, framework.NewStatus(framework.UnschedulableAndUnresolvable, "PersistentVolume had no name")
162155
}
163156

164157
pv, err := pl.pvLister.Get(pvName)
@@ -325,18 +318,17 @@ func (pl *VolumeZone) isSchedulableAfterPersistentVolumeClaimChange(logger klog.
325318
if err != nil {
326319
return framework.Queue, fmt.Errorf("unexpected objects in isSchedulableAfterPersistentVolumeClaimChange: %w", err)
327320
}
328-
isMatched := pl.checkPVCBindingToPodPV(logger, modifiedPVC, pod)
329-
// updated PVC is not schedulable because PVC doesn't match the pod's PVC
330-
if !isMatched {
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))
332-
return framework.QueueSkip, nil
321+
if pl.IsPVCRequestedFromPod(logger, modifiedPVC, pod) {
322+
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))
323+
return framework.Queue, nil
333324
}
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
325+
326+
logger.V(5).Info("PVC irrelevant to the Pod was created or updated, which doesn't make this pod schedulable", "pod", klog.KObj(pod), "PVC", klog.KObj(modifiedPVC))
327+
return framework.QueueSkip, nil
336328
}
337329

338-
// checkPVCBindingToPodPV verifies if the PVC is bound to PV of a given Pod.
339-
func (pl *VolumeZone) checkPVCBindingToPodPV(logger klog.Logger, pvc *v1.PersistentVolumeClaim, pod *v1.Pod) bool {
330+
// IsPVCRequestedFromPod verifies if the PVC is bound to PV of a given Pod.
331+
func (pl *VolumeZone) IsPVCRequestedFromPod(logger klog.Logger, pvc *v1.PersistentVolumeClaim, pod *v1.Pod) bool {
340332
if (pvc == nil) || (pod.Namespace != pvc.Namespace) {
341333
return false
342334
}

0 commit comments

Comments
 (0)