mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Merge pull request #99731 from AliceZhang2016/newFramework-accept-KubeSchedulerProfile
Make runtime.NewFramework accept KubeSchedulerProfile
This commit is contained in:
commit
699b38669f
@ -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()),
|
||||
|
@ -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()),
|
||||
)
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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),
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -69,7 +69,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},
|
||||
@ -323,7 +323,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},
|
||||
@ -566,7 +566,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},
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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 {
|
||||
|
@ -539,7 +539,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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user