Merge pull request #99731 from AliceZhang2016/newFramework-accept-KubeSchedulerProfile

Make runtime.NewFramework accept KubeSchedulerProfile
This commit is contained in:
Kubernetes Prow Robot 2021-03-06 12:49:48 -08:00 committed by GitHub
commit 699b38669f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 112 additions and 84 deletions

View File

@ -267,9 +267,8 @@ func TestGenericSchedulerWithExtenders(t *testing.T) {
for _, name := range test.nodes { for _, name := range test.nodes {
cache.AddNode(createNode(name)) cache.AddNode(createNode(name))
} }
fwk, err := st.NewFramework( fwk, err := st.NewFramework(
test.registerPlugins, test.registerPlugins, "",
runtime.WithClientSet(client), runtime.WithClientSet(client),
runtime.WithInformerFactory(informerFactory), runtime.WithInformerFactory(informerFactory),
runtime.WithPodNominator(internalqueue.NewPodNominator()), runtime.WithPodNominator(internalqueue.NewPodNominator()),

View File

@ -992,7 +992,7 @@ func TestGenericScheduler(t *testing.T) {
} }
snapshot := internalcache.NewSnapshot(test.pods, nodes) snapshot := internalcache.NewSnapshot(test.pods, nodes)
fwk, err := st.NewFramework( fwk, err := st.NewFramework(
test.registerPlugins, test.registerPlugins, "",
frameworkruntime.WithSnapshotSharedLister(snapshot), frameworkruntime.WithSnapshotSharedLister(snapshot),
frameworkruntime.WithInformerFactory(informerFactory), frameworkruntime.WithInformerFactory(informerFactory),
frameworkruntime.WithPodNominator(internalqueue.NewPodNominator()), frameworkruntime.WithPodNominator(internalqueue.NewPodNominator()),
@ -1057,6 +1057,7 @@ func TestFindFitAllError(t *testing.T) {
st.RegisterFilterPlugin("MatchFilter", st.NewMatchFilterPlugin), st.RegisterFilterPlugin("MatchFilter", st.NewMatchFilterPlugin),
st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
}, },
"",
frameworkruntime.WithPodNominator(internalqueue.NewPodNominator()), frameworkruntime.WithPodNominator(internalqueue.NewPodNominator()),
) )
if err != nil { if err != nil {
@ -1089,6 +1090,7 @@ func TestFindFitSomeError(t *testing.T) {
st.RegisterFilterPlugin("MatchFilter", st.NewMatchFilterPlugin), st.RegisterFilterPlugin("MatchFilter", st.NewMatchFilterPlugin),
st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
}, },
"",
frameworkruntime.WithPodNominator(internalqueue.NewPodNominator()), frameworkruntime.WithPodNominator(internalqueue.NewPodNominator()),
) )
if err != nil { if err != nil {
@ -1162,7 +1164,7 @@ func TestFindFitPredicateCallCounts(t *testing.T) {
st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
} }
fwk, err := st.NewFramework( fwk, err := st.NewFramework(
registerPlugins, registerPlugins, "",
frameworkruntime.WithPodNominator(internalqueue.NewPodNominator()), frameworkruntime.WithPodNominator(internalqueue.NewPodNominator()),
) )
if err != nil { if err != nil {
@ -1315,7 +1317,7 @@ func TestZeroRequest(t *testing.T) {
st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
} }
fwk, err := st.NewFramework( fwk, err := st.NewFramework(
pluginRegistrations, pluginRegistrations, "",
frameworkruntime.WithInformerFactory(informerFactory), frameworkruntime.WithInformerFactory(informerFactory),
frameworkruntime.WithSnapshotSharedLister(snapshot), frameworkruntime.WithSnapshotSharedLister(snapshot),
frameworkruntime.WithClientSet(client), frameworkruntime.WithClientSet(client),
@ -1421,6 +1423,7 @@ func TestFairEvaluationForNodes(t *testing.T) {
st.RegisterFilterPlugin("TrueFilter", st.NewTrueFilterPlugin), st.RegisterFilterPlugin("TrueFilter", st.NewTrueFilterPlugin),
st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
}, },
"",
frameworkruntime.WithPodNominator(internalqueue.NewPodNominator()), frameworkruntime.WithPodNominator(internalqueue.NewPodNominator()),
) )
if err != nil { if err != nil {
@ -1505,7 +1508,7 @@ func TestPreferNominatedNodeFilterCallCounts(t *testing.T) {
st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
} }
fwk, err := st.NewFramework( fwk, err := st.NewFramework(
registerPlugins, registerPlugins, "",
frameworkruntime.WithClientSet(client), frameworkruntime.WithClientSet(client),
frameworkruntime.WithPodNominator(internalqueue.NewPodNominator()), frameworkruntime.WithPodNominator(internalqueue.NewPodNominator()),
) )

View File

@ -66,7 +66,7 @@ func TestDefaultBinder(t *testing.T) {
return true, gotBinding, nil 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 { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -277,7 +277,7 @@ func TestPostFilter(t *testing.T) {
if tt.extender != nil { if tt.extender != nil {
extenders = append(extenders, tt.extender) extenders = append(extenders, tt.extender)
} }
f, err := st.NewFramework(registeredPlugins, f, err := st.NewFramework(registeredPlugins, "",
frameworkruntime.WithClientSet(cs), frameworkruntime.WithClientSet(cs),
frameworkruntime.WithEventRecorder(&events.FakeRecorder{}), frameworkruntime.WithEventRecorder(&events.FakeRecorder{}),
frameworkruntime.WithInformerFactory(informerFactory), frameworkruntime.WithInformerFactory(informerFactory),
@ -997,7 +997,7 @@ func TestDryRunPreemption(t *testing.T) {
objs := []runtime.Object{&v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: ""}}} objs := []runtime.Object{&v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: ""}}}
informerFactory := informers.NewSharedInformerFactory(clientsetfake.NewSimpleClientset(objs...), 0) informerFactory := informers.NewSharedInformerFactory(clientsetfake.NewSimpleClientset(objs...), 0)
fwk, err := st.NewFramework( fwk, err := st.NewFramework(
registeredPlugins, registeredPlugins, "",
frameworkruntime.WithPodNominator(internalqueue.NewPodNominator()), frameworkruntime.WithPodNominator(internalqueue.NewPodNominator()),
frameworkruntime.WithSnapshotSharedLister(snapshot), frameworkruntime.WithSnapshotSharedLister(snapshot),
frameworkruntime.WithInformerFactory(informerFactory), frameworkruntime.WithInformerFactory(informerFactory),
@ -1244,6 +1244,7 @@ func TestSelectBestCandidate(t *testing.T) {
st.RegisterQueueSortPlugin(queuesort.Name, queuesort.New), st.RegisterQueueSortPlugin(queuesort.Name, queuesort.New),
st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
}, },
"",
frameworkruntime.WithPodNominator(internalqueue.NewPodNominator()), frameworkruntime.WithPodNominator(internalqueue.NewPodNominator()),
frameworkruntime.WithSnapshotSharedLister(snapshot), frameworkruntime.WithSnapshotSharedLister(snapshot),
) )
@ -1644,13 +1645,13 @@ func TestPreempt(t *testing.T) {
extender.CachedNodeNameToInfo = cachedNodeInfoMap extender.CachedNodeNameToInfo = cachedNodeInfoMap
extenders = append(extenders, extender) extenders = append(extenders, extender)
} }
fwk, err := st.NewFramework( fwk, err := st.NewFramework(
[]st.RegisterPluginFunc{ []st.RegisterPluginFunc{
test.registerPlugin, test.registerPlugin,
st.RegisterQueueSortPlugin(queuesort.Name, queuesort.New), st.RegisterQueueSortPlugin(queuesort.Name, queuesort.New),
st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
}, },
"",
frameworkruntime.WithClientSet(client), frameworkruntime.WithClientSet(client),
frameworkruntime.WithEventRecorder(&events.FakeRecorder{}), frameworkruntime.WithEventRecorder(&events.FakeRecorder{}),
frameworkruntime.WithExtenders(extenders), frameworkruntime.WithExtenders(extenders),

View File

@ -334,8 +334,7 @@ func TestImageLocalityPriority(t *testing.T) {
snapshot := cache.NewSnapshot(nil, test.nodes) snapshot := cache.NewSnapshot(nil, test.nodes)
state := framework.NewCycleState() state := framework.NewCycleState()
fh, _ := runtime.NewFramework(nil, nil, runtime.WithSnapshotSharedLister(snapshot))
fh, _ := runtime.NewFramework(nil, nil, nil, runtime.WithSnapshotSharedLister(snapshot))
p, _ := New(nil, fh) p, _ := New(nil, fh)
var gotList framework.NodeScoreList var gotList framework.NodeScoreList

View File

@ -1071,8 +1071,7 @@ func TestNodeAffinityPriority(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
state := framework.NewCycleState() state := framework.NewCycleState()
fh, _ := runtime.NewFramework(nil, nil, runtime.WithSnapshotSharedLister(cache.NewSnapshot(nil, test.nodes)))
fh, _ := runtime.NewFramework(nil, nil, nil, runtime.WithSnapshotSharedLister(cache.NewSnapshot(nil, test.nodes)))
p, err := New(&test.args, fh) p, err := New(&test.args, fh)
if err != nil { if err != nil {
t.Fatalf("Creating plugin: %v", err) t.Fatalf("Creating plugin: %v", err)

View File

@ -237,7 +237,7 @@ func TestNodeLabelScore(t *testing.T) {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
state := framework.NewCycleState() state := framework.NewCycleState()
node := &v1.Node{ObjectMeta: metav1.ObjectMeta{Name: "machine1", Labels: map[string]string{"foo": "", "bar": ""}}} 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) p, err := New(&test.args, fh)
if err != nil { if err != nil {
t.Fatalf("Failed to create plugin: %+v", err) t.Fatalf("Failed to create plugin: %+v", err)
@ -271,7 +271,7 @@ func TestNodeLabelFilterWithoutNode(t *testing.T) {
func TestNodeLabelScoreWithoutNode(t *testing.T) { func TestNodeLabelScoreWithoutNode(t *testing.T) {
t.Run("node does not exist", func(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) p, err := New(&config.NodeLabelArgs{}, fh)
if err != nil { if err != nil {
t.Fatalf("Failed to create plugin: %+v", err) t.Fatalf("Failed to create plugin: %+v", err)

View File

@ -144,7 +144,7 @@ func TestNodePreferAvoidPods(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
state := framework.NewCycleState() 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) p, _ := New(nil, fh)
var gotList framework.NodeScoreList var gotList framework.NodeScoreList
for _, n := range test.nodes { for _, n := range test.nodes {

View File

@ -389,7 +389,7 @@ func TestNodeResourcesBalancedAllocation(t *testing.T) {
info.TransientInfo.TransNodeInfo.RequestedVolumes = len(test.pod.Spec.Volumes) 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) p, _ := NewBalancedAllocation(nil, fh)
for i := range test.nodes { for i := range test.nodes {

View File

@ -305,7 +305,7 @@ func TestNodeResourcesLeastAllocated(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
snapshot := cache.NewSnapshot(test.pods, test.nodes) 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) p, err := NewLeastAllocated(&test.args, fh)
if test.wantErr != nil { if test.wantErr != nil {

View File

@ -265,7 +265,7 @@ func TestNodeResourcesMostAllocated(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
snapshot := cache.NewSnapshot(test.pods, test.nodes) 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) p, err := NewMostAllocated(&test.args, fh)
if test.wantErr != nil { if test.wantErr != nil {

View File

@ -69,7 +69,7 @@ func TestRequestedToCapacityRatio(t *testing.T) {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
state := framework.NewCycleState() state := framework.NewCycleState()
snapshot := cache.NewSnapshot(test.scheduledPods, test.nodes) 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{ args := config.RequestedToCapacityRatioArgs{
Shape: []config.UtilizationShapePoint{ Shape: []config.UtilizationShapePoint{
{Utilization: 0, Score: 10}, {Utilization: 0, Score: 10},
@ -323,7 +323,7 @@ func TestResourceBinPackingSingleExtended(t *testing.T) {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
state := framework.NewCycleState() state := framework.NewCycleState()
snapshot := cache.NewSnapshot(test.pods, test.nodes) 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{ args := config.RequestedToCapacityRatioArgs{
Shape: []config.UtilizationShapePoint{ Shape: []config.UtilizationShapePoint{
{Utilization: 0, Score: 0}, {Utilization: 0, Score: 0},
@ -566,7 +566,7 @@ func TestResourceBinPackingMultipleExtended(t *testing.T) {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
state := framework.NewCycleState() state := framework.NewCycleState()
snapshot := cache.NewSnapshot(test.pods, test.nodes) 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{ args := config.RequestedToCapacityRatioArgs{
Shape: []config.UtilizationShapePoint{ Shape: []config.UtilizationShapePoint{
{Utilization: 0, Score: 0}, {Utilization: 0, Score: 0},

View File

@ -239,7 +239,7 @@ func TestPreScoreStateEmptyNodes(t *testing.T) {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
ctx := context.Background() ctx := context.Background()
informerFactory := informers.NewSharedInformerFactory(fake.NewSimpleClientset(tt.objs...), 0) 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.WithSnapshotSharedLister(cache.NewSnapshot(nil, tt.nodes)),
frameworkruntime.WithInformerFactory(informerFactory)) frameworkruntime.WithInformerFactory(informerFactory))
if err != nil { if err != nil {
@ -827,7 +827,7 @@ func BenchmarkTestDefaultEvenPodsSpreadPriority(b *testing.B) {
) )
ctx := context.Background() ctx := context.Background()
informerFactory := informers.NewSharedInformerFactory(client, 0) informerFactory := informers.NewSharedInformerFactory(client, 0)
f, err := frameworkruntime.NewFramework(nil, nil, nil, f, err := frameworkruntime.NewFramework(nil, nil,
frameworkruntime.WithSnapshotSharedLister(snapshot), frameworkruntime.WithSnapshotSharedLister(snapshot),
frameworkruntime.WithInformerFactory(informerFactory)) frameworkruntime.WithInformerFactory(informerFactory))
if err != nil { if err != nil {

View File

@ -68,7 +68,7 @@ func BenchmarkTestSelectorSpreadPriority(b *testing.B) {
b.Errorf("error waiting for informer cache sync") 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) pl, err := New(nil, fh)
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)

View File

@ -376,7 +376,7 @@ func TestSelectorSpreadScore(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("error creating informerFactory: %+v", err) 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 { if err != nil {
t.Errorf("error creating new framework handle: %+v", err) t.Errorf("error creating new framework handle: %+v", err)
} }
@ -632,7 +632,7 @@ func TestZoneSelectorSpreadPriority(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("error creating informerFactory: %+v", err) 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 { if err != nil {
t.Errorf("error creating new framework handle: %+v", err) t.Errorf("error creating new framework handle: %+v", err)
} }

View File

@ -230,7 +230,7 @@ func TestTaintTolerationScore(t *testing.T) {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
state := framework.NewCycleState() state := framework.NewCycleState()
snapshot := cache.NewSnapshot(nil, test.nodes) 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) p, _ := New(nil, fh)
status := p.(framework.PreScorePlugin).PreScore(context.Background(), state, test.pod, test.nodes) status := p.(framework.PreScorePlugin).PreScore(context.Background(), state, test.pod, test.nodes)

View File

@ -43,7 +43,7 @@ func SetupPlugin(
) framework.Plugin { ) framework.Plugin {
objs = append([]runtime.Object{&v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: ""}}}, objs...) objs = append([]runtime.Object{&v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: ""}}}, objs...)
informerFactory := informers.NewSharedInformerFactory(fake.NewSimpleClientset(objs...), 0) informerFactory := informers.NewSharedInformerFactory(fake.NewSimpleClientset(objs...), 0)
fh, err := frameworkruntime.NewFramework(nil, nil, nil, fh, err := frameworkruntime.NewFramework(nil, nil,
frameworkruntime.WithSnapshotSharedLister(sharedLister), frameworkruntime.WithSnapshotSharedLister(sharedLister),
frameworkruntime.WithInformerFactory(informerFactory)) frameworkruntime.WithInformerFactory(informerFactory))
if err != nil { if err != nil {

View File

@ -539,7 +539,7 @@ func TestVolumeBinding(t *testing.T) {
runtime.WithClientSet(client), runtime.WithClientSet(client),
runtime.WithInformerFactory(informerFactory), runtime.WithInformerFactory(informerFactory),
} }
fh, err := runtime.NewFramework(nil, nil, nil, opts...) fh, err := runtime.NewFramework(nil, nil, opts...)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -144,7 +144,6 @@ type frameworkOptions struct {
informerFactory informers.SharedInformerFactory informerFactory informers.SharedInformerFactory
snapshotSharedLister framework.SharedLister snapshotSharedLister framework.SharedLister
metricsRecorder *metricsRecorder metricsRecorder *metricsRecorder
profileName string
podNominator framework.PodNominator podNominator framework.PodNominator
extenders []framework.Extender extenders []framework.Extender
runAllFilters bool 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. // withMetricsRecorder is only used in tests.
func withMetricsRecorder(recorder *metricsRecorder) Option { func withMetricsRecorder(recorder *metricsRecorder) Option {
return func(o *frameworkOptions) { return func(o *frameworkOptions) {
@ -246,7 +238,7 @@ func WithClusterEventMap(m map[framework.ClusterEvent]sets.String) Option {
var _ framework.Framework = &frameworkImpl{} var _ framework.Framework = &frameworkImpl{}
// NewFramework initializes plugins given the configuration and the registry. // 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() options := defaultFrameworkOptions()
for _, opt := range opts { for _, opt := range opts {
opt(&options) opt(&options)
@ -261,29 +253,34 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi
eventRecorder: options.eventRecorder, eventRecorder: options.eventRecorder,
informerFactory: options.informerFactory, informerFactory: options.informerFactory,
metricsRecorder: options.metricsRecorder, metricsRecorder: options.metricsRecorder,
profileName: options.profileName,
runAllFilters: options.runAllFilters, runAllFilters: options.runAllFilters,
extenders: options.extenders, extenders: options.extenders,
PodNominator: options.podNominator, PodNominator: options.podNominator,
} }
if plugins == nil {
if profile == nil {
return f, nil
}
f.profileName = profile.SchedulerName
if profile.Plugins == nil {
return f, nil return f, nil
} }
// get needed plugins from config // get needed plugins from config
pg := f.pluginsNeeded(plugins) pg := f.pluginsNeeded(profile.Plugins)
pluginConfig := make(map[string]runtime.Object, len(args)) pluginConfig := make(map[string]runtime.Object, len(profile.PluginConfig))
for i := range args { for i := range profile.PluginConfig {
name := args[i].Name name := profile.PluginConfig[i].Name
if _, ok := pluginConfig[name]; ok { if _, ok := pluginConfig[name]; ok {
return nil, fmt.Errorf("repeated config for plugin %s", name) return nil, fmt.Errorf("repeated config for plugin %s", name)
} }
pluginConfig[name] = args[i].Args pluginConfig[name] = profile.PluginConfig[i].Args
} }
outputProfile := config.KubeSchedulerProfile{ outputProfile := config.KubeSchedulerProfile{
SchedulerName: f.profileName, SchedulerName: f.profileName,
Plugins: plugins, Plugins: profile.Plugins,
PluginConfig: make([]config.PluginConfig, 0, len(pg)), 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 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 { if err := updatePluginList(e.slicePtr, e.plugins, pluginsMap); err != nil {
return nil, err return nil, err
} }

View File

@ -338,7 +338,6 @@ var defaultWeights = map[string]int32{
scorePlugin1: 1, scorePlugin1: 1,
} }
var emptyArgs = make([]config.PluginConfig, 0)
var state = &framework.CycleState{} var state = &framework.CycleState{}
// Pod is only used for logging errors. // Pod is only used for logging errors.
@ -367,7 +366,7 @@ var (
errInjectedFilterStatus = errors.New("injected filter status") 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 { if _, ok := r[queueSortPlugin]; !ok {
r[queueSortPlugin] = newQueueSortPlugin r[queueSortPlugin] = newQueueSortPlugin
} }
@ -375,7 +374,7 @@ func newFrameworkWithQueueSortAndBind(r Registry, pl *config.Plugins, plc []conf
r[bindPlugin] = newBindPlugin r[bindPlugin] = newBindPlugin
} }
plugins := &config.Plugins{} plugins := &config.Plugins{}
plugins.Append(pl) plugins.Append(profile.Plugins)
if len(plugins.QueueSort.Enabled) == 0 { if len(plugins.QueueSort.Enabled) == 0 {
plugins.Append(&config.Plugins{ plugins.Append(&config.Plugins{
QueueSort: config.PluginSet{ 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) { func TestInitFrameworkWithScorePlugins(t *testing.T) {
@ -430,7 +430,8 @@ func TestInitFrameworkWithScorePlugins(t *testing.T) {
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { 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 { if tt.initErr && err == nil {
t.Fatal("Framework initialization should fail") t.Fatal("Framework initialization should fail")
} }
@ -482,7 +483,11 @@ func TestNewFrameworkErrors(t *testing.T) {
for _, tc := range tests { for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) { 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) { if err == nil || !strings.Contains(err.Error(), tc.wantErr) {
t.Errorf("Unexpected error, got %v, expect: %s", err, 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 { for _, name := range pluginsWithArgs {
registry[name] = recordingPluginFactory(name, result) 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 { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -789,7 +798,8 @@ func TestNewFrameworkFillEventToPluginMap(t *testing.T) {
} }
got := make(map[framework.ClusterEvent]sets.String) 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 { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -963,7 +973,11 @@ func TestRunScorePlugins(t *testing.T) {
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
// Inject the results via Args in PluginConfig. // 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 { if err != nil {
t.Fatalf("Failed to create framework for testing: %v", err) 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}}}} plugins := &config.Plugins{PreFilter: config.PluginSet{Enabled: []config.Plugin{{Name: preFilterWithExtensionsPluginName}, {Name: preFilterPluginName}}}}
t.Run("TestPreFilterPlugin", func(t *testing.T) { 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 { if err != nil {
t.Fatalf("Failed to create framework for testing: %v", err) t.Fatalf("Failed to create framework for testing: %v", err)
} }
@ -1241,8 +1256,8 @@ func TestFilterPlugins(t *testing.T) {
cfgPls.Filter.Enabled, cfgPls.Filter.Enabled,
config.Plugin{Name: pl.name}) config.Plugin{Name: pl.name})
} }
profile := config.KubeSchedulerProfile{Plugins: cfgPls}
f, err := newFrameworkWithQueueSortAndBind(registry, cfgPls, emptyArgs, WithRunAllFilters(tt.runAllFilters)) f, err := newFrameworkWithQueueSortAndBind(registry, profile, WithRunAllFilters(tt.runAllFilters))
if err != nil { if err != nil {
t.Fatalf("fail to create framework: %s", err) t.Fatalf("fail to create framework: %s", err)
} }
@ -1323,8 +1338,8 @@ func TestPostFilterPlugins(t *testing.T) {
config.Plugin{Name: pl.name}, config.Plugin{Name: pl.name},
) )
} }
profile := config.KubeSchedulerProfile{Plugins: cfgPls}
f, err := newFrameworkWithQueueSortAndBind(registry, cfgPls, emptyArgs) f, err := newFrameworkWithQueueSortAndBind(registry, profile)
if err != nil { if err != nil {
t.Fatalf("fail to create framework: %s", err) t.Fatalf("fail to create framework: %s", err)
} }
@ -1468,7 +1483,8 @@ func TestFilterPluginsWithNominatedPods(t *testing.T) {
if tt.nominatedPod != nil { if tt.nominatedPod != nil {
podNominator.AddNominatedPod(framework.NewPodInfo(tt.nominatedPod), nodeName) 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 { if err != nil {
t.Fatalf("fail to create framework: %s", err) t.Fatalf("fail to create framework: %s", err)
} }
@ -1622,8 +1638,8 @@ func TestPreBindPlugins(t *testing.T) {
config.Plugin{Name: pl.name}, config.Plugin{Name: pl.name},
) )
} }
profile := config.KubeSchedulerProfile{Plugins: configPlugins}
f, err := newFrameworkWithQueueSortAndBind(registry, configPlugins, emptyArgs) f, err := newFrameworkWithQueueSortAndBind(registry, profile)
if err != nil { if err != nil {
t.Fatalf("fail to create framework: %s", err) t.Fatalf("fail to create framework: %s", err)
} }
@ -1778,8 +1794,8 @@ func TestReservePlugins(t *testing.T) {
config.Plugin{Name: pl.name}, config.Plugin{Name: pl.name},
) )
} }
profile := config.KubeSchedulerProfile{Plugins: configPlugins}
f, err := newFrameworkWithQueueSortAndBind(registry, configPlugins, emptyArgs) f, err := newFrameworkWithQueueSortAndBind(registry, profile)
if err != nil { if err != nil {
t.Fatalf("fail to create framework: %s", err) t.Fatalf("fail to create framework: %s", err)
} }
@ -1902,8 +1918,8 @@ func TestPermitPlugins(t *testing.T) {
config.Plugin{Name: pl.name}, config.Plugin{Name: pl.name},
) )
} }
profile := config.KubeSchedulerProfile{Plugins: configPlugins}
f, err := newFrameworkWithQueueSortAndBind(registry, configPlugins, emptyArgs) f, err := newFrameworkWithQueueSortAndBind(registry, profile)
if err != nil { if err != nil {
t.Fatalf("fail to create framework: %s", err) t.Fatalf("fail to create framework: %s", err)
} }
@ -2066,7 +2082,11 @@ func TestRecordingMetrics(t *testing.T) {
PostBind: pluginSet, PostBind: pluginSet,
} }
recorder := newMetricsRecorder(100, time.Nanosecond) 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 { if err != nil {
t.Fatalf("Failed to create framework for testing: %v", err) t.Fatalf("Failed to create framework for testing: %v", err)
} }
@ -2171,7 +2191,11 @@ func TestRunBindPlugins(t *testing.T) {
} }
plugins := &config.Plugins{Bind: pluginSet} plugins := &config.Plugins{Bind: pluginSet}
recorder := newMetricsRecorder(100, time.Nanosecond) 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 { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -2224,7 +2248,8 @@ func TestPermitWaitDurationMetric(t *testing.T) {
plugins := &config.Plugins{ plugins := &config.Plugins{
Permit: config.PluginSet{Enabled: []config.Plugin{{Name: testPlugin, Weight: 1}}}, 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 { if err != nil {
t.Fatalf("Failed to create framework for testing: %v", err) t.Fatalf("Failed to create framework for testing: %v", err)
} }
@ -2277,8 +2302,8 @@ func TestWaitOnPermit(t *testing.T) {
plugins := &config.Plugins{ plugins := &config.Plugins{
Permit: config.PluginSet{Enabled: []config.Plugin{{Name: permitPlugin, Weight: 1}}}, Permit: config.PluginSet{Enabled: []config.Plugin{{Name: permitPlugin, Weight: 1}}},
} }
profile := config.KubeSchedulerProfile{Plugins: plugins}
f, err := newFrameworkWithQueueSortAndBind(r, plugins, emptyArgs) f, err := newFrameworkWithQueueSortAndBind(r, profile)
if err != nil { if err != nil {
t.Fatalf("Failed to create framework for testing: %v", err) t.Fatalf("Failed to create framework for testing: %v", err)
} }
@ -2322,7 +2347,8 @@ func TestListPlugins(t *testing.T) {
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { 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 { if err != nil {
t.Fatalf("Failed to create framework for testing: %v", err) t.Fatalf("Failed to create framework for testing: %v", err)
} }

View File

@ -37,8 +37,8 @@ type RecorderFactory func(string) events.EventRecorder
func newProfile(cfg config.KubeSchedulerProfile, r frameworkruntime.Registry, recorderFact RecorderFactory, func newProfile(cfg config.KubeSchedulerProfile, r frameworkruntime.Registry, recorderFact RecorderFactory,
opts ...frameworkruntime.Option) (framework.Framework, error) { opts ...frameworkruntime.Option) (framework.Framework, error) {
recorder := recorderFact(cfg.SchedulerName) recorder := recorderFact(cfg.SchedulerName)
opts = append(opts, frameworkruntime.WithEventRecorder(recorder), frameworkruntime.WithProfileName(cfg.SchedulerName)) opts = append(opts, frameworkruntime.WithEventRecorder(recorder))
fwk, err := frameworkruntime.NewFramework(r, cfg.Plugins, cfg.PluginConfig, opts...) fwk, err := frameworkruntime.NewFramework(r, &cfg, opts...)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -341,9 +341,9 @@ func TestSchedulerScheduleOne(t *testing.T) {
st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
) )
fwk, err := st.NewFramework(registerPluginFuncs, fwk, err := st.NewFramework(registerPluginFuncs,
testSchedulerName,
frameworkruntime.WithClientSet(client), frameworkruntime.WithClientSet(client),
frameworkruntime.WithEventRecorder(eventBroadcaster.NewRecorder(scheme.Scheme, testSchedulerName)), frameworkruntime.WithEventRecorder(eventBroadcaster.NewRecorder(scheme.Scheme, testSchedulerName)))
frameworkruntime.WithProfileName(testSchedulerName))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -821,11 +821,11 @@ func setupTestScheduler(queuedPodStore *clientcache.FIFO, scache internalcache.C
fwk, _ := st.NewFramework( fwk, _ := st.NewFramework(
fns, fns,
testSchedulerName,
frameworkruntime.WithClientSet(client), frameworkruntime.WithClientSet(client),
frameworkruntime.WithEventRecorder(recorder), frameworkruntime.WithEventRecorder(recorder),
frameworkruntime.WithInformerFactory(informerFactory), frameworkruntime.WithInformerFactory(informerFactory),
frameworkruntime.WithPodNominator(internalqueue.NewPodNominator()), frameworkruntime.WithPodNominator(internalqueue.NewPodNominator()),
frameworkruntime.WithProfileName(testSchedulerName),
) )
algo := core.NewGenericScheduler( algo := core.NewGenericScheduler(
@ -1168,7 +1168,7 @@ func TestSchedulerBinding(t *testing.T) {
fwk, err := st.NewFramework([]st.RegisterPluginFunc{ fwk, err := st.NewFramework([]st.RegisterPluginFunc{
st.RegisterQueueSortPlugin(queuesort.Name, queuesort.New), st.RegisterQueueSortPlugin(queuesort.Name, queuesort.New),
st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
}, frameworkruntime.WithClientSet(client), frameworkruntime.WithEventRecorder(&events.FakeRecorder{})) }, "", frameworkruntime.WithClientSet(client), frameworkruntime.WithEventRecorder(&events.FakeRecorder{}))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -23,13 +23,17 @@ import (
) )
// NewFramework creates a Framework from the register functions and options. // 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{} registry := runtime.Registry{}
plugins := &schedulerapi.Plugins{} plugins := &schedulerapi.Plugins{}
for _, f := range fns { for _, f := range fns {
f(&registry, plugins) f(&registry, 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() // RegisterPluginFunc is a function signature used in method RegisterFilterPlugin()