diff --git a/cmd/kube-scheduler/app/server.go b/cmd/kube-scheduler/app/server.go index 7d39910014..ec16307f7a 100644 --- a/cmd/kube-scheduler/app/server.go +++ b/cmd/kube-scheduler/app/server.go @@ -476,7 +476,7 @@ func NewSchedulerServer(config *componentconfig.KubeSchedulerConfiguration, mast SchedulerName: config.SchedulerName, Client: client, InformerFactory: informers.NewSharedInformerFactory(client, 0), - PodInformer: factory.NewPodInformer(client, 0, config.SchedulerName), + PodInformer: factory.NewPodInformer(client, 0), AlgorithmSource: config.AlgorithmSource, HardPodAffinitySymmetricWeight: config.HardPodAffinitySymmetricWeight, EventClient: eventClient, diff --git a/pkg/scheduler/factory/factory.go b/pkg/scheduler/factory/factory.go index 0a5df6ed64..174c1f384c 100644 --- a/pkg/scheduler/factory/factory.go +++ b/pkg/scheduler/factory/factory.go @@ -218,10 +218,10 @@ func NewConfigFactory( FilterFunc: func(obj interface{}) bool { switch t := obj.(type) { case *v1.Pod: - return unassignedNonTerminatedPod(t) + return unassignedNonTerminatedPod(t) && responsibleForPod(t, schedulerName) case cache.DeletedFinalStateUnknown: if pod, ok := t.Obj.(*v1.Pod); ok { - return unassignedNonTerminatedPod(pod) + return unassignedNonTerminatedPod(pod) && responsibleForPod(pod, schedulerName) } runtime.HandleError(fmt.Errorf("unable to convert object %T to *v1.Pod in %T", obj, c)) return false @@ -1198,6 +1198,11 @@ func assignedNonTerminatedPod(pod *v1.Pod) bool { return true } +// responsibleForPod returns true if the pod has asked to be scheduled by the given scheduler. +func responsibleForPod(pod *v1.Pod, schedulerName string) bool { + return schedulerName == pod.Spec.SchedulerName +} + // assignedPodLister filters the pods returned from a PodLister to // only include those that have a node name set. type assignedPodLister struct { @@ -1270,10 +1275,9 @@ func (i *podInformer) Lister() corelisters.PodLister { } // NewPodInformer creates a shared index informer that returns only non-terminal pods. -func NewPodInformer(client clientset.Interface, resyncPeriod time.Duration, schedulerName string) coreinformers.PodInformer { +func NewPodInformer(client clientset.Interface, resyncPeriod time.Duration) coreinformers.PodInformer { selector := fields.ParseSelectorOrDie( - "spec.schedulerName=" + schedulerName + - ",status.phase!=" + string(v1.PodSucceeded) + + "status.phase!=" + string(v1.PodSucceeded) + ",status.phase!=" + string(v1.PodFailed)) lw := cache.NewListWatchFromClient(client.CoreV1().RESTClient(), string(v1.ResourcePods), metav1.NamespaceAll, selector) return &podInformer{ diff --git a/test/integration/scheduler/util.go b/test/integration/scheduler/util.go index 2a383a1fc3..c55e8d9428 100644 --- a/test/integration/scheduler/util.go +++ b/test/integration/scheduler/util.go @@ -164,7 +164,7 @@ func initTestSchedulerWithOptions( // create independent pod informer if required if setPodInformer { - podInformer = factory.NewPodInformer(context.clientSet, 12*time.Hour, v1.DefaultSchedulerName) + podInformer = factory.NewPodInformer(context.clientSet, 12*time.Hour) } else { podInformer = context.informerFactory.Core().V1().Pods() }