Skip to content

Commit 5e81a2d

Browse files
committed
Optimize VolumeRestrictions scheduler plugin
1 parent e6ee924 commit 5e81a2d

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,7 @@ func (pl *VolumeRestrictions) Name() string {
4242
return Name
4343
}
4444

45-
func isVolumeConflict(volume v1.Volume, pod *v1.Pod) bool {
46-
// fast path if there is no conflict checking targets.
47-
if volume.GCEPersistentDisk == nil && volume.AWSElasticBlockStore == nil && volume.RBD == nil && volume.ISCSI == nil {
48-
return false
49-
}
50-
45+
func isVolumeConflict(volume *v1.Volume, pod *v1.Pod) bool {
5146
for _, existingVolume := range pod.Spec.Volumes {
5247
// Same GCE disk mounted by multiple pods conflicts unless all pods mount it read-only.
5348
if volume.GCEPersistentDisk != nil && existingVolume.GCEPersistentDisk != nil {
@@ -118,7 +113,13 @@ func haveOverlap(a1, a2 []string) bool {
118113
// - Ceph RBD forbids if any two pods share at least same monitor, and match pool and image, and the image is read-only
119114
// - ISCSI forbids if any two pods share at least same IQN and ISCSI volume is read-only
120115
func (pl *VolumeRestrictions) Filter(ctx context.Context, _ *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) *framework.Status {
121-
for _, v := range pod.Spec.Volumes {
116+
for i := range pod.Spec.Volumes {
117+
v := &pod.Spec.Volumes[i]
118+
// fast path if there is no conflict checking targets.
119+
if v.GCEPersistentDisk == nil && v.AWSElasticBlockStore == nil && v.RBD == nil && v.ISCSI == nil {
120+
continue
121+
}
122+
122123
for _, ev := range nodeInfo.Pods {
123124
if isVolumeConflict(v, ev.Pod) {
124125
return framework.NewStatus(framework.Unschedulable, ErrReasonDiskConflict)

0 commit comments

Comments
 (0)