diff --git a/pkg/scheduler/algorithm/predicates/predicates.go b/pkg/scheduler/algorithm/predicates/predicates.go index c5b84b978f..61967923ef 100644 --- a/pkg/scheduler/algorithm/predicates/predicates.go +++ b/pkg/scheduler/algorithm/predicates/predicates.go @@ -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") diff --git a/pkg/scheduler/scheduler_test.go b/pkg/scheduler/scheduler_test.go index e062a9ce60..92b739d299 100644 --- a/pkg/scheduler/scheduler_test.go +++ b/pkg/scheduler/scheduler_test.go @@ -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{ @@ -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", }, { @@ -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", }, {