From b38caa91ccd5bf721239647e0f588a083bba878c Mon Sep 17 00:00:00 2001 From: Mengxue Zhang Date: Wed, 3 Mar 2021 21:44:25 +0000 Subject: [PATCH] make runtime.NewFramework accept KubeSchedulerProfile --- pkg/scheduler/core/extender_test.go | 3 +- pkg/scheduler/core/generic_scheduler_test.go | 11 ++- .../defaultbinder/default_binder_test.go | 2 +- .../default_preemption_test.go | 7 +- .../imagelocality/image_locality_test.go | 3 +- .../nodeaffinity/node_affinity_test.go | 3 +- .../plugins/nodelabel/node_label_test.go | 4 +- .../node_prefer_avoid_pods_test.go | 2 +- .../noderesources/balanced_allocation_test.go | 2 +- .../noderesources/least_allocated_test.go | 2 +- .../noderesources/most_allocated_test.go | 2 +- .../requested_to_capacity_ratio_test.go | 6 +- .../plugins/podtopologyspread/scoring_test.go | 4 +- .../selector_spread_perf_test.go | 2 +- .../selectorspread/selector_spread_test.go | 4 +- .../tainttoleration/taint_toleration_test.go | 2 +- .../framework/plugins/testing/testing.go | 2 +- .../volumebinding/volume_binding_test.go | 2 +- pkg/scheduler/framework/runtime/framework.go | 33 ++++---- .../framework/runtime/framework_test.go | 80 ++++++++++++------- pkg/scheduler/profile/profile.go | 4 +- pkg/scheduler/scheduler_test.go | 8 +- pkg/scheduler/testing/framework_helpers.go | 8 +- 23 files changed, 112 insertions(+), 84 deletions(-) diff --git a/pkg/scheduler/core/extender_test.go b/pkg/scheduler/core/extender_test.go index afd35fd78da..3bb78d3d69e 100644 --- a/pkg/scheduler/core/extender_test.go +++ b/pkg/scheduler/core/extender_test.go @@ -267,9 +267,8 @@ func TestGenericSchedulerWithExtenders(t *testing.T) { for _, name := range test.nodes { cache.AddNode(createNode(name)) } - fwk, err := st.NewFramework( - test.registerPlugins, + test.registerPlugins, "", runtime.WithClientSet(client), runtime.WithInformerFactory(informerFactory), runtime.WithPodNominator(internalqueue.NewPodNominator()), diff --git a/pkg/scheduler/core/generic_scheduler_test.go b/pkg/scheduler/core/generic_scheduler_test.go index bfc8d96c70c..2cc27b31432 100644 --- a/pkg/scheduler/core/generic_scheduler_test.go +++ b/pkg/scheduler/core/generic_scheduler_test.go @@ -992,7 +992,7 @@ func TestGenericScheduler(t *testing.T) { } snapshot := internalcache.NewSnapshot(test.pods, nodes) fwk, err := st.NewFramework( - test.registerPlugins, + test.registerPlugins, "", frameworkruntime.WithSnapshotSharedLister(snapshot), frameworkruntime.WithInformerFactory(informerFactory), frameworkruntime.WithPodNominator(internalqueue.NewPodNominator()), @@ -1057,6 +1057,7 @@ func TestFindFitAllError(t *testing.T) { st.RegisterFilterPlugin("MatchFilter", st.NewMatchFilterPlugin), st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), }, + "", frameworkruntime.WithPodNominator(internalqueue.NewPodNominator()), ) if err != nil { @@ -1089,6 +1090,7 @@ func TestFindFitSomeError(t *testing.T) { st.RegisterFilterPlugin("MatchFilter", st.NewMatchFilterPlugin), st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), }, + "", frameworkruntime.WithPodNominator(internalqueue.NewPodNominator()), ) if err != nil { @@ -1162,7 +1164,7 @@ func TestFindFitPredicateCallCounts(t *testing.T) { st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), } fwk, err := st.NewFramework( - registerPlugins, + registerPlugins, "", frameworkruntime.WithPodNominator(internalqueue.NewPodNominator()), ) if err != nil { @@ -1315,7 +1317,7 @@ func TestZeroRequest(t *testing.T) { st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), } fwk, err := st.NewFramework( - pluginRegistrations, + pluginRegistrations, "", frameworkruntime.WithInformerFactory(informerFactory), frameworkruntime.WithSnapshotSharedLister(snapshot), frameworkruntime.WithClientSet(client), @@ -1421,6 +1423,7 @@ func TestFairEvaluationForNodes(t *testing.T) { st.RegisterFilterPlugin("TrueFilter", st.NewTrueFilterPlugin), st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), }, + "", frameworkruntime.WithPodNominator(internalqueue.NewPodNominator()), ) if err != nil { @@ -1505,7 +1508,7 @@ func TestPreferNominatedNodeFilterCallCounts(t *testing.T) { st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), } fwk, err := st.NewFramework( - registerPlugins, + registerPlugins, "", frameworkruntime.WithClientSet(client), frameworkruntime.WithPodNominator(internalqueue.NewPodNominator()), ) diff --git a/pkg/scheduler/framework/plugins/defaultbinder/default_binder_test.go b/pkg/scheduler/framework/plugins/defaultbinder/default_binder_test.go index 76d68eb08f3..0ef47239c7d 100644 --- a/pkg/scheduler/framework/plugins/defaultbinder/default_binder_test.go +++ b/pkg/scheduler/framework/plugins/defaultbinder/default_binder_test.go @@ -66,7 +66,7 @@ func TestDefaultBinder(t *testing.T) { return true, gotBinding, nil }) - fh, err := frameworkruntime.NewFramework(nil, nil, nil, frameworkruntime.WithClientSet(client)) + fh, err := frameworkruntime.NewFramework(nil, nil, frameworkruntime.WithClientSet(client)) if err != nil { t.Fatal(err) } diff --git a/pkg/scheduler/framework/plugins/defaultpreemption/default_preemption_test.go b/pkg/scheduler/framework/plugins/defaultpreemption/default_preemption_test.go index 832e4f3a0ac..9952c315fb5 100644 --- a/pkg/scheduler/framework/plugins/defaultpreemption/default_preemption_test.go +++ b/pkg/scheduler/framework/plugins/defaultpreemption/default_preemption_test.go @@ -277,7 +277,7 @@ func TestPostFilter(t *testing.T) { if tt.extender != nil { extenders = append(extenders, tt.extender) } - f, err := st.NewFramework(registeredPlugins, + f, err := st.NewFramework(registeredPlugins, "", frameworkruntime.WithClientSet(cs), frameworkruntime.WithEventRecorder(&events.FakeRecorder{}), frameworkruntime.WithInformerFactory(informerFactory), @@ -997,7 +997,7 @@ func TestDryRunPreemption(t *testing.T) { objs := []runtime.Object{&v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: ""}}} informerFactory := informers.NewSharedInformerFactory(clientsetfake.NewSimpleClientset(objs...), 0) fwk, err := st.NewFramework( - registeredPlugins, + registeredPlugins, "", frameworkruntime.WithPodNominator(internalqueue.NewPodNominator()), frameworkruntime.WithSnapshotSharedLister(snapshot), frameworkruntime.WithInformerFactory(informerFactory), @@ -1244,6 +1244,7 @@ func TestSelectBestCandidate(t *testing.T) { st.RegisterQueueSortPlugin(queuesort.Name, queuesort.New), st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), }, + "", frameworkruntime.WithPodNominator(internalqueue.NewPodNominator()), frameworkruntime.WithSnapshotSharedLister(snapshot), ) @@ -1644,13 +1645,13 @@ func TestPreempt(t *testing.T) { extender.CachedNodeNameToInfo = cachedNodeInfoMap extenders = append(extenders, extender) } - fwk, err := st.NewFramework( []st.RegisterPluginFunc{ test.registerPlugin, st.RegisterQueueSortPlugin(queuesort.Name, queuesort.New), st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), }, + "", frameworkruntime.WithClientSet(client), frameworkruntime.WithEventRecorder(&events.FakeRecorder{}), frameworkruntime.WithExtenders(extenders), diff --git a/pkg/scheduler/framework/plugins/imagelocality/image_locality_test.go b/pkg/scheduler/framework/plugins/imagelocality/image_locality_test.go index c18b68fc019..6f7446f9a64 100644 --- a/pkg/scheduler/framework/plugins/imagelocality/image_locality_test.go +++ b/pkg/scheduler/framework/plugins/imagelocality/image_locality_test.go @@ -334,8 +334,7 @@ func TestImageLocalityPriority(t *testing.T) { snapshot := cache.NewSnapshot(nil, test.nodes) state := framework.NewCycleState() - - fh, _ := runtime.NewFramework(nil, nil, nil, runtime.WithSnapshotSharedLister(snapshot)) + fh, _ := runtime.NewFramework(nil, nil, runtime.WithSnapshotSharedLister(snapshot)) p, _ := New(nil, fh) var gotList framework.NodeScoreList diff --git a/pkg/scheduler/framework/plugins/nodeaffinity/node_affinity_test.go b/pkg/scheduler/framework/plugins/nodeaffinity/node_affinity_test.go index dfe257a59b2..487125d2fd1 100644 --- a/pkg/scheduler/framework/plugins/nodeaffinity/node_affinity_test.go +++ b/pkg/scheduler/framework/plugins/nodeaffinity/node_affinity_test.go @@ -1071,8 +1071,7 @@ func TestNodeAffinityPriority(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { state := framework.NewCycleState() - - fh, _ := runtime.NewFramework(nil, nil, nil, runtime.WithSnapshotSharedLister(cache.NewSnapshot(nil, test.nodes))) + fh, _ := runtime.NewFramework(nil, nil, runtime.WithSnapshotSharedLister(cache.NewSnapshot(nil, test.nodes))) p, err := New(&test.args, fh) if err != nil { t.Fatalf("Creating plugin: %v", err) diff --git a/pkg/scheduler/framework/plugins/nodelabel/node_label_test.go b/pkg/scheduler/framework/plugins/nodelabel/node_label_test.go index 970df7d16bd..5f332321b7e 100644 --- a/pkg/scheduler/framework/plugins/nodelabel/node_label_test.go +++ b/pkg/scheduler/framework/plugins/nodelabel/node_label_test.go @@ -237,7 +237,7 @@ func TestNodeLabelScore(t *testing.T) { t.Run(test.name, func(t *testing.T) { state := framework.NewCycleState() node := &v1.Node{ObjectMeta: metav1.ObjectMeta{Name: "machine1", Labels: map[string]string{"foo": "", "bar": ""}}} - fh, _ := runtime.NewFramework(nil, nil, nil, runtime.WithSnapshotSharedLister(cache.NewSnapshot(nil, []*v1.Node{node}))) + fh, _ := runtime.NewFramework(nil, nil, runtime.WithSnapshotSharedLister(cache.NewSnapshot(nil, []*v1.Node{node}))) p, err := New(&test.args, fh) if err != nil { t.Fatalf("Failed to create plugin: %+v", err) @@ -271,7 +271,7 @@ func TestNodeLabelFilterWithoutNode(t *testing.T) { func TestNodeLabelScoreWithoutNode(t *testing.T) { t.Run("node does not exist", func(t *testing.T) { - fh, _ := runtime.NewFramework(nil, nil, nil, runtime.WithSnapshotSharedLister(cache.NewEmptySnapshot())) + fh, _ := runtime.NewFramework(nil, nil, runtime.WithSnapshotSharedLister(cache.NewEmptySnapshot())) p, err := New(&config.NodeLabelArgs{}, fh) if err != nil { t.Fatalf("Failed to create plugin: %+v", err) diff --git a/pkg/scheduler/framework/plugins/nodepreferavoidpods/node_prefer_avoid_pods_test.go b/pkg/scheduler/framework/plugins/nodepreferavoidpods/node_prefer_avoid_pods_test.go index 442ecdc341a..bd32e998adf 100644 --- a/pkg/scheduler/framework/plugins/nodepreferavoidpods/node_prefer_avoid_pods_test.go +++ b/pkg/scheduler/framework/plugins/nodepreferavoidpods/node_prefer_avoid_pods_test.go @@ -144,7 +144,7 @@ func TestNodePreferAvoidPods(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { state := framework.NewCycleState() - fh, _ := runtime.NewFramework(nil, nil, nil, runtime.WithSnapshotSharedLister(cache.NewSnapshot(nil, test.nodes))) + fh, _ := runtime.NewFramework(nil, nil, runtime.WithSnapshotSharedLister(cache.NewSnapshot(nil, test.nodes))) p, _ := New(nil, fh) var gotList framework.NodeScoreList for _, n := range test.nodes { diff --git a/pkg/scheduler/framework/plugins/noderesources/balanced_allocation_test.go b/pkg/scheduler/framework/plugins/noderesources/balanced_allocation_test.go index 676f28a3dba..ac4267d339e 100644 --- a/pkg/scheduler/framework/plugins/noderesources/balanced_allocation_test.go +++ b/pkg/scheduler/framework/plugins/noderesources/balanced_allocation_test.go @@ -389,7 +389,7 @@ func TestNodeResourcesBalancedAllocation(t *testing.T) { info.TransientInfo.TransNodeInfo.RequestedVolumes = len(test.pod.Spec.Volumes) } } - fh, _ := runtime.NewFramework(nil, nil, nil, runtime.WithSnapshotSharedLister(snapshot)) + fh, _ := runtime.NewFramework(nil, nil, runtime.WithSnapshotSharedLister(snapshot)) p, _ := NewBalancedAllocation(nil, fh) for i := range test.nodes { diff --git a/pkg/scheduler/framework/plugins/noderesources/least_allocated_test.go b/pkg/scheduler/framework/plugins/noderesources/least_allocated_test.go index c4530d8f1ad..752877ed755 100644 --- a/pkg/scheduler/framework/plugins/noderesources/least_allocated_test.go +++ b/pkg/scheduler/framework/plugins/noderesources/least_allocated_test.go @@ -305,7 +305,7 @@ func TestNodeResourcesLeastAllocated(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { snapshot := cache.NewSnapshot(test.pods, test.nodes) - fh, _ := runtime.NewFramework(nil, nil, nil, runtime.WithSnapshotSharedLister(snapshot)) + fh, _ := runtime.NewFramework(nil, nil, runtime.WithSnapshotSharedLister(snapshot)) p, err := NewLeastAllocated(&test.args, fh) if test.wantErr != nil { diff --git a/pkg/scheduler/framework/plugins/noderesources/most_allocated_test.go b/pkg/scheduler/framework/plugins/noderesources/most_allocated_test.go index fdbbe2d800c..0cf1d97352c 100644 --- a/pkg/scheduler/framework/plugins/noderesources/most_allocated_test.go +++ b/pkg/scheduler/framework/plugins/noderesources/most_allocated_test.go @@ -265,7 +265,7 @@ func TestNodeResourcesMostAllocated(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { snapshot := cache.NewSnapshot(test.pods, test.nodes) - fh, _ := runtime.NewFramework(nil, nil, nil, runtime.WithSnapshotSharedLister(snapshot)) + fh, _ := runtime.NewFramework(nil, nil, runtime.WithSnapshotSharedLister(snapshot)) p, err := NewMostAllocated(&test.args, fh) if test.wantErr != nil { diff --git a/pkg/scheduler/framework/plugins/noderesources/requested_to_capacity_ratio_test.go b/pkg/scheduler/framework/plugins/noderesources/requested_to_capacity_ratio_test.go index 17254b3fe84..4b329af2441 100644 --- a/pkg/scheduler/framework/plugins/noderesources/requested_to_capacity_ratio_test.go +++ b/pkg/scheduler/framework/plugins/noderesources/requested_to_capacity_ratio_test.go @@ -68,7 +68,7 @@ func TestRequestedToCapacityRatio(t *testing.T) { t.Run(test.name, func(t *testing.T) { state := framework.NewCycleState() snapshot := cache.NewSnapshot(test.scheduledPods, test.nodes) - fh, _ := runtime.NewFramework(nil, nil, nil, runtime.WithSnapshotSharedLister(snapshot)) + fh, _ := runtime.NewFramework(nil, nil, runtime.WithSnapshotSharedLister(snapshot)) args := config.RequestedToCapacityRatioArgs{ Shape: []config.UtilizationShapePoint{ {Utilization: 0, Score: 10}, @@ -322,7 +322,7 @@ func TestResourceBinPackingSingleExtended(t *testing.T) { t.Run(test.name, func(t *testing.T) { state := framework.NewCycleState() snapshot := cache.NewSnapshot(test.pods, test.nodes) - fh, _ := runtime.NewFramework(nil, nil, nil, runtime.WithSnapshotSharedLister(snapshot)) + fh, _ := runtime.NewFramework(nil, nil, runtime.WithSnapshotSharedLister(snapshot)) args := config.RequestedToCapacityRatioArgs{ Shape: []config.UtilizationShapePoint{ {Utilization: 0, Score: 0}, @@ -565,7 +565,7 @@ func TestResourceBinPackingMultipleExtended(t *testing.T) { t.Run(test.name, func(t *testing.T) { state := framework.NewCycleState() snapshot := cache.NewSnapshot(test.pods, test.nodes) - fh, _ := runtime.NewFramework(nil, nil, nil, runtime.WithSnapshotSharedLister(snapshot)) + fh, _ := runtime.NewFramework(nil, nil, runtime.WithSnapshotSharedLister(snapshot)) args := config.RequestedToCapacityRatioArgs{ Shape: []config.UtilizationShapePoint{ {Utilization: 0, Score: 0}, diff --git a/pkg/scheduler/framework/plugins/podtopologyspread/scoring_test.go b/pkg/scheduler/framework/plugins/podtopologyspread/scoring_test.go index 48933d6d1ec..ac9415d8e14 100644 --- a/pkg/scheduler/framework/plugins/podtopologyspread/scoring_test.go +++ b/pkg/scheduler/framework/plugins/podtopologyspread/scoring_test.go @@ -239,7 +239,7 @@ func TestPreScoreStateEmptyNodes(t *testing.T) { t.Run(tt.name, func(t *testing.T) { ctx := context.Background() informerFactory := informers.NewSharedInformerFactory(fake.NewSimpleClientset(tt.objs...), 0) - f, err := frameworkruntime.NewFramework(nil, nil, nil, + f, err := frameworkruntime.NewFramework(nil, nil, frameworkruntime.WithSnapshotSharedLister(cache.NewSnapshot(nil, tt.nodes)), frameworkruntime.WithInformerFactory(informerFactory)) if err != nil { @@ -827,7 +827,7 @@ func BenchmarkTestDefaultEvenPodsSpreadPriority(b *testing.B) { ) ctx := context.Background() informerFactory := informers.NewSharedInformerFactory(client, 0) - f, err := frameworkruntime.NewFramework(nil, nil, nil, + f, err := frameworkruntime.NewFramework(nil, nil, frameworkruntime.WithSnapshotSharedLister(snapshot), frameworkruntime.WithInformerFactory(informerFactory)) if err != nil { diff --git a/pkg/scheduler/framework/plugins/selectorspread/selector_spread_perf_test.go b/pkg/scheduler/framework/plugins/selectorspread/selector_spread_perf_test.go index 9b76d181031..e238eec90a4 100644 --- a/pkg/scheduler/framework/plugins/selectorspread/selector_spread_perf_test.go +++ b/pkg/scheduler/framework/plugins/selectorspread/selector_spread_perf_test.go @@ -68,7 +68,7 @@ func BenchmarkTestSelectorSpreadPriority(b *testing.B) { b.Errorf("error waiting for informer cache sync") } } - fh, _ := runtime.NewFramework(nil, nil, nil, runtime.WithSnapshotSharedLister(snapshot), runtime.WithInformerFactory(informerFactory)) + fh, _ := runtime.NewFramework(nil, nil, runtime.WithSnapshotSharedLister(snapshot), runtime.WithInformerFactory(informerFactory)) pl, err := New(nil, fh) if err != nil { b.Fatal(err) diff --git a/pkg/scheduler/framework/plugins/selectorspread/selector_spread_test.go b/pkg/scheduler/framework/plugins/selectorspread/selector_spread_test.go index 81f80d63651..a14684992d5 100644 --- a/pkg/scheduler/framework/plugins/selectorspread/selector_spread_test.go +++ b/pkg/scheduler/framework/plugins/selectorspread/selector_spread_test.go @@ -376,7 +376,7 @@ func TestSelectorSpreadScore(t *testing.T) { if err != nil { t.Errorf("error creating informerFactory: %+v", err) } - fh, err := frameworkruntime.NewFramework(nil, nil, nil, frameworkruntime.WithSnapshotSharedLister(snapshot), frameworkruntime.WithInformerFactory(informerFactory)) + fh, err := frameworkruntime.NewFramework(nil, nil, frameworkruntime.WithSnapshotSharedLister(snapshot), frameworkruntime.WithInformerFactory(informerFactory)) if err != nil { t.Errorf("error creating new framework handle: %+v", err) } @@ -632,7 +632,7 @@ func TestZoneSelectorSpreadPriority(t *testing.T) { if err != nil { t.Errorf("error creating informerFactory: %+v", err) } - fh, err := frameworkruntime.NewFramework(nil, nil, nil, frameworkruntime.WithSnapshotSharedLister(snapshot), frameworkruntime.WithInformerFactory(informerFactory)) + fh, err := frameworkruntime.NewFramework(nil, nil, frameworkruntime.WithSnapshotSharedLister(snapshot), frameworkruntime.WithInformerFactory(informerFactory)) if err != nil { t.Errorf("error creating new framework handle: %+v", err) } diff --git a/pkg/scheduler/framework/plugins/tainttoleration/taint_toleration_test.go b/pkg/scheduler/framework/plugins/tainttoleration/taint_toleration_test.go index 9450d36a8a6..920a3e5c029 100644 --- a/pkg/scheduler/framework/plugins/tainttoleration/taint_toleration_test.go +++ b/pkg/scheduler/framework/plugins/tainttoleration/taint_toleration_test.go @@ -230,7 +230,7 @@ func TestTaintTolerationScore(t *testing.T) { t.Run(test.name, func(t *testing.T) { state := framework.NewCycleState() snapshot := cache.NewSnapshot(nil, test.nodes) - fh, _ := runtime.NewFramework(nil, nil, nil, runtime.WithSnapshotSharedLister(snapshot)) + fh, _ := runtime.NewFramework(nil, nil, runtime.WithSnapshotSharedLister(snapshot)) p, _ := New(nil, fh) status := p.(framework.PreScorePlugin).PreScore(context.Background(), state, test.pod, test.nodes) diff --git a/pkg/scheduler/framework/plugins/testing/testing.go b/pkg/scheduler/framework/plugins/testing/testing.go index 1165cd9d9f1..72f6cfa83e2 100644 --- a/pkg/scheduler/framework/plugins/testing/testing.go +++ b/pkg/scheduler/framework/plugins/testing/testing.go @@ -43,7 +43,7 @@ func SetupPlugin( ) framework.Plugin { objs = append([]runtime.Object{&v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: ""}}}, objs...) informerFactory := informers.NewSharedInformerFactory(fake.NewSimpleClientset(objs...), 0) - fh, err := frameworkruntime.NewFramework(nil, nil, nil, + fh, err := frameworkruntime.NewFramework(nil, nil, frameworkruntime.WithSnapshotSharedLister(sharedLister), frameworkruntime.WithInformerFactory(informerFactory)) if err != nil { diff --git a/pkg/scheduler/framework/plugins/volumebinding/volume_binding_test.go b/pkg/scheduler/framework/plugins/volumebinding/volume_binding_test.go index ba3056d0e42..29a89c49467 100644 --- a/pkg/scheduler/framework/plugins/volumebinding/volume_binding_test.go +++ b/pkg/scheduler/framework/plugins/volumebinding/volume_binding_test.go @@ -257,7 +257,7 @@ func TestVolumeBinding(t *testing.T) { runtime.WithClientSet(client), runtime.WithInformerFactory(informerFactory), } - fh, err := runtime.NewFramework(nil, nil, nil, opts...) + fh, err := runtime.NewFramework(nil, nil, opts...) if err != nil { t.Fatal(err) } diff --git a/pkg/scheduler/framework/runtime/framework.go b/pkg/scheduler/framework/runtime/framework.go index cab97369933..a6305e07d03 100644 --- a/pkg/scheduler/framework/runtime/framework.go +++ b/pkg/scheduler/framework/runtime/framework.go @@ -144,7 +144,6 @@ type frameworkOptions struct { informerFactory informers.SharedInformerFactory snapshotSharedLister framework.SharedLister metricsRecorder *metricsRecorder - profileName string podNominator framework.PodNominator extenders []framework.Extender runAllFilters bool @@ -191,13 +190,6 @@ func WithRunAllFilters(runAllFilters bool) Option { } } -// WithProfileName sets the profile name. -func WithProfileName(name string) Option { - return func(o *frameworkOptions) { - o.profileName = name - } -} - // withMetricsRecorder is only used in tests. func withMetricsRecorder(recorder *metricsRecorder) Option { return func(o *frameworkOptions) { @@ -246,7 +238,7 @@ func WithClusterEventMap(m map[framework.ClusterEvent]sets.String) Option { var _ framework.Framework = &frameworkImpl{} // NewFramework initializes plugins given the configuration and the registry. -func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfig, opts ...Option) (framework.Framework, error) { +func NewFramework(r Registry, profile *config.KubeSchedulerProfile, opts ...Option) (framework.Framework, error) { options := defaultFrameworkOptions() for _, opt := range opts { opt(&options) @@ -261,29 +253,34 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi eventRecorder: options.eventRecorder, informerFactory: options.informerFactory, metricsRecorder: options.metricsRecorder, - profileName: options.profileName, runAllFilters: options.runAllFilters, extenders: options.extenders, PodNominator: options.podNominator, } - if plugins == nil { + + if profile == nil { + return f, nil + } + + f.profileName = profile.SchedulerName + if profile.Plugins == nil { return f, nil } // get needed plugins from config - pg := f.pluginsNeeded(plugins) + pg := f.pluginsNeeded(profile.Plugins) - pluginConfig := make(map[string]runtime.Object, len(args)) - for i := range args { - name := args[i].Name + pluginConfig := make(map[string]runtime.Object, len(profile.PluginConfig)) + for i := range profile.PluginConfig { + name := profile.PluginConfig[i].Name if _, ok := pluginConfig[name]; ok { return nil, fmt.Errorf("repeated config for plugin %s", name) } - pluginConfig[name] = args[i].Args + pluginConfig[name] = profile.PluginConfig[i].Args } outputProfile := config.KubeSchedulerProfile{ SchedulerName: f.profileName, - Plugins: plugins, + Plugins: profile.Plugins, PluginConfig: make([]config.PluginConfig, 0, len(pg)), } @@ -327,7 +324,7 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi totalPriority += int64(f.pluginNameToWeightMap[name]) * framework.MaxNodeScore } - for _, e := range f.getExtensionPoints(plugins) { + for _, e := range f.getExtensionPoints(profile.Plugins) { if err := updatePluginList(e.slicePtr, e.plugins, pluginsMap); err != nil { return nil, err } diff --git a/pkg/scheduler/framework/runtime/framework_test.go b/pkg/scheduler/framework/runtime/framework_test.go index c2f5c514949..a6982b035f0 100644 --- a/pkg/scheduler/framework/runtime/framework_test.go +++ b/pkg/scheduler/framework/runtime/framework_test.go @@ -338,7 +338,6 @@ var defaultWeights = map[string]int32{ scorePlugin1: 1, } -var emptyArgs = make([]config.PluginConfig, 0) var state = &framework.CycleState{} // Pod is only used for logging errors. @@ -367,7 +366,7 @@ var ( errInjectedFilterStatus = errors.New("injected filter status") ) -func newFrameworkWithQueueSortAndBind(r Registry, pl *config.Plugins, plc []config.PluginConfig, opts ...Option) (framework.Framework, error) { +func newFrameworkWithQueueSortAndBind(r Registry, profile config.KubeSchedulerProfile, opts ...Option) (framework.Framework, error) { if _, ok := r[queueSortPlugin]; !ok { r[queueSortPlugin] = newQueueSortPlugin } @@ -375,7 +374,7 @@ func newFrameworkWithQueueSortAndBind(r Registry, pl *config.Plugins, plc []conf r[bindPlugin] = newBindPlugin } plugins := &config.Plugins{} - plugins.Append(pl) + plugins.Append(profile.Plugins) if len(plugins.QueueSort.Enabled) == 0 { plugins.Append(&config.Plugins{ QueueSort: config.PluginSet{ @@ -390,7 +389,8 @@ func newFrameworkWithQueueSortAndBind(r Registry, pl *config.Plugins, plc []conf }, }) } - return NewFramework(r, plugins, plc, opts...) + profile.Plugins = plugins + return NewFramework(r, &profile, opts...) } func TestInitFrameworkWithScorePlugins(t *testing.T) { @@ -430,7 +430,8 @@ func TestInitFrameworkWithScorePlugins(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - _, err := newFrameworkWithQueueSortAndBind(registry, tt.plugins, emptyArgs) + profile := config.KubeSchedulerProfile{Plugins: tt.plugins} + _, err := newFrameworkWithQueueSortAndBind(registry, profile) if tt.initErr && err == nil { t.Fatal("Framework initialization should fail") } @@ -482,7 +483,11 @@ func TestNewFrameworkErrors(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - _, err := NewFramework(registry, tc.plugins, tc.pluginCfg) + profile := &config.KubeSchedulerProfile{ + Plugins: tc.plugins, + PluginConfig: tc.pluginCfg, + } + _, err := NewFramework(registry, profile) if err == nil || !strings.Contains(err.Error(), tc.wantErr) { t.Errorf("Unexpected error, got %v, expect: %s", err, tc.wantErr) } @@ -629,7 +634,11 @@ func TestNewFrameworkPluginDefaults(t *testing.T) { for _, name := range pluginsWithArgs { registry[name] = recordingPluginFactory(name, result) } - _, err := NewFramework(registry, &plugins, tt.pluginCfg) + profile := &config.KubeSchedulerProfile{ + Plugins: &plugins, + PluginConfig: tt.pluginCfg, + } + _, err := NewFramework(registry, profile) if err != nil { t.Fatal(err) } @@ -789,7 +798,8 @@ func TestNewFrameworkFillEventToPluginMap(t *testing.T) { } got := make(map[framework.ClusterEvent]sets.String) - _, err := newFrameworkWithQueueSortAndBind(registry, cfgPls, emptyArgs, WithClusterEventMap(got)) + profile := config.KubeSchedulerProfile{Plugins: cfgPls} + _, err := newFrameworkWithQueueSortAndBind(registry, profile, WithClusterEventMap(got)) if err != nil { t.Fatal(err) } @@ -963,7 +973,11 @@ func TestRunScorePlugins(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { // Inject the results via Args in PluginConfig. - f, err := newFrameworkWithQueueSortAndBind(registry, tt.plugins, tt.pluginConfigs) + profile := config.KubeSchedulerProfile{ + Plugins: tt.plugins, + PluginConfig: tt.pluginConfigs, + } + f, err := newFrameworkWithQueueSortAndBind(registry, profile) if err != nil { t.Fatalf("Failed to create framework for testing: %v", err) } @@ -1001,7 +1015,8 @@ func TestPreFilterPlugins(t *testing.T) { }) plugins := &config.Plugins{PreFilter: config.PluginSet{Enabled: []config.Plugin{{Name: preFilterWithExtensionsPluginName}, {Name: preFilterPluginName}}}} t.Run("TestPreFilterPlugin", func(t *testing.T) { - f, err := newFrameworkWithQueueSortAndBind(r, plugins, emptyArgs) + profile := config.KubeSchedulerProfile{Plugins: plugins} + f, err := newFrameworkWithQueueSortAndBind(r, profile) if err != nil { t.Fatalf("Failed to create framework for testing: %v", err) } @@ -1241,8 +1256,8 @@ func TestFilterPlugins(t *testing.T) { cfgPls.Filter.Enabled, config.Plugin{Name: pl.name}) } - - f, err := newFrameworkWithQueueSortAndBind(registry, cfgPls, emptyArgs, WithRunAllFilters(tt.runAllFilters)) + profile := config.KubeSchedulerProfile{Plugins: cfgPls} + f, err := newFrameworkWithQueueSortAndBind(registry, profile, WithRunAllFilters(tt.runAllFilters)) if err != nil { t.Fatalf("fail to create framework: %s", err) } @@ -1323,8 +1338,8 @@ func TestPostFilterPlugins(t *testing.T) { config.Plugin{Name: pl.name}, ) } - - f, err := newFrameworkWithQueueSortAndBind(registry, cfgPls, emptyArgs) + profile := config.KubeSchedulerProfile{Plugins: cfgPls} + f, err := newFrameworkWithQueueSortAndBind(registry, profile) if err != nil { t.Fatalf("fail to create framework: %s", err) } @@ -1468,7 +1483,8 @@ func TestFilterPluginsWithNominatedPods(t *testing.T) { if tt.nominatedPod != nil { podNominator.AddNominatedPod(framework.NewPodInfo(tt.nominatedPod), nodeName) } - f, err := newFrameworkWithQueueSortAndBind(registry, cfgPls, emptyArgs, WithPodNominator(podNominator)) + profile := config.KubeSchedulerProfile{Plugins: cfgPls} + f, err := newFrameworkWithQueueSortAndBind(registry, profile, WithPodNominator(podNominator)) if err != nil { t.Fatalf("fail to create framework: %s", err) } @@ -1622,8 +1638,8 @@ func TestPreBindPlugins(t *testing.T) { config.Plugin{Name: pl.name}, ) } - - f, err := newFrameworkWithQueueSortAndBind(registry, configPlugins, emptyArgs) + profile := config.KubeSchedulerProfile{Plugins: configPlugins} + f, err := newFrameworkWithQueueSortAndBind(registry, profile) if err != nil { t.Fatalf("fail to create framework: %s", err) } @@ -1778,8 +1794,8 @@ func TestReservePlugins(t *testing.T) { config.Plugin{Name: pl.name}, ) } - - f, err := newFrameworkWithQueueSortAndBind(registry, configPlugins, emptyArgs) + profile := config.KubeSchedulerProfile{Plugins: configPlugins} + f, err := newFrameworkWithQueueSortAndBind(registry, profile) if err != nil { t.Fatalf("fail to create framework: %s", err) } @@ -1902,8 +1918,8 @@ func TestPermitPlugins(t *testing.T) { config.Plugin{Name: pl.name}, ) } - - f, err := newFrameworkWithQueueSortAndBind(registry, configPlugins, emptyArgs) + profile := config.KubeSchedulerProfile{Plugins: configPlugins} + f, err := newFrameworkWithQueueSortAndBind(registry, profile) if err != nil { t.Fatalf("fail to create framework: %s", err) } @@ -2066,7 +2082,11 @@ func TestRecordingMetrics(t *testing.T) { PostBind: pluginSet, } recorder := newMetricsRecorder(100, time.Nanosecond) - f, err := newFrameworkWithQueueSortAndBind(r, plugins, emptyArgs, withMetricsRecorder(recorder), WithProfileName(testProfileName)) + profile := config.KubeSchedulerProfile{ + SchedulerName: testProfileName, + Plugins: plugins, + } + f, err := newFrameworkWithQueueSortAndBind(r, profile, withMetricsRecorder(recorder)) if err != nil { t.Fatalf("Failed to create framework for testing: %v", err) } @@ -2171,7 +2191,11 @@ func TestRunBindPlugins(t *testing.T) { } plugins := &config.Plugins{Bind: pluginSet} recorder := newMetricsRecorder(100, time.Nanosecond) - fwk, err := newFrameworkWithQueueSortAndBind(r, plugins, emptyArgs, withMetricsRecorder(recorder), WithProfileName(testProfileName)) + profile := config.KubeSchedulerProfile{ + SchedulerName: testProfileName, + Plugins: plugins, + } + fwk, err := newFrameworkWithQueueSortAndBind(r, profile, withMetricsRecorder(recorder)) if err != nil { t.Fatal(err) } @@ -2224,7 +2248,8 @@ func TestPermitWaitDurationMetric(t *testing.T) { plugins := &config.Plugins{ Permit: config.PluginSet{Enabled: []config.Plugin{{Name: testPlugin, Weight: 1}}}, } - f, err := newFrameworkWithQueueSortAndBind(r, plugins, emptyArgs) + profile := config.KubeSchedulerProfile{Plugins: plugins} + f, err := newFrameworkWithQueueSortAndBind(r, profile) if err != nil { t.Fatalf("Failed to create framework for testing: %v", err) } @@ -2277,8 +2302,8 @@ func TestWaitOnPermit(t *testing.T) { plugins := &config.Plugins{ Permit: config.PluginSet{Enabled: []config.Plugin{{Name: permitPlugin, Weight: 1}}}, } - - f, err := newFrameworkWithQueueSortAndBind(r, plugins, emptyArgs) + profile := config.KubeSchedulerProfile{Plugins: plugins} + f, err := newFrameworkWithQueueSortAndBind(r, profile) if err != nil { t.Fatalf("Failed to create framework for testing: %v", err) } @@ -2322,7 +2347,8 @@ func TestListPlugins(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - f, err := newFrameworkWithQueueSortAndBind(registry, tt.plugins, emptyArgs) + profile := config.KubeSchedulerProfile{Plugins: tt.plugins} + f, err := newFrameworkWithQueueSortAndBind(registry, profile) if err != nil { t.Fatalf("Failed to create framework for testing: %v", err) } diff --git a/pkg/scheduler/profile/profile.go b/pkg/scheduler/profile/profile.go index fb5752a79aa..206b1a66c2f 100644 --- a/pkg/scheduler/profile/profile.go +++ b/pkg/scheduler/profile/profile.go @@ -37,8 +37,8 @@ type RecorderFactory func(string) events.EventRecorder func newProfile(cfg config.KubeSchedulerProfile, r frameworkruntime.Registry, recorderFact RecorderFactory, opts ...frameworkruntime.Option) (framework.Framework, error) { recorder := recorderFact(cfg.SchedulerName) - opts = append(opts, frameworkruntime.WithEventRecorder(recorder), frameworkruntime.WithProfileName(cfg.SchedulerName)) - fwk, err := frameworkruntime.NewFramework(r, cfg.Plugins, cfg.PluginConfig, opts...) + opts = append(opts, frameworkruntime.WithEventRecorder(recorder)) + fwk, err := frameworkruntime.NewFramework(r, &cfg, opts...) if err != nil { return nil, err } diff --git a/pkg/scheduler/scheduler_test.go b/pkg/scheduler/scheduler_test.go index c39ad061558..c9dfd7f8cb9 100644 --- a/pkg/scheduler/scheduler_test.go +++ b/pkg/scheduler/scheduler_test.go @@ -341,9 +341,9 @@ func TestSchedulerScheduleOne(t *testing.T) { st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), ) fwk, err := st.NewFramework(registerPluginFuncs, + testSchedulerName, frameworkruntime.WithClientSet(client), - frameworkruntime.WithEventRecorder(eventBroadcaster.NewRecorder(scheme.Scheme, testSchedulerName)), - frameworkruntime.WithProfileName(testSchedulerName)) + frameworkruntime.WithEventRecorder(eventBroadcaster.NewRecorder(scheme.Scheme, testSchedulerName))) if err != nil { t.Fatal(err) } @@ -821,11 +821,11 @@ func setupTestScheduler(queuedPodStore *clientcache.FIFO, scache internalcache.C fwk, _ := st.NewFramework( fns, + testSchedulerName, frameworkruntime.WithClientSet(client), frameworkruntime.WithEventRecorder(recorder), frameworkruntime.WithInformerFactory(informerFactory), frameworkruntime.WithPodNominator(internalqueue.NewPodNominator()), - frameworkruntime.WithProfileName(testSchedulerName), ) algo := core.NewGenericScheduler( @@ -1168,7 +1168,7 @@ func TestSchedulerBinding(t *testing.T) { fwk, err := st.NewFramework([]st.RegisterPluginFunc{ st.RegisterQueueSortPlugin(queuesort.Name, queuesort.New), st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), - }, frameworkruntime.WithClientSet(client), frameworkruntime.WithEventRecorder(&events.FakeRecorder{})) + }, "", frameworkruntime.WithClientSet(client), frameworkruntime.WithEventRecorder(&events.FakeRecorder{})) if err != nil { t.Fatal(err) } diff --git a/pkg/scheduler/testing/framework_helpers.go b/pkg/scheduler/testing/framework_helpers.go index 3ac33775e0d..1e71c0b028b 100644 --- a/pkg/scheduler/testing/framework_helpers.go +++ b/pkg/scheduler/testing/framework_helpers.go @@ -23,13 +23,17 @@ import ( ) // NewFramework creates a Framework from the register functions and options. -func NewFramework(fns []RegisterPluginFunc, opts ...runtime.Option) (framework.Framework, error) { +func NewFramework(fns []RegisterPluginFunc, profileName string, opts ...runtime.Option) (framework.Framework, error) { registry := runtime.Registry{} plugins := &schedulerapi.Plugins{} for _, f := range fns { f(®istry, plugins) } - return runtime.NewFramework(registry, plugins, nil, opts...) + profile := &schedulerapi.KubeSchedulerProfile{ + SchedulerName: profileName, + Plugins: plugins, + } + return runtime.NewFramework(registry, profile, opts...) } // RegisterPluginFunc is a function signature used in method RegisterFilterPlugin()