diff --git a/pkg/scheduler/schedule_one_test.go b/pkg/scheduler/schedule_one_test.go index 7375ef51fa0..43a606de145 100644 --- a/pkg/scheduler/schedule_one_test.go +++ b/pkg/scheduler/schedule_one_test.go @@ -3829,146 +3829,6 @@ func TestFindFitPredicateCallCounts(t *testing.T) { } } -// Tests score for pods on nodes with zero-request pods. -func TestZeroRequest(t *testing.T) { - noResources := v1.PodSpec{ - Containers: []v1.Container{ - {}, - }, - } - noResources1 := noResources - noResources1.NodeName = "node1" - small := v1.PodSpec{ - Containers: []v1.Container{ - { - Resources: v1.ResourceRequirements{ - Requests: v1.ResourceList{ - v1.ResourceCPU: resource.MustParse( - strconv.FormatInt(schedutil.DefaultMilliCPURequest, 10) + "m"), - v1.ResourceMemory: resource.MustParse( - strconv.FormatInt(schedutil.DefaultMemoryRequest, 10)), - }, - }, - }, - }, - } - small2 := small - small2.NodeName = "node2" - large := v1.PodSpec{ - Containers: []v1.Container{ - { - Resources: v1.ResourceRequirements{ - Requests: v1.ResourceList{ - v1.ResourceCPU: resource.MustParse( - strconv.FormatInt(schedutil.DefaultMilliCPURequest*3, 10) + "m"), - v1.ResourceMemory: resource.MustParse( - strconv.FormatInt(schedutil.DefaultMemoryRequest*3, 10)), - }, - }, - }, - }, - } - large1 := large - large1.NodeName = "node1" - large2 := large - large2.NodeName = "node2" - tests := []struct { - requestedPod *v1.Pod - existingPods []*v1.Pod - nodes []*v1.Node - name string - expectedScore int64 - }{ - { - name: "test priority of zero-request pod with node with zero-request pod", - requestedPod: &v1.Pod{Spec: noResources}, - nodes: []*v1.Node{makeNode("node1", 1000, schedutil.DefaultMemoryRequest*10), makeNode("node2", 1000, schedutil.DefaultMemoryRequest*10)}, - existingPods: []*v1.Pod{ - {Spec: large1}, {Spec: noResources1}, - {Spec: large2}, {Spec: small2}, - }, - expectedScore: 50, - }, - { - name: "test priority of nonzero-request pod with node with zero-request pod", - requestedPod: &v1.Pod{Spec: small}, - nodes: []*v1.Node{makeNode("node1", 1000, schedutil.DefaultMemoryRequest*10), makeNode("node2", 1000, schedutil.DefaultMemoryRequest*10)}, - existingPods: []*v1.Pod{ - {Spec: large1}, {Spec: noResources1}, - {Spec: large2}, {Spec: small2}, - }, - expectedScore: 125, - }, - // The point of this test is to verify that we're not just getting the same score no matter what we schedule. - { - name: "test priority of larger pod with node with zero-request pod", - requestedPod: &v1.Pod{Spec: large}, - nodes: []*v1.Node{makeNode("node1", 1000, schedutil.DefaultMemoryRequest*10), makeNode("node2", 1000, schedutil.DefaultMemoryRequest*10)}, - existingPods: []*v1.Pod{ - {Spec: large1}, {Spec: noResources1}, - {Spec: large2}, {Spec: small2}, - }, - expectedScore: 105, - }, - } - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := clientsetfake.NewClientset() - informerFactory := informers.NewSharedInformerFactory(client, 0) - - snapshot := internalcache.NewSnapshot(test.existingPods, test.nodes) - fts := feature.Features{} - pluginRegistrations := []tf.RegisterPluginFunc{ - tf.RegisterQueueSortPlugin(queuesort.Name, queuesort.New), - tf.RegisterScorePlugin(noderesources.Name, frameworkruntime.FactoryAdapter(fts, noderesources.NewFit), 1), - tf.RegisterScorePlugin(noderesources.BalancedAllocationName, frameworkruntime.FactoryAdapter(fts, noderesources.NewBalancedAllocation), 1), - tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), - } - _, ctx := ktesting.NewTestContext(t) - ctx, cancel := context.WithCancel(ctx) - defer cancel() - fwk, err := tf.NewFramework( - ctx, - pluginRegistrations, "", - frameworkruntime.WithInformerFactory(informerFactory), - frameworkruntime.WithSnapshotSharedLister(snapshot), - frameworkruntime.WithClientSet(client), - frameworkruntime.WithPodNominator(internalqueue.NewSchedulingQueue(nil, informerFactory)), - ) - if err != nil { - t.Fatalf("error creating framework: %+v", err) - } - - sched := &Scheduler{ - nodeInfoSnapshot: snapshot, - percentageOfNodesToScore: schedulerapi.DefaultPercentageOfNodesToScore, - } - sched.applyDefaultHandlers() - - state := framework.NewCycleState() - _, _, _, _, err = sched.findNodesThatFitPod(ctx, fwk, state, test.requestedPod) - if err != nil { - t.Fatalf("error filtering nodes: %+v", err) - } - nodeInfos, err := snapshot.NodeInfos().List() - if err != nil { - t.Fatalf("failed to list node from snapshot: %v", err) - } - fwk.RunPreScorePlugins(ctx, state, test.requestedPod, nodeInfos) - list, err := prioritizeNodes(ctx, nil, fwk, state, test.requestedPod, nodeInfos) - if err != nil { - t.Errorf("unexpected error: %v", err) - } - for _, hp := range list { - if hp.TotalScore != test.expectedScore { - t.Errorf("expected %d for all priorities, got list %#v", test.expectedScore, list) - } - } - }) - } -} - func Test_prioritizeNodes(t *testing.T) { imageStatus1 := []v1.ContainerImage{ {