Skip to content

Commit

Permalink
Merge pull request #73652 from bsalamat/fast_volume_checker
Browse files Browse the repository at this point in the history
Short circuit volume checker if the pod is not requesting any volumes
  • Loading branch information
k8s-ci-robot committed Feb 3, 2019
2 parents 8de3885 + a20a243 commit 1b8435d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
14 changes: 14 additions & 0 deletions pkg/scheduler/algorithm/predicates/predicates.go
Expand Up @@ -1642,7 +1642,21 @@ func NewVolumeBindingPredicate(binder *volumebinder.VolumeBinder) FitPredicate {
return c.predicate
}

func podHasPVCs(pod *v1.Pod) bool {
for _, vol := range pod.Spec.Volumes {
if vol.PersistentVolumeClaim != nil {
return true
}
}
return false
}

func (c *VolumeBindingChecker) predicate(pod *v1.Pod, meta PredicateMetadata, nodeInfo *schedulernodeinfo.NodeInfo) (bool, []PredicateFailureReason, error) {
// If pod does not request any PVC, we don't need to do anything.
if !podHasPVCs(pod) {
return true, nil, nil
}

node := nodeInfo.Node()
if node == nil {
return false, nil, fmt.Errorf("node not found")
Expand Down
13 changes: 9 additions & 4 deletions pkg/scheduler/scheduler_test.go
Expand Up @@ -736,10 +736,15 @@ func setupTestSchedulerLongBindingWithRetry(queuedPodStore *clientcache.FIFO, sc
func setupTestSchedulerWithVolumeBinding(fakeVolumeBinder *volumebinder.VolumeBinder, stop <-chan struct{}, broadcaster record.EventBroadcaster) (*Scheduler, chan *v1.Binding, chan error) {
testNode := v1.Node{ObjectMeta: metav1.ObjectMeta{Name: "machine1", UID: types.UID("machine1")}}
queuedPodStore := clientcache.NewFIFO(clientcache.MetaNamespaceKeyFunc)
queuedPodStore.Add(podWithID("foo", ""))
pod := podWithID("foo", "")
pod.Namespace = "foo-ns"
pod.Spec.Volumes = append(pod.Spec.Volumes, v1.Volume{Name: "testVol",
VolumeSource: v1.VolumeSource{PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{ClaimName: "testPVC"}}})
queuedPodStore.Add(pod)
scache := schedulerinternalcache.New(10*time.Minute, stop)
scache.AddNode(&testNode)
client := clientsetfake.NewSimpleClientset(&testNode)
testPVC := v1.PersistentVolumeClaim{ObjectMeta: metav1.ObjectMeta{Name: "testPVC", Namespace: pod.Namespace, UID: types.UID("testPVC")}}
client := clientsetfake.NewSimpleClientset(&testNode, &testPVC)
informerFactory := informers.NewSharedInformerFactory(client, 0)

predicateMap := map[string]predicates.FitPredicate{
Expand Down Expand Up @@ -790,7 +795,7 @@ func TestSchedulerWithVolumeBinding(t *testing.T) {
FindBoundSatsified: true,
},
expectAssumeCalled: true,
expectPodBind: &v1.Binding{ObjectMeta: metav1.ObjectMeta{Name: "foo", UID: types.UID("foo")}, Target: v1.ObjectReference{Kind: "Node", Name: "machine1"}},
expectPodBind: &v1.Binding{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "foo-ns", UID: types.UID("foo")}, Target: v1.ObjectReference{Kind: "Node", Name: "machine1"}},
eventReason: "Scheduled",
},
{
Expand Down Expand Up @@ -829,7 +834,7 @@ func TestSchedulerWithVolumeBinding(t *testing.T) {
},
expectAssumeCalled: true,
expectBindCalled: true,
expectPodBind: &v1.Binding{ObjectMeta: metav1.ObjectMeta{Name: "foo", UID: types.UID("foo")}, Target: v1.ObjectReference{Kind: "Node", Name: "machine1"}},
expectPodBind: &v1.Binding{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "foo-ns", UID: types.UID("foo")}, Target: v1.ObjectReference{Kind: "Node", Name: "machine1"}},
eventReason: "Scheduled",
},
{
Expand Down

0 comments on commit 1b8435d

Please sign in to comment.