Split scheduler framework implementation into new runtime package

This commit is contained in:
Ali Farah 2020-06-19 19:05:45 +10:00
parent e24a42f07b
commit a22e115a0e
58 changed files with 663 additions and 562 deletions

View File

@ -429,7 +429,7 @@ package_group(
name = "vendor_githubcom_prometheus_CONSUMERS", name = "vendor_githubcom_prometheus_CONSUMERS",
packages = [ packages = [
"//cluster/images/etcd-version-monitor", "//cluster/images/etcd-version-monitor",
"//pkg/scheduler/framework/v1alpha1", "//pkg/scheduler/framework/runtime",
"//pkg/volume/util/operationexecutor", "//pkg/volume/util/operationexecutor",
"//staging/src/k8s.io/apiserver/pkg/admission/metrics", "//staging/src/k8s.io/apiserver/pkg/admission/metrics",
"//staging/src/k8s.io/component-base/metrics/...", "//staging/src/k8s.io/component-base/metrics/...",

View File

@ -16,7 +16,7 @@ go_library(
"//pkg/api/legacyscheme:go_default_library", "//pkg/api/legacyscheme:go_default_library",
"//pkg/scheduler:go_default_library", "//pkg/scheduler:go_default_library",
"//pkg/scheduler/apis/config:go_default_library", "//pkg/scheduler/apis/config:go_default_library",
"//pkg/scheduler/framework/v1alpha1:go_default_library", "//pkg/scheduler/framework/runtime:go_default_library",
"//pkg/scheduler/metrics:go_default_library", "//pkg/scheduler/metrics:go_default_library",
"//pkg/scheduler/profile:go_default_library", "//pkg/scheduler/profile:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library",

View File

@ -57,13 +57,13 @@ import (
"k8s.io/kubernetes/pkg/api/legacyscheme" "k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/scheduler" "k8s.io/kubernetes/pkg/scheduler"
kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config" kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" "k8s.io/kubernetes/pkg/scheduler/framework/runtime"
"k8s.io/kubernetes/pkg/scheduler/metrics" "k8s.io/kubernetes/pkg/scheduler/metrics"
"k8s.io/kubernetes/pkg/scheduler/profile" "k8s.io/kubernetes/pkg/scheduler/profile"
) )
// Option configures a framework.Registry. // Option configures a framework.Registry.
type Option func(framework.Registry) error type Option func(runtime.Registry) error
// NewSchedulerCommand creates a *cobra.Command object with default parameters and registryOptions // NewSchedulerCommand creates a *cobra.Command object with default parameters and registryOptions
func NewSchedulerCommand(registryOptions ...Option) *cobra.Command { func NewSchedulerCommand(registryOptions ...Option) *cobra.Command {
@ -299,8 +299,8 @@ func getRecorderFactory(cc *schedulerserverconfig.CompletedConfig) profile.Recor
// WithPlugin creates an Option based on plugin name and factory. Please don't remove this function: it is used to register out-of-tree plugins, // WithPlugin creates an Option based on plugin name and factory. Please don't remove this function: it is used to register out-of-tree plugins,
// hence there are no references to it from the kubernetes scheduler code base. // hence there are no references to it from the kubernetes scheduler code base.
func WithPlugin(name string, factory framework.PluginFactory) Option { func WithPlugin(name string, factory runtime.PluginFactory) Option {
return func(registry framework.Registry) error { return func(registry runtime.Registry) error {
return registry.Register(name, factory) return registry.Register(name, factory)
} }
} }
@ -319,7 +319,7 @@ func Setup(ctx context.Context, opts *options.Options, outOfTreeRegistryOptions
// Get the completed config // Get the completed config
cc := c.Complete() cc := c.Complete()
outOfTreeRegistry := make(framework.Registry) outOfTreeRegistry := make(runtime.Registry)
for _, option := range outOfTreeRegistryOptions { for _, option := range outOfTreeRegistryOptions {
if err := option(outOfTreeRegistry); err != nil { if err := option(outOfTreeRegistry); err != nil {
return nil, nil, err return nil, nil, err

View File

@ -21,6 +21,7 @@ go_library(
"//pkg/scheduler/framework/plugins/defaultbinder:go_default_library", "//pkg/scheduler/framework/plugins/defaultbinder:go_default_library",
"//pkg/scheduler/framework/plugins/noderesources:go_default_library", "//pkg/scheduler/framework/plugins/noderesources:go_default_library",
"//pkg/scheduler/framework/plugins/queuesort:go_default_library", "//pkg/scheduler/framework/plugins/queuesort:go_default_library",
"//pkg/scheduler/framework/runtime:go_default_library",
"//pkg/scheduler/framework/v1alpha1:go_default_library", "//pkg/scheduler/framework/v1alpha1:go_default_library",
"//pkg/scheduler/internal/cache:go_default_library", "//pkg/scheduler/internal/cache:go_default_library",
"//pkg/scheduler/internal/cache/debugger:go_default_library", "//pkg/scheduler/internal/cache/debugger:go_default_library",
@ -71,6 +72,7 @@ go_test(
"//pkg/scheduler/framework/plugins/queuesort:go_default_library", "//pkg/scheduler/framework/plugins/queuesort:go_default_library",
"//pkg/scheduler/framework/plugins/serviceaffinity:go_default_library", "//pkg/scheduler/framework/plugins/serviceaffinity:go_default_library",
"//pkg/scheduler/framework/plugins/volumebinding:go_default_library", "//pkg/scheduler/framework/plugins/volumebinding:go_default_library",
"//pkg/scheduler/framework/runtime:go_default_library",
"//pkg/scheduler/framework/v1alpha1:go_default_library", "//pkg/scheduler/framework/v1alpha1:go_default_library",
"//pkg/scheduler/internal/cache:go_default_library", "//pkg/scheduler/internal/cache:go_default_library",
"//pkg/scheduler/internal/cache/fake:go_default_library", "//pkg/scheduler/internal/cache/fake:go_default_library",

View File

@ -12,6 +12,7 @@ go_library(
"//pkg/api/v1/pod:go_default_library", "//pkg/api/v1/pod:go_default_library",
"//pkg/features:go_default_library", "//pkg/features:go_default_library",
"//pkg/scheduler/apis/config:go_default_library", "//pkg/scheduler/apis/config:go_default_library",
"//pkg/scheduler/framework/runtime:go_default_library",
"//pkg/scheduler/framework/v1alpha1:go_default_library", "//pkg/scheduler/framework/v1alpha1:go_default_library",
"//pkg/scheduler/internal/cache:go_default_library", "//pkg/scheduler/internal/cache:go_default_library",
"//pkg/scheduler/internal/parallelize:go_default_library", "//pkg/scheduler/internal/parallelize:go_default_library",
@ -56,6 +57,7 @@ go_test(
"//pkg/scheduler/framework/plugins/tainttoleration:go_default_library", "//pkg/scheduler/framework/plugins/tainttoleration:go_default_library",
"//pkg/scheduler/framework/plugins/volumerestrictions:go_default_library", "//pkg/scheduler/framework/plugins/volumerestrictions:go_default_library",
"//pkg/scheduler/framework/plugins/volumezone:go_default_library", "//pkg/scheduler/framework/plugins/volumezone:go_default_library",
"//pkg/scheduler/framework/runtime:go_default_library",
"//pkg/scheduler/framework/v1alpha1:go_default_library", "//pkg/scheduler/framework/v1alpha1:go_default_library",
"//pkg/scheduler/framework/v1alpha1/fake:go_default_library", "//pkg/scheduler/framework/v1alpha1/fake:go_default_library",
"//pkg/scheduler/internal/cache:go_default_library", "//pkg/scheduler/internal/cache:go_default_library",

View File

@ -32,6 +32,7 @@ import (
schedulerapi "k8s.io/kubernetes/pkg/scheduler/apis/config" schedulerapi "k8s.io/kubernetes/pkg/scheduler/apis/config"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/defaultbinder" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/defaultbinder"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/queuesort" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/queuesort"
"k8s.io/kubernetes/pkg/scheduler/framework/runtime"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
internalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache" internalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache"
internalqueue "k8s.io/kubernetes/pkg/scheduler/internal/queue" internalqueue "k8s.io/kubernetes/pkg/scheduler/internal/queue"
@ -269,7 +270,7 @@ func TestGenericSchedulerWithExtenders(t *testing.T) {
} }
queue := internalqueue.NewSchedulingQueue(nil) queue := internalqueue.NewSchedulingQueue(nil)
fwk, err := st.NewFramework(test.registerPlugins, framework.WithClientSet(client)) fwk, err := st.NewFramework(test.registerPlugins, runtime.WithClientSet(client))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -38,6 +38,7 @@ import (
extenderv1 "k8s.io/kube-scheduler/extender/v1" extenderv1 "k8s.io/kube-scheduler/extender/v1"
podutil "k8s.io/kubernetes/pkg/api/v1/pod" podutil "k8s.io/kubernetes/pkg/api/v1/pod"
kubefeatures "k8s.io/kubernetes/pkg/features" kubefeatures "k8s.io/kubernetes/pkg/features"
"k8s.io/kubernetes/pkg/scheduler/framework/runtime"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
internalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache" internalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache"
"k8s.io/kubernetes/pkg/scheduler/internal/parallelize" "k8s.io/kubernetes/pkg/scheduler/internal/parallelize"
@ -499,7 +500,7 @@ func (g *genericScheduler) findNodesThatPassFilters(ctx context.Context, prof *p
// We record Filter extension point latency here instead of in framework.go because framework.RunFilterPlugins // We record Filter extension point latency here instead of in framework.go because framework.RunFilterPlugins
// function is called for each node, whereas we want to have an overall latency for all nodes per scheduling cycle. // function is called for each node, whereas we want to have an overall latency for all nodes per scheduling cycle.
// Note that this latency also includes latency for `addNominatedPods`, which calls framework.RunPreFilterAddPod. // Note that this latency also includes latency for `addNominatedPods`, which calls framework.RunPreFilterAddPod.
metrics.FrameworkExtensionPointDuration.WithLabelValues(framework.Filter, statusCode.String()).Observe(metrics.SinceInSeconds(beginCheckNode)) metrics.FrameworkExtensionPointDuration.WithLabelValues(runtime.Filter, statusCode.String()).Observe(metrics.SinceInSeconds(beginCheckNode))
}() }()
// Stops searching for more nodes once the configured number of feasible nodes // Stops searching for more nodes once the configured number of feasible nodes

View File

@ -54,6 +54,7 @@ import (
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/tainttoleration" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/tainttoleration"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumerestrictions" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumerestrictions"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumezone" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumezone"
frameworkruntime "k8s.io/kubernetes/pkg/scheduler/framework/runtime"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
fakeframework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1/fake" fakeframework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1/fake"
internalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache" internalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache"
@ -89,7 +90,7 @@ func NewNoPodsFilterPlugin(_ runtime.Object, _ framework.FrameworkHandle) (frame
type numericMapPlugin struct{} type numericMapPlugin struct{}
func newNumericMapPlugin() framework.PluginFactory { func newNumericMapPlugin() frameworkruntime.PluginFactory {
return func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) { return func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) {
return &numericMapPlugin{}, nil return &numericMapPlugin{}, nil
} }
@ -113,7 +114,7 @@ func (pl *numericMapPlugin) ScoreExtensions() framework.ScoreExtensions {
type reverseNumericMapPlugin struct{} type reverseNumericMapPlugin struct{}
func newReverseNumericMapPlugin() framework.PluginFactory { func newReverseNumericMapPlugin() frameworkruntime.PluginFactory {
return func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) { return func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) {
return &reverseNumericMapPlugin{}, nil return &reverseNumericMapPlugin{}, nil
} }
@ -154,7 +155,7 @@ func (pl *reverseNumericMapPlugin) NormalizeScore(_ context.Context, _ *framewor
type trueMapPlugin struct{} type trueMapPlugin struct{}
func newTrueMapPlugin() framework.PluginFactory { func newTrueMapPlugin() frameworkruntime.PluginFactory {
return func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) { return func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) {
return &trueMapPlugin{}, nil return &trueMapPlugin{}, nil
} }
@ -183,7 +184,7 @@ func (pl *trueMapPlugin) NormalizeScore(_ context.Context, _ *framework.CycleSta
type falseMapPlugin struct{} type falseMapPlugin struct{}
func newFalseMapPlugin() framework.PluginFactory { func newFalseMapPlugin() frameworkruntime.PluginFactory {
return func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) { return func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) {
return &falseMapPlugin{}, nil return &falseMapPlugin{}, nil
} }
@ -705,7 +706,7 @@ func TestGenericScheduler(t *testing.T) {
} }
snapshot := internalcache.NewSnapshot(test.pods, nodes) snapshot := internalcache.NewSnapshot(test.pods, nodes)
fwk, err := st.NewFramework(test.registerPlugins, framework.WithSnapshotSharedLister(snapshot)) fwk, err := st.NewFramework(test.registerPlugins, frameworkruntime.WithSnapshotSharedLister(snapshot))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -1026,9 +1027,9 @@ func TestZeroRequest(t *testing.T) {
} }
fwk, err := st.NewFramework( fwk, err := st.NewFramework(
pluginRegistrations, pluginRegistrations,
framework.WithInformerFactory(informerFactory), frameworkruntime.WithInformerFactory(informerFactory),
framework.WithSnapshotSharedLister(snapshot), frameworkruntime.WithSnapshotSharedLister(snapshot),
framework.WithClientSet(client), frameworkruntime.WithClientSet(client),
) )
if err != nil { if err != nil {
t.Fatalf("error creating framework: %+v", err) t.Fatalf("error creating framework: %+v", err)
@ -1538,7 +1539,7 @@ func TestSelectNodesForPreemption(t *testing.T) {
registerPlugins := append([]st.RegisterPluginFunc{registerFakeFilterFunc}, test.registerPlugins...) registerPlugins := append([]st.RegisterPluginFunc{registerFakeFilterFunc}, test.registerPlugins...)
// Use a real snapshot since it's needed in some Filter Plugin (e.g., PodAffinity) // Use a real snapshot since it's needed in some Filter Plugin (e.g., PodAffinity)
snapshot := internalcache.NewSnapshot(test.pods, nodes) snapshot := internalcache.NewSnapshot(test.pods, nodes)
fwk, err := st.NewFramework(registerPlugins, framework.WithSnapshotSharedLister(snapshot)) fwk, err := st.NewFramework(registerPlugins, frameworkruntime.WithSnapshotSharedLister(snapshot))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -1825,7 +1826,7 @@ func TestPickOneNodeForPreemption(t *testing.T) {
nodes = append(nodes, makeNode(n, schedutil.DefaultMilliCPURequest*5, schedutil.DefaultMemoryRequest*5)) nodes = append(nodes, makeNode(n, schedutil.DefaultMilliCPURequest*5, schedutil.DefaultMemoryRequest*5))
} }
snapshot := internalcache.NewSnapshot(test.pods, nodes) snapshot := internalcache.NewSnapshot(test.pods, nodes)
fwk, err := st.NewFramework(test.registerPlugins, framework.WithSnapshotSharedLister(snapshot)) fwk, err := st.NewFramework(test.registerPlugins, frameworkruntime.WithSnapshotSharedLister(snapshot))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -2338,12 +2339,12 @@ func TestPreempt(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,
framework.WithClientSet(client), frameworkruntime.WithClientSet(client),
framework.WithEventRecorder(&events.FakeRecorder{}), frameworkruntime.WithEventRecorder(&events.FakeRecorder{}),
framework.WithExtenders(extenders), frameworkruntime.WithExtenders(extenders),
framework.WithPodNominator(podNominator), frameworkruntime.WithPodNominator(podNominator),
framework.WithSnapshotSharedLister(snapshot), frameworkruntime.WithSnapshotSharedLister(snapshot),
framework.WithInformerFactory(informers.NewSharedInformerFactory(client, 0)), frameworkruntime.WithInformerFactory(informers.NewSharedInformerFactory(client, 0)),
) )
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)

View File

@ -44,6 +44,7 @@ import (
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/defaultbinder" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/defaultbinder"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/noderesources" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/noderesources"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/queuesort" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/queuesort"
frameworkruntime "k8s.io/kubernetes/pkg/scheduler/framework/runtime"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
internalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache" internalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache"
cachedebugger "k8s.io/kubernetes/pkg/scheduler/internal/cache/debugger" cachedebugger "k8s.io/kubernetes/pkg/scheduler/internal/cache/debugger"
@ -86,23 +87,23 @@ type Configurator struct {
podMaxBackoffSeconds int64 podMaxBackoffSeconds int64
profiles []schedulerapi.KubeSchedulerProfile profiles []schedulerapi.KubeSchedulerProfile
registry framework.Registry registry frameworkruntime.Registry
nodeInfoSnapshot *internalcache.Snapshot nodeInfoSnapshot *internalcache.Snapshot
extenders []schedulerapi.Extender extenders []schedulerapi.Extender
frameworkCapturer FrameworkCapturer frameworkCapturer FrameworkCapturer
} }
func (c *Configurator) buildFramework(p schedulerapi.KubeSchedulerProfile, opts ...framework.Option) (framework.Framework, error) { func (c *Configurator) buildFramework(p schedulerapi.KubeSchedulerProfile, opts ...frameworkruntime.Option) (framework.Framework, error) {
if c.frameworkCapturer != nil { if c.frameworkCapturer != nil {
c.frameworkCapturer(p) c.frameworkCapturer(p)
} }
opts = append([]framework.Option{ opts = append([]frameworkruntime.Option{
framework.WithClientSet(c.client), frameworkruntime.WithClientSet(c.client),
framework.WithInformerFactory(c.informerFactory), frameworkruntime.WithInformerFactory(c.informerFactory),
framework.WithSnapshotSharedLister(c.nodeInfoSnapshot), frameworkruntime.WithSnapshotSharedLister(c.nodeInfoSnapshot),
framework.WithRunAllFilters(c.alwaysCheckAllPredicates), frameworkruntime.WithRunAllFilters(c.alwaysCheckAllPredicates),
}, opts...) }, opts...)
return framework.NewFramework( return frameworkruntime.NewFramework(
c.registry, c.registry,
p.Plugins, p.Plugins,
p.PluginConfig, p.PluginConfig,
@ -158,7 +159,7 @@ func (c *Configurator) create() (*Scheduler, error) {
// The nominator will be passed all the way to framework instantiation. // The nominator will be passed all the way to framework instantiation.
nominator := internalqueue.NewPodNominator() nominator := internalqueue.NewPodNominator()
profiles, err := profile.NewMap(c.profiles, c.buildFramework, c.recorderFactory, profiles, err := profile.NewMap(c.profiles, c.buildFramework, c.recorderFactory,
framework.WithPodNominator(nominator)) frameworkruntime.WithPodNominator(nominator))
if err != nil { if err != nil {
return nil, fmt.Errorf("initializing profiles: %v", err) return nil, fmt.Errorf("initializing profiles: %v", err)
} }

View File

@ -44,6 +44,7 @@ import (
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodelabel" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodelabel"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/queuesort" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/queuesort"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/serviceaffinity" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/serviceaffinity"
frameworkruntime "k8s.io/kubernetes/pkg/scheduler/framework/runtime"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
internalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache" internalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache"
internalqueue "k8s.io/kubernetes/pkg/scheduler/internal/queue" internalqueue "k8s.io/kubernetes/pkg/scheduler/internal/queue"
@ -445,7 +446,7 @@ func getPodFromPriorityQueue(queue *internalqueue.PriorityQueue, pod *v1.Pod) *v
func newConfigFactoryWithFrameworkRegistry( func newConfigFactoryWithFrameworkRegistry(
client clientset.Interface, stopCh <-chan struct{}, client clientset.Interface, stopCh <-chan struct{},
registry framework.Registry) *Configurator { registry frameworkruntime.Registry) *Configurator {
informerFactory := informers.NewSharedInformerFactory(client, 0) informerFactory := informers.NewSharedInformerFactory(client, 0)
snapshot := internalcache.NewEmptySnapshot() snapshot := internalcache.NewEmptySnapshot()
recorderFactory := profile.NewRecorderFactory(events.NewBroadcaster(&events.EventSinkImpl{Interface: client.EventsV1beta1().Events("")})) recorderFactory := profile.NewRecorderFactory(events.NewBroadcaster(&events.EventSinkImpl{Interface: client.EventsV1beta1().Events("")}))

View File

@ -10,6 +10,7 @@ filegroup(
srcs = [ srcs = [
":package-srcs", ":package-srcs",
"//pkg/scheduler/framework/plugins:all-srcs", "//pkg/scheduler/framework/plugins:all-srcs",
"//pkg/scheduler/framework/runtime:all-srcs",
"//pkg/scheduler/framework/v1alpha1:all-srcs", "//pkg/scheduler/framework/v1alpha1:all-srcs",
], ],
tags = ["automanaged"], tags = ["automanaged"],

View File

@ -29,7 +29,7 @@ go_library(
"//pkg/scheduler/framework/plugins/volumebinding:go_default_library", "//pkg/scheduler/framework/plugins/volumebinding:go_default_library",
"//pkg/scheduler/framework/plugins/volumerestrictions:go_default_library", "//pkg/scheduler/framework/plugins/volumerestrictions:go_default_library",
"//pkg/scheduler/framework/plugins/volumezone:go_default_library", "//pkg/scheduler/framework/plugins/volumezone:go_default_library",
"//pkg/scheduler/framework/v1alpha1:go_default_library", "//pkg/scheduler/framework/runtime:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//vendor/k8s.io/klog/v2:go_default_library", "//vendor/k8s.io/klog/v2:go_default_library",
], ],

View File

@ -19,7 +19,7 @@ go_test(
srcs = ["default_binder_test.go"], srcs = ["default_binder_test.go"],
embed = [":go_default_library"], embed = [":go_default_library"],
deps = [ deps = [
"//pkg/scheduler/framework/v1alpha1:go_default_library", "//pkg/scheduler/framework/runtime:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",

View File

@ -27,7 +27,7 @@ import (
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes/fake" "k8s.io/client-go/kubernetes/fake"
clienttesting "k8s.io/client-go/testing" clienttesting "k8s.io/client-go/testing"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" frameworkruntime "k8s.io/kubernetes/pkg/scheduler/framework/runtime"
) )
func TestDefaultBinder(t *testing.T) { func TestDefaultBinder(t *testing.T) {
@ -66,7 +66,7 @@ func TestDefaultBinder(t *testing.T) {
return true, gotBinding, nil return true, gotBinding, nil
}) })
fh, err := framework.NewFramework(nil, nil, nil, framework.WithClientSet(client)) fh, err := frameworkruntime.NewFramework(nil, nil, nil, frameworkruntime.WithClientSet(client))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -23,6 +23,7 @@ go_test(
], ],
embed = [":go_default_library"], embed = [":go_default_library"],
deps = [ deps = [
"//pkg/scheduler/framework/runtime:go_default_library",
"//pkg/scheduler/framework/v1alpha1:go_default_library", "//pkg/scheduler/framework/v1alpha1:go_default_library",
"//pkg/scheduler/internal/cache:go_default_library", "//pkg/scheduler/internal/cache:go_default_library",
"//pkg/scheduler/internal/parallelize:go_default_library", "//pkg/scheduler/internal/parallelize:go_default_library",

View File

@ -23,6 +23,7 @@ import (
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
"k8s.io/client-go/informers" "k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes/fake" "k8s.io/client-go/kubernetes/fake"
"k8s.io/kubernetes/pkg/scheduler/framework/runtime"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
"k8s.io/kubernetes/pkg/scheduler/internal/cache" "k8s.io/kubernetes/pkg/scheduler/internal/cache"
"k8s.io/kubernetes/pkg/scheduler/internal/parallelize" "k8s.io/kubernetes/pkg/scheduler/internal/parallelize"
@ -67,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, _ := framework.NewFramework(nil, nil, nil, framework.WithSnapshotSharedLister(snapshot), framework.WithInformerFactory(informerFactory)) fh, _ := runtime.NewFramework(nil, nil, nil, runtime.WithSnapshotSharedLister(snapshot), runtime.WithInformerFactory(informerFactory))
plugin := &DefaultPodTopologySpread{handle: fh} plugin := &DefaultPodTopologySpread{handle: fh}
b.ResetTimer() b.ResetTimer()

View File

@ -29,6 +29,7 @@ import (
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/informers" "k8s.io/client-go/informers"
clientsetfake "k8s.io/client-go/kubernetes/fake" clientsetfake "k8s.io/client-go/kubernetes/fake"
frameworkruntime "k8s.io/kubernetes/pkg/scheduler/framework/runtime"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
"k8s.io/kubernetes/pkg/scheduler/internal/cache" "k8s.io/kubernetes/pkg/scheduler/internal/cache"
) )
@ -375,7 +376,7 @@ func TestDefaultPodTopologySpreadScore(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 := framework.NewFramework(nil, nil, nil, framework.WithSnapshotSharedLister(snapshot), framework.WithInformerFactory(informerFactory)) fh, err := frameworkruntime.NewFramework(nil, 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)
} }
@ -629,7 +630,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 := framework.NewFramework(nil, nil, nil, framework.WithSnapshotSharedLister(snapshot), framework.WithInformerFactory(informerFactory)) fh, err := frameworkruntime.NewFramework(nil, 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

@ -17,6 +17,7 @@ go_test(
srcs = ["image_locality_test.go"], srcs = ["image_locality_test.go"],
embed = [":go_default_library"], embed = [":go_default_library"],
deps = [ deps = [
"//pkg/scheduler/framework/runtime:go_default_library",
"//pkg/scheduler/framework/v1alpha1:go_default_library", "//pkg/scheduler/framework/v1alpha1:go_default_library",
"//pkg/scheduler/internal/cache:go_default_library", "//pkg/scheduler/internal/cache:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library",

View File

@ -25,6 +25,7 @@ import (
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/kubernetes/pkg/scheduler/framework/runtime"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
"k8s.io/kubernetes/pkg/scheduler/internal/cache" "k8s.io/kubernetes/pkg/scheduler/internal/cache"
) )
@ -334,7 +335,7 @@ func TestImageLocalityPriority(t *testing.T) {
state := framework.NewCycleState() state := framework.NewCycleState()
fh, _ := framework.NewFramework(nil, nil, nil, framework.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

@ -30,6 +30,7 @@ go_test(
embed = [":go_default_library"], embed = [":go_default_library"],
deps = [ deps = [
"//pkg/scheduler/apis/config:go_default_library", "//pkg/scheduler/apis/config:go_default_library",
"//pkg/scheduler/framework/runtime:go_default_library",
"//pkg/scheduler/framework/v1alpha1:go_default_library", "//pkg/scheduler/framework/v1alpha1:go_default_library",
"//pkg/scheduler/internal/cache:go_default_library", "//pkg/scheduler/internal/cache:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library",

View File

@ -24,6 +24,7 @@ import (
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/kubernetes/pkg/scheduler/apis/config" "k8s.io/kubernetes/pkg/scheduler/apis/config"
"k8s.io/kubernetes/pkg/scheduler/framework/runtime"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
"k8s.io/kubernetes/pkg/scheduler/internal/cache" "k8s.io/kubernetes/pkg/scheduler/internal/cache"
) )
@ -625,7 +626,7 @@ func TestPreferredAffinityWithHardPodAffinitySymmetricWeight(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, _ := framework.NewFramework(nil, nil, nil, framework.WithSnapshotSharedLister(snapshot)) fh, _ := runtime.NewFramework(nil, nil, nil, runtime.WithSnapshotSharedLister(snapshot))
args := &config.InterPodAffinityArgs{HardPodAffinityWeight: test.hardPodAffinityWeight} args := &config.InterPodAffinityArgs{HardPodAffinityWeight: test.hardPodAffinityWeight}
p, err := New(args, fh) p, err := New(args, fh)

View File

@ -35,6 +35,7 @@ go_test(
embed = [":go_default_library"], embed = [":go_default_library"],
deps = [ deps = [
"//pkg/apis/core:go_default_library", "//pkg/apis/core:go_default_library",
"//pkg/scheduler/framework/runtime:go_default_library",
"//pkg/scheduler/framework/v1alpha1:go_default_library", "//pkg/scheduler/framework/v1alpha1:go_default_library",
"//pkg/scheduler/internal/cache:go_default_library", "//pkg/scheduler/internal/cache:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library",

View File

@ -24,6 +24,7 @@ import (
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
api "k8s.io/kubernetes/pkg/apis/core" api "k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/scheduler/framework/runtime"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
"k8s.io/kubernetes/pkg/scheduler/internal/cache" "k8s.io/kubernetes/pkg/scheduler/internal/cache"
) )
@ -848,7 +849,7 @@ func TestNodeAffinityPriority(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()
fh, _ := framework.NewFramework(nil, nil, nil, framework.WithSnapshotSharedLister(cache.NewSnapshot(nil, test.nodes))) fh, _ := runtime.NewFramework(nil, 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

@ -21,6 +21,7 @@ go_test(
embed = [":go_default_library"], embed = [":go_default_library"],
deps = [ deps = [
"//pkg/scheduler/apis/config:go_default_library", "//pkg/scheduler/apis/config:go_default_library",
"//pkg/scheduler/framework/runtime:go_default_library",
"//pkg/scheduler/framework/v1alpha1:go_default_library", "//pkg/scheduler/framework/v1alpha1:go_default_library",
"//pkg/scheduler/internal/cache:go_default_library", "//pkg/scheduler/internal/cache:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library",

View File

@ -23,6 +23,7 @@ import (
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/kubernetes/pkg/scheduler/apis/config" "k8s.io/kubernetes/pkg/scheduler/apis/config"
"k8s.io/kubernetes/pkg/scheduler/framework/runtime"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
"k8s.io/kubernetes/pkg/scheduler/internal/cache" "k8s.io/kubernetes/pkg/scheduler/internal/cache"
) )
@ -236,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, _ := framework.NewFramework(nil, nil, nil, framework.WithSnapshotSharedLister(cache.NewSnapshot(nil, []*v1.Node{node}))) fh, _ := runtime.NewFramework(nil, 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)
@ -270,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, _ := framework.NewFramework(nil, nil, nil, framework.WithSnapshotSharedLister(cache.NewEmptySnapshot())) fh, _ := runtime.NewFramework(nil, 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

@ -19,6 +19,7 @@ go_test(
srcs = ["node_prefer_avoid_pods_test.go"], srcs = ["node_prefer_avoid_pods_test.go"],
embed = [":go_default_library"], embed = [":go_default_library"],
deps = [ deps = [
"//pkg/scheduler/framework/runtime:go_default_library",
"//pkg/scheduler/framework/v1alpha1:go_default_library", "//pkg/scheduler/framework/v1alpha1:go_default_library",
"//pkg/scheduler/internal/cache:go_default_library", "//pkg/scheduler/internal/cache:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library",

View File

@ -23,6 +23,7 @@ import (
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/kubernetes/pkg/scheduler/framework/runtime"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
"k8s.io/kubernetes/pkg/scheduler/internal/cache" "k8s.io/kubernetes/pkg/scheduler/internal/cache"
) )
@ -143,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, _ := framework.NewFramework(nil, nil, nil, framework.WithSnapshotSharedLister(cache.NewSnapshot(nil, test.nodes))) fh, _ := runtime.NewFramework(nil, 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

@ -58,6 +58,7 @@ go_test(
"//pkg/apis/core/v1/helper:go_default_library", "//pkg/apis/core/v1/helper:go_default_library",
"//pkg/features:go_default_library", "//pkg/features:go_default_library",
"//pkg/scheduler/apis/config:go_default_library", "//pkg/scheduler/apis/config:go_default_library",
"//pkg/scheduler/framework/runtime:go_default_library",
"//pkg/scheduler/framework/v1alpha1:go_default_library", "//pkg/scheduler/framework/v1alpha1:go_default_library",
"//pkg/scheduler/internal/cache:go_default_library", "//pkg/scheduler/internal/cache:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library",

View File

@ -27,6 +27,7 @@ import (
utilfeature "k8s.io/apiserver/pkg/util/feature" utilfeature "k8s.io/apiserver/pkg/util/feature"
featuregatetesting "k8s.io/component-base/featuregate/testing" featuregatetesting "k8s.io/component-base/featuregate/testing"
"k8s.io/kubernetes/pkg/features" "k8s.io/kubernetes/pkg/features"
"k8s.io/kubernetes/pkg/scheduler/framework/runtime"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
"k8s.io/kubernetes/pkg/scheduler/internal/cache" "k8s.io/kubernetes/pkg/scheduler/internal/cache"
) )
@ -388,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, _ := framework.NewFramework(nil, nil, nil, framework.WithSnapshotSharedLister(snapshot)) fh, _ := runtime.NewFramework(nil, 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

@ -25,6 +25,7 @@ import (
"k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/kubernetes/pkg/scheduler/apis/config" "k8s.io/kubernetes/pkg/scheduler/apis/config"
"k8s.io/kubernetes/pkg/scheduler/framework/runtime"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
"k8s.io/kubernetes/pkg/scheduler/internal/cache" "k8s.io/kubernetes/pkg/scheduler/internal/cache"
) )
@ -286,7 +287,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, _ := framework.NewFramework(nil, nil, nil, framework.WithSnapshotSharedLister(snapshot)) fh, _ := runtime.NewFramework(nil, nil, nil, runtime.WithSnapshotSharedLister(snapshot))
p, err := NewLeastAllocated(&test.args, fh) p, err := NewLeastAllocated(&test.args, fh)
if len(test.wantErr) != 0 { if len(test.wantErr) != 0 {

View File

@ -25,6 +25,7 @@ import (
"k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/kubernetes/pkg/scheduler/apis/config" "k8s.io/kubernetes/pkg/scheduler/apis/config"
"k8s.io/kubernetes/pkg/scheduler/framework/runtime"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
"k8s.io/kubernetes/pkg/scheduler/internal/cache" "k8s.io/kubernetes/pkg/scheduler/internal/cache"
) )
@ -246,7 +247,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, _ := framework.NewFramework(nil, nil, nil, framework.WithSnapshotSharedLister(snapshot)) fh, _ := runtime.NewFramework(nil, nil, nil, runtime.WithSnapshotSharedLister(snapshot))
p, err := NewMostAllocated(&test.args, fh) p, err := NewMostAllocated(&test.args, fh)
if len(test.wantErr) != 0 { if len(test.wantErr) != 0 {

View File

@ -25,6 +25,7 @@ import (
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/api/resource"
"k8s.io/kubernetes/pkg/scheduler/apis/config" "k8s.io/kubernetes/pkg/scheduler/apis/config"
"k8s.io/kubernetes/pkg/scheduler/framework/runtime"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
"k8s.io/kubernetes/pkg/scheduler/internal/cache" "k8s.io/kubernetes/pkg/scheduler/internal/cache"
) )
@ -66,7 +67,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, _ := framework.NewFramework(nil, nil, nil, framework.WithSnapshotSharedLister(snapshot)) fh, _ := runtime.NewFramework(nil, 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},
@ -318,7 +319,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, _ := framework.NewFramework(nil, nil, nil, framework.WithSnapshotSharedLister(snapshot)) fh, _ := runtime.NewFramework(nil, 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},
@ -561,7 +562,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, _ := framework.NewFramework(nil, nil, nil, framework.WithSnapshotSharedLister(snapshot)) fh, _ := runtime.NewFramework(nil, 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

@ -36,14 +36,14 @@ import (
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumebinding" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumebinding"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumerestrictions" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumerestrictions"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumezone" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumezone"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" "k8s.io/kubernetes/pkg/scheduler/framework/runtime"
) )
// NewInTreeRegistry builds the registry with all the in-tree plugins. // NewInTreeRegistry builds the registry with all the in-tree plugins.
// A scheduler that runs out of tree plugins can register additional plugins // A scheduler that runs out of tree plugins can register additional plugins
// through the WithFrameworkOutOfTreeRegistry option. // through the WithFrameworkOutOfTreeRegistry option.
func NewInTreeRegistry() framework.Registry { func NewInTreeRegistry() runtime.Registry {
return framework.Registry{ return runtime.Registry{
defaultpodtopologyspread.Name: defaultpodtopologyspread.New, defaultpodtopologyspread.Name: defaultpodtopologyspread.New,
imagelocality.Name: imagelocality.New, imagelocality.Name: imagelocality.New,
tainttoleration.Name: tainttoleration.New, tainttoleration.Name: tainttoleration.New,

View File

@ -33,6 +33,7 @@ go_test(
srcs = ["taint_toleration_test.go"], srcs = ["taint_toleration_test.go"],
embed = [":go_default_library"], embed = [":go_default_library"],
deps = [ deps = [
"//pkg/scheduler/framework/runtime:go_default_library",
"//pkg/scheduler/framework/v1alpha1:go_default_library", "//pkg/scheduler/framework/v1alpha1:go_default_library",
"//pkg/scheduler/internal/cache:go_default_library", "//pkg/scheduler/internal/cache:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library",

View File

@ -23,6 +23,7 @@ import (
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/kubernetes/pkg/scheduler/framework/runtime"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
"k8s.io/kubernetes/pkg/scheduler/internal/cache" "k8s.io/kubernetes/pkg/scheduler/internal/cache"
) )
@ -229,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, _ := framework.NewFramework(nil, nil, nil, framework.WithSnapshotSharedLister(snapshot)) fh, _ := runtime.NewFramework(nil, 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

@ -39,6 +39,7 @@ go_test(
"//pkg/controller/volume/persistentvolume/util:go_default_library", "//pkg/controller/volume/persistentvolume/util:go_default_library",
"//pkg/controller/volume/scheduling:go_default_library", "//pkg/controller/volume/scheduling:go_default_library",
"//pkg/scheduler/apis/config:go_default_library", "//pkg/scheduler/apis/config:go_default_library",
"//pkg/scheduler/framework/runtime:go_default_library",
"//pkg/scheduler/framework/v1alpha1:go_default_library", "//pkg/scheduler/framework/v1alpha1:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/api/storage/v1:go_default_library", "//staging/src/k8s.io/api/storage/v1:go_default_library",

View File

@ -29,6 +29,7 @@ import (
pvutil "k8s.io/kubernetes/pkg/controller/volume/persistentvolume/util" pvutil "k8s.io/kubernetes/pkg/controller/volume/persistentvolume/util"
"k8s.io/kubernetes/pkg/controller/volume/scheduling" "k8s.io/kubernetes/pkg/controller/volume/scheduling"
"k8s.io/kubernetes/pkg/scheduler/apis/config" "k8s.io/kubernetes/pkg/scheduler/apis/config"
"k8s.io/kubernetes/pkg/scheduler/framework/runtime"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
"k8s.io/utils/pointer" "k8s.io/utils/pointer"
) )
@ -231,11 +232,11 @@ func TestVolumeBinding(t *testing.T) {
ctx := context.Background() ctx := context.Background()
client := fake.NewSimpleClientset() client := fake.NewSimpleClientset()
informerFactory := informers.NewSharedInformerFactory(client, 0) informerFactory := informers.NewSharedInformerFactory(client, 0)
opts := []framework.Option{ opts := []runtime.Option{
framework.WithClientSet(client), runtime.WithClientSet(client),
framework.WithInformerFactory(informerFactory), runtime.WithInformerFactory(informerFactory),
} }
fh, err := framework.NewFramework(nil, nil, nil, opts...) fh, err := runtime.NewFramework(nil, nil, nil, opts...)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -0,0 +1,67 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
go_library(
name = "go_default_library",
srcs = [
"framework.go",
"metrics_recorder.go",
"registry.go",
"waiting_pods_map.go",
],
importpath = "k8s.io/kubernetes/pkg/scheduler/framework/runtime",
visibility = ["//visibility:public"],
deps = [
"//pkg/scheduler/apis/config:go_default_library",
"//pkg/scheduler/apis/config/scheme:go_default_library",
"//pkg/scheduler/framework/v1alpha1:go_default_library",
"//pkg/scheduler/internal/parallelize:go_default_library",
"//pkg/scheduler/metrics:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/json:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//staging/src/k8s.io/client-go/informers:go_default_library",
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
"//staging/src/k8s.io/client-go/tools/events:go_default_library",
"//staging/src/k8s.io/component-base/metrics:go_default_library",
"//staging/src/k8s.io/kube-scheduler/config/v1beta1:go_default_library",
"//vendor/k8s.io/klog/v2:go_default_library",
"//vendor/sigs.k8s.io/yaml:go_default_library",
],
)
go_test(
name = "go_default_test",
srcs = [
"framework_test.go",
"registry_test.go",
],
embed = [":go_default_library"],
deps = [
"//pkg/scheduler/apis/config:go_default_library",
"//pkg/scheduler/framework/v1alpha1:go_default_library",
"//pkg/scheduler/metrics:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
"//vendor/github.com/google/go-cmp/cmp:go_default_library",
"//vendor/github.com/prometheus/client_golang/prometheus:go_default_library",
"//vendor/github.com/prometheus/client_model/go:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package v1alpha1 package runtime
import ( import (
"context" "context"
@ -33,6 +33,7 @@ import (
"k8s.io/kube-scheduler/config/v1beta1" "k8s.io/kube-scheduler/config/v1beta1"
"k8s.io/kubernetes/pkg/scheduler/apis/config" "k8s.io/kubernetes/pkg/scheduler/apis/config"
"k8s.io/kubernetes/pkg/scheduler/apis/config/scheme" "k8s.io/kubernetes/pkg/scheduler/apis/config/scheme"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
"k8s.io/kubernetes/pkg/scheduler/internal/parallelize" "k8s.io/kubernetes/pkg/scheduler/internal/parallelize"
"k8s.io/kubernetes/pkg/scheduler/metrics" "k8s.io/kubernetes/pkg/scheduler/metrics"
) )
@ -59,25 +60,25 @@ const (
var configDecoder = scheme.Codecs.UniversalDecoder() var configDecoder = scheme.Codecs.UniversalDecoder()
// framework is the component responsible for initializing and running scheduler // frameworkImpl is the component responsible for initializing and running scheduler
// plugins. // plugins.
type framework struct { type frameworkImpl struct {
registry Registry registry Registry
snapshotSharedLister SharedLister snapshotSharedLister framework.SharedLister
waitingPods *waitingPodsMap waitingPods *waitingPodsMap
pluginNameToWeightMap map[string]int pluginNameToWeightMap map[string]int
queueSortPlugins []QueueSortPlugin queueSortPlugins []framework.QueueSortPlugin
preFilterPlugins []PreFilterPlugin preFilterPlugins []framework.PreFilterPlugin
filterPlugins []FilterPlugin filterPlugins []framework.FilterPlugin
postFilterPlugins []PostFilterPlugin postFilterPlugins []framework.PostFilterPlugin
preScorePlugins []PreScorePlugin preScorePlugins []framework.PreScorePlugin
scorePlugins []ScorePlugin scorePlugins []framework.ScorePlugin
reservePlugins []ReservePlugin reservePlugins []framework.ReservePlugin
preBindPlugins []PreBindPlugin preBindPlugins []framework.PreBindPlugin
bindPlugins []BindPlugin bindPlugins []framework.BindPlugin
postBindPlugins []PostBindPlugin postBindPlugins []framework.PostBindPlugin
unreservePlugins []UnreservePlugin unreservePlugins []framework.UnreservePlugin
permitPlugins []PermitPlugin permitPlugins []framework.PermitPlugin
clientSet clientset.Interface clientSet clientset.Interface
eventRecorder events.EventRecorder eventRecorder events.EventRecorder
@ -85,7 +86,7 @@ type framework struct {
metricsRecorder *metricsRecorder metricsRecorder *metricsRecorder
preemptHandle PreemptHandle preemptHandle framework.PreemptHandle
// Indicates that RunFilterPlugins should accumulate all failed statuses and not return // Indicates that RunFilterPlugins should accumulate all failed statuses and not return
// after the first failure. // after the first failure.
@ -94,7 +95,7 @@ type framework struct {
// extensionPoint encapsulates desired and applied set of plugins at a specific extension // extensionPoint encapsulates desired and applied set of plugins at a specific extension
// point. This is used to simplify iterating over all extension points supported by the // point. This is used to simplify iterating over all extension points supported by the
// framework. // frameworkImpl.
type extensionPoint struct { type extensionPoint struct {
// the set of plugins to be configured at this extension point. // the set of plugins to be configured at this extension point.
plugins *config.PluginSet plugins *config.PluginSet
@ -103,7 +104,7 @@ type extensionPoint struct {
slicePtr interface{} slicePtr interface{}
} }
func (f *framework) getExtensionPoints(plugins *config.Plugins) []extensionPoint { func (f *frameworkImpl) getExtensionPoints(plugins *config.Plugins) []extensionPoint {
return []extensionPoint{ return []extensionPoint{
{plugins.PreFilter, &f.preFilterPlugins}, {plugins.PreFilter, &f.preFilterPlugins},
{plugins.Filter, &f.filterPlugins}, {plugins.Filter, &f.filterPlugins},
@ -124,31 +125,31 @@ type frameworkOptions struct {
clientSet clientset.Interface clientSet clientset.Interface
eventRecorder events.EventRecorder eventRecorder events.EventRecorder
informerFactory informers.SharedInformerFactory informerFactory informers.SharedInformerFactory
snapshotSharedLister SharedLister snapshotSharedLister framework.SharedLister
metricsRecorder *metricsRecorder metricsRecorder *metricsRecorder
podNominator PodNominator podNominator framework.PodNominator
extenders []Extender extenders []framework.Extender
runAllFilters bool runAllFilters bool
} }
// Option for the framework. // Option for the frameworkImpl.
type Option func(*frameworkOptions) type Option func(*frameworkOptions)
// WithClientSet sets clientSet for the scheduling framework. // WithClientSet sets clientSet for the scheduling frameworkImpl.
func WithClientSet(clientSet clientset.Interface) Option { func WithClientSet(clientSet clientset.Interface) Option {
return func(o *frameworkOptions) { return func(o *frameworkOptions) {
o.clientSet = clientSet o.clientSet = clientSet
} }
} }
// WithEventRecorder sets clientSet for the scheduling framework. // WithEventRecorder sets clientSet for the scheduling frameworkImpl.
func WithEventRecorder(recorder events.EventRecorder) Option { func WithEventRecorder(recorder events.EventRecorder) Option {
return func(o *frameworkOptions) { return func(o *frameworkOptions) {
o.eventRecorder = recorder o.eventRecorder = recorder
} }
} }
// WithInformerFactory sets informer factory for the scheduling framework. // WithInformerFactory sets informer factory for the scheduling frameworkImpl.
func WithInformerFactory(informerFactory informers.SharedInformerFactory) Option { func WithInformerFactory(informerFactory informers.SharedInformerFactory) Option {
return func(o *frameworkOptions) { return func(o *frameworkOptions) {
o.informerFactory = informerFactory o.informerFactory = informerFactory
@ -156,7 +157,7 @@ func WithInformerFactory(informerFactory informers.SharedInformerFactory) Option
} }
// WithSnapshotSharedLister sets the SharedLister of the snapshot. // WithSnapshotSharedLister sets the SharedLister of the snapshot.
func WithSnapshotSharedLister(snapshotSharedLister SharedLister) Option { func WithSnapshotSharedLister(snapshotSharedLister framework.SharedLister) Option {
return func(o *frameworkOptions) { return func(o *frameworkOptions) {
o.snapshotSharedLister = snapshotSharedLister o.snapshotSharedLister = snapshotSharedLister
} }
@ -177,15 +178,15 @@ func withMetricsRecorder(recorder *metricsRecorder) Option {
} }
} }
// WithPodNominator sets podNominator for the scheduling framework. // WithPodNominator sets podNominator for the scheduling frameworkImpl.
func WithPodNominator(nominator PodNominator) Option { func WithPodNominator(nominator framework.PodNominator) Option {
return func(o *frameworkOptions) { return func(o *frameworkOptions) {
o.podNominator = nominator o.podNominator = nominator
} }
} }
// WithExtenders sets extenders for the scheduling framework. // WithExtenders sets extenders for the scheduling frameworkImpl.
func WithExtenders(extenders []Extender) Option { func WithExtenders(extenders []framework.Extender) Option {
return func(o *frameworkOptions) { return func(o *frameworkOptions) {
o.extenders = extenders o.extenders = extenders
} }
@ -195,30 +196,30 @@ var defaultFrameworkOptions = frameworkOptions{
metricsRecorder: newMetricsRecorder(1000, time.Second), metricsRecorder: newMetricsRecorder(1000, time.Second),
} }
// TODO(#91029): move this to framework runtime package. // TODO(#91029): move this to frameworkImpl runtime package.
var _ PreemptHandle = &preemptHandle{} var _ framework.PreemptHandle = &preemptHandle{}
type preemptHandle struct { type preemptHandle struct {
extenders []Extender extenders []framework.Extender
PodNominator framework.PodNominator
PluginsRunner framework.PluginsRunner
} }
// Extenders returns the registered extenders. // Extenders returns the registered extenders.
func (ph *preemptHandle) Extenders() []Extender { func (ph *preemptHandle) Extenders() []framework.Extender {
return ph.extenders return ph.extenders
} }
var _ Framework = &framework{} 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, error) { func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfig, opts ...Option) (framework.Framework, error) {
options := defaultFrameworkOptions options := defaultFrameworkOptions
for _, opt := range opts { for _, opt := range opts {
opt(&options) opt(&options)
} }
f := &framework{ f := &frameworkImpl{
registry: r, registry: r,
snapshotSharedLister: options.snapshotSharedLister, snapshotSharedLister: options.snapshotSharedLister,
pluginNameToWeightMap: make(map[string]int), pluginNameToWeightMap: make(map[string]int),
@ -250,7 +251,7 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi
pluginConfig[name] = args[i].Args pluginConfig[name] = args[i].Args
} }
pluginsMap := make(map[string]Plugin) pluginsMap := make(map[string]framework.Plugin)
var totalPriority int64 var totalPriority int64
for name, factory := range r { for name, factory := range r {
// initialize only needed plugins. // initialize only needed plugins.
@ -275,10 +276,10 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi
f.pluginNameToWeightMap[name] = 1 f.pluginNameToWeightMap[name] = 1
} }
// Checks totalPriority against MaxTotalScore to avoid overflow // Checks totalPriority against MaxTotalScore to avoid overflow
if int64(f.pluginNameToWeightMap[name])*MaxNodeScore > MaxTotalScore-totalPriority { if int64(f.pluginNameToWeightMap[name])*framework.MaxNodeScore > framework.MaxTotalScore-totalPriority {
return nil, fmt.Errorf("total score of Score plugins could overflow") return nil, fmt.Errorf("total score of Score plugins could overflow")
} }
totalPriority += int64(f.pluginNameToWeightMap[name]) * MaxNodeScore totalPriority += int64(f.pluginNameToWeightMap[name]) * framework.MaxNodeScore
} }
for _, e := range f.getExtensionPoints(plugins) { for _, e := range f.getExtensionPoints(plugins) {
@ -327,7 +328,7 @@ func getPluginArgsOrDefault(pluginConfig map[string]runtime.Object, name string)
return obj, err return obj, err
} }
func updatePluginList(pluginList interface{}, pluginSet *config.PluginSet, pluginsMap map[string]Plugin) error { func updatePluginList(pluginList interface{}, pluginSet *config.PluginSet, pluginsMap map[string]framework.Plugin) error {
if pluginSet == nil { if pluginSet == nil {
return nil return nil
} }
@ -358,15 +359,15 @@ func updatePluginList(pluginList interface{}, pluginSet *config.PluginSet, plugi
} }
// QueueSortFunc returns the function to sort pods in scheduling queue // QueueSortFunc returns the function to sort pods in scheduling queue
func (f *framework) QueueSortFunc() LessFunc { func (f *frameworkImpl) QueueSortFunc() framework.LessFunc {
if f == nil { if f == nil {
// If framework is nil, simply keep their order unchanged. // If frameworkImpl is nil, simply keep their order unchanged.
// NOTE: this is primarily for tests. // NOTE: this is primarily for tests.
return func(_, _ *QueuedPodInfo) bool { return false } return func(_, _ *framework.QueuedPodInfo) bool { return false }
} }
if len(f.queueSortPlugins) == 0 { if len(f.queueSortPlugins) == 0 {
panic("No QueueSort plugin is registered in the framework.") panic("No QueueSort plugin is registered in the frameworkImpl.")
} }
// Only one QueueSort plugin can be enabled. // Only one QueueSort plugin can be enabled.
@ -377,7 +378,7 @@ func (f *framework) QueueSortFunc() LessFunc {
// *Status and its code is set to non-success if any of the plugins returns // *Status and its code is set to non-success if any of the plugins returns
// anything but Success. If a non-success status is returned, then the scheduling // anything but Success. If a non-success status is returned, then the scheduling
// cycle is aborted. // cycle is aborted.
func (f *framework) RunPreFilterPlugins(ctx context.Context, state *CycleState, pod *v1.Pod) (status *Status) { func (f *frameworkImpl) RunPreFilterPlugins(ctx context.Context, state *framework.CycleState, pod *v1.Pod) (status *framework.Status) {
startTime := time.Now() startTime := time.Now()
defer func() { defer func() {
metrics.FrameworkExtensionPointDuration.WithLabelValues(preFilter, status.Code().String()).Observe(metrics.SinceInSeconds(startTime)) metrics.FrameworkExtensionPointDuration.WithLabelValues(preFilter, status.Code().String()).Observe(metrics.SinceInSeconds(startTime))
@ -388,18 +389,18 @@ func (f *framework) RunPreFilterPlugins(ctx context.Context, state *CycleState,
if status.IsUnschedulable() { if status.IsUnschedulable() {
msg := fmt.Sprintf("rejected by %q at prefilter: %v", pl.Name(), status.Message()) msg := fmt.Sprintf("rejected by %q at prefilter: %v", pl.Name(), status.Message())
klog.V(4).Infof(msg) klog.V(4).Infof(msg)
return NewStatus(status.Code(), msg) return framework.NewStatus(status.Code(), msg)
} }
msg := fmt.Sprintf("error while running %q prefilter plugin for pod %q: %v", pl.Name(), pod.Name, status.Message()) msg := fmt.Sprintf("error while running %q prefilter plugin for pod %q: %v", pl.Name(), pod.Name, status.Message())
klog.Error(msg) klog.Error(msg)
return NewStatus(Error, msg) return framework.NewStatus(framework.Error, msg)
} }
} }
return nil return nil
} }
func (f *framework) runPreFilterPlugin(ctx context.Context, pl PreFilterPlugin, state *CycleState, pod *v1.Pod) *Status { func (f *frameworkImpl) runPreFilterPlugin(ctx context.Context, pl framework.PreFilterPlugin, state *framework.CycleState, pod *v1.Pod) *framework.Status {
if !state.ShouldRecordPluginMetrics() { if !state.ShouldRecordPluginMetrics() {
return pl.PreFilter(ctx, state, pod) return pl.PreFilter(ctx, state, pod)
} }
@ -412,13 +413,13 @@ func (f *framework) runPreFilterPlugin(ctx context.Context, pl PreFilterPlugin,
// RunPreFilterExtensionAddPod calls the AddPod interface for the set of configured // RunPreFilterExtensionAddPod calls the AddPod interface for the set of configured
// PreFilter plugins. It returns directly if any of the plugins return any // PreFilter plugins. It returns directly if any of the plugins return any
// status other than Success. // status other than Success.
func (f *framework) RunPreFilterExtensionAddPod( func (f *frameworkImpl) RunPreFilterExtensionAddPod(
ctx context.Context, ctx context.Context,
state *CycleState, state *framework.CycleState,
podToSchedule *v1.Pod, podToSchedule *v1.Pod,
podToAdd *v1.Pod, podToAdd *v1.Pod,
nodeInfo *NodeInfo, nodeInfo *framework.NodeInfo,
) (status *Status) { ) (status *framework.Status) {
for _, pl := range f.preFilterPlugins { for _, pl := range f.preFilterPlugins {
if pl.PreFilterExtensions() == nil { if pl.PreFilterExtensions() == nil {
continue continue
@ -428,14 +429,14 @@ func (f *framework) RunPreFilterExtensionAddPod(
msg := fmt.Sprintf("error while running AddPod for plugin %q while scheduling pod %q: %v", msg := fmt.Sprintf("error while running AddPod for plugin %q while scheduling pod %q: %v",
pl.Name(), podToSchedule.Name, status.Message()) pl.Name(), podToSchedule.Name, status.Message())
klog.Error(msg) klog.Error(msg)
return NewStatus(Error, msg) return framework.NewStatus(framework.Error, msg)
} }
} }
return nil return nil
} }
func (f *framework) runPreFilterExtensionAddPod(ctx context.Context, pl PreFilterPlugin, state *CycleState, podToSchedule *v1.Pod, podToAdd *v1.Pod, nodeInfo *NodeInfo) *Status { func (f *frameworkImpl) runPreFilterExtensionAddPod(ctx context.Context, pl framework.PreFilterPlugin, state *framework.CycleState, podToSchedule *v1.Pod, podToAdd *v1.Pod, nodeInfo *framework.NodeInfo) *framework.Status {
if !state.ShouldRecordPluginMetrics() { if !state.ShouldRecordPluginMetrics() {
return pl.PreFilterExtensions().AddPod(ctx, state, podToSchedule, podToAdd, nodeInfo) return pl.PreFilterExtensions().AddPod(ctx, state, podToSchedule, podToAdd, nodeInfo)
} }
@ -448,13 +449,13 @@ func (f *framework) runPreFilterExtensionAddPod(ctx context.Context, pl PreFilte
// RunPreFilterExtensionRemovePod calls the RemovePod interface for the set of configured // RunPreFilterExtensionRemovePod calls the RemovePod interface for the set of configured
// PreFilter plugins. It returns directly if any of the plugins return any // PreFilter plugins. It returns directly if any of the plugins return any
// status other than Success. // status other than Success.
func (f *framework) RunPreFilterExtensionRemovePod( func (f *frameworkImpl) RunPreFilterExtensionRemovePod(
ctx context.Context, ctx context.Context,
state *CycleState, state *framework.CycleState,
podToSchedule *v1.Pod, podToSchedule *v1.Pod,
podToRemove *v1.Pod, podToRemove *v1.Pod,
nodeInfo *NodeInfo, nodeInfo *framework.NodeInfo,
) (status *Status) { ) (status *framework.Status) {
for _, pl := range f.preFilterPlugins { for _, pl := range f.preFilterPlugins {
if pl.PreFilterExtensions() == nil { if pl.PreFilterExtensions() == nil {
continue continue
@ -464,14 +465,14 @@ func (f *framework) RunPreFilterExtensionRemovePod(
msg := fmt.Sprintf("error while running RemovePod for plugin %q while scheduling pod %q: %v", msg := fmt.Sprintf("error while running RemovePod for plugin %q while scheduling pod %q: %v",
pl.Name(), podToSchedule.Name, status.Message()) pl.Name(), podToSchedule.Name, status.Message())
klog.Error(msg) klog.Error(msg)
return NewStatus(Error, msg) return framework.NewStatus(framework.Error, msg)
} }
} }
return nil return nil
} }
func (f *framework) runPreFilterExtensionRemovePod(ctx context.Context, pl PreFilterPlugin, state *CycleState, podToSchedule *v1.Pod, podToAdd *v1.Pod, nodeInfo *NodeInfo) *Status { func (f *frameworkImpl) runPreFilterExtensionRemovePod(ctx context.Context, pl framework.PreFilterPlugin, state *framework.CycleState, podToSchedule *v1.Pod, podToAdd *v1.Pod, nodeInfo *framework.NodeInfo) *framework.Status {
if !state.ShouldRecordPluginMetrics() { if !state.ShouldRecordPluginMetrics() {
return pl.PreFilterExtensions().RemovePod(ctx, state, podToSchedule, podToAdd, nodeInfo) return pl.PreFilterExtensions().RemovePod(ctx, state, podToSchedule, podToAdd, nodeInfo)
} }
@ -485,21 +486,21 @@ func (f *framework) runPreFilterExtensionRemovePod(ctx context.Context, pl PreFi
// the given node. If any of these plugins doesn't return "Success", the // the given node. If any of these plugins doesn't return "Success", the
// given node is not suitable for running pod. // given node is not suitable for running pod.
// Meanwhile, the failure message and status are set for the given node. // Meanwhile, the failure message and status are set for the given node.
func (f *framework) RunFilterPlugins( func (f *frameworkImpl) RunFilterPlugins(
ctx context.Context, ctx context.Context,
state *CycleState, state *framework.CycleState,
pod *v1.Pod, pod *v1.Pod,
nodeInfo *NodeInfo, nodeInfo *framework.NodeInfo,
) PluginToStatus { ) framework.PluginToStatus {
statuses := make(PluginToStatus) statuses := make(framework.PluginToStatus)
for _, pl := range f.filterPlugins { for _, pl := range f.filterPlugins {
pluginStatus := f.runFilterPlugin(ctx, pl, state, pod, nodeInfo) pluginStatus := f.runFilterPlugin(ctx, pl, state, pod, nodeInfo)
if !pluginStatus.IsSuccess() { if !pluginStatus.IsSuccess() {
if !pluginStatus.IsUnschedulable() { if !pluginStatus.IsUnschedulable() {
// Filter plugins are not supposed to return any status other than // Filter plugins are not supposed to return any status other than
// Success or Unschedulable. // Success or Unschedulable.
errStatus := NewStatus(Error, fmt.Sprintf("running %q filter plugin for pod %q: %v", pl.Name(), pod.Name, pluginStatus.Message())) errStatus := framework.NewStatus(framework.Error, fmt.Sprintf("running %q filter plugin for pod %q: %v", pl.Name(), pod.Name, pluginStatus.Message()))
return map[string]*Status{pl.Name(): errStatus} return map[string]*framework.Status{pl.Name(): errStatus}
} }
statuses[pl.Name()] = pluginStatus statuses[pl.Name()] = pluginStatus
if !f.runAllFilters { if !f.runAllFilters {
@ -512,7 +513,7 @@ func (f *framework) RunFilterPlugins(
return statuses return statuses
} }
func (f *framework) runFilterPlugin(ctx context.Context, pl FilterPlugin, state *CycleState, pod *v1.Pod, nodeInfo *NodeInfo) *Status { func (f *frameworkImpl) runFilterPlugin(ctx context.Context, pl framework.FilterPlugin, state *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) *framework.Status {
if !state.ShouldRecordPluginMetrics() { if !state.ShouldRecordPluginMetrics() {
return pl.Filter(ctx, state, pod, nodeInfo) return pl.Filter(ctx, state, pod, nodeInfo)
} }
@ -524,22 +525,22 @@ func (f *framework) runFilterPlugin(ctx context.Context, pl FilterPlugin, state
// RunPostFilterPlugins runs the set of configured PostFilter plugins until the first // RunPostFilterPlugins runs the set of configured PostFilter plugins until the first
// Success or Error is met, otherwise continues to execute all plugins. // Success or Error is met, otherwise continues to execute all plugins.
func (f *framework) RunPostFilterPlugins(ctx context.Context, state *CycleState, pod *v1.Pod, filteredNodeStatusMap NodeToStatusMap) (*PostFilterResult, *Status) { func (f *frameworkImpl) RunPostFilterPlugins(ctx context.Context, state *framework.CycleState, pod *v1.Pod, filteredNodeStatusMap framework.NodeToStatusMap) (*framework.PostFilterResult, *framework.Status) {
statuses := make(PluginToStatus) statuses := make(framework.PluginToStatus)
for _, pl := range f.postFilterPlugins { for _, pl := range f.postFilterPlugins {
r, s := f.runPostFilterPlugin(ctx, pl, state, pod, filteredNodeStatusMap) r, s := f.runPostFilterPlugin(ctx, pl, state, pod, filteredNodeStatusMap)
if s.IsSuccess() { if s.IsSuccess() {
return r, s return r, s
} else if !s.IsUnschedulable() { } else if !s.IsUnschedulable() {
// Any status other than Success or Unschedulable is Error. // Any status other than Success or Unschedulable is Error.
return nil, NewStatus(Error, s.Message()) return nil, framework.NewStatus(framework.Error, s.Message())
} }
statuses[pl.Name()] = s statuses[pl.Name()] = s
} }
return nil, statuses.Merge() return nil, statuses.Merge()
} }
func (f *framework) runPostFilterPlugin(ctx context.Context, pl PostFilterPlugin, state *CycleState, pod *v1.Pod, filteredNodeStatusMap NodeToStatusMap) (*PostFilterResult, *Status) { func (f *frameworkImpl) runPostFilterPlugin(ctx context.Context, pl framework.PostFilterPlugin, state *framework.CycleState, pod *v1.Pod, filteredNodeStatusMap framework.NodeToStatusMap) (*framework.PostFilterResult, *framework.Status) {
if !state.ShouldRecordPluginMetrics() { if !state.ShouldRecordPluginMetrics() {
return pl.PostFilter(ctx, state, pod, filteredNodeStatusMap) return pl.PostFilter(ctx, state, pod, filteredNodeStatusMap)
} }
@ -551,12 +552,12 @@ func (f *framework) runPostFilterPlugin(ctx context.Context, pl PostFilterPlugin
// RunPreScorePlugins runs the set of configured pre-score plugins. If any // RunPreScorePlugins runs the set of configured pre-score plugins. If any
// of these plugins returns any status other than "Success", the given pod is rejected. // of these plugins returns any status other than "Success", the given pod is rejected.
func (f *framework) RunPreScorePlugins( func (f *frameworkImpl) RunPreScorePlugins(
ctx context.Context, ctx context.Context,
state *CycleState, state *framework.CycleState,
pod *v1.Pod, pod *v1.Pod,
nodes []*v1.Node, nodes []*v1.Node,
) (status *Status) { ) (status *framework.Status) {
startTime := time.Now() startTime := time.Now()
defer func() { defer func() {
metrics.FrameworkExtensionPointDuration.WithLabelValues(preScore, status.Code().String()).Observe(metrics.SinceInSeconds(startTime)) metrics.FrameworkExtensionPointDuration.WithLabelValues(preScore, status.Code().String()).Observe(metrics.SinceInSeconds(startTime))
@ -566,14 +567,14 @@ func (f *framework) RunPreScorePlugins(
if !status.IsSuccess() { if !status.IsSuccess() {
msg := fmt.Sprintf("error while running %q prescore plugin for pod %q: %v", pl.Name(), pod.Name, status.Message()) msg := fmt.Sprintf("error while running %q prescore plugin for pod %q: %v", pl.Name(), pod.Name, status.Message())
klog.Error(msg) klog.Error(msg)
return NewStatus(Error, msg) return framework.NewStatus(framework.Error, msg)
} }
} }
return nil return nil
} }
func (f *framework) runPreScorePlugin(ctx context.Context, pl PreScorePlugin, state *CycleState, pod *v1.Pod, nodes []*v1.Node) *Status { func (f *frameworkImpl) runPreScorePlugin(ctx context.Context, pl framework.PreScorePlugin, state *framework.CycleState, pod *v1.Pod, nodes []*v1.Node) *framework.Status {
if !state.ShouldRecordPluginMetrics() { if !state.ShouldRecordPluginMetrics() {
return pl.PreScore(ctx, state, pod, nodes) return pl.PreScore(ctx, state, pod, nodes)
} }
@ -587,14 +588,14 @@ func (f *framework) runPreScorePlugin(ctx context.Context, pl PreScorePlugin, st
// stores for each scoring plugin name the corresponding NodeScoreList(s). // stores for each scoring plugin name the corresponding NodeScoreList(s).
// It also returns *Status, which is set to non-success if any of the plugins returns // It also returns *Status, which is set to non-success if any of the plugins returns
// a non-success status. // a non-success status.
func (f *framework) RunScorePlugins(ctx context.Context, state *CycleState, pod *v1.Pod, nodes []*v1.Node) (ps PluginToNodeScores, status *Status) { func (f *frameworkImpl) RunScorePlugins(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodes []*v1.Node) (ps framework.PluginToNodeScores, status *framework.Status) {
startTime := time.Now() startTime := time.Now()
defer func() { defer func() {
metrics.FrameworkExtensionPointDuration.WithLabelValues(score, status.Code().String()).Observe(metrics.SinceInSeconds(startTime)) metrics.FrameworkExtensionPointDuration.WithLabelValues(score, status.Code().String()).Observe(metrics.SinceInSeconds(startTime))
}() }()
pluginToNodeScores := make(PluginToNodeScores, len(f.scorePlugins)) pluginToNodeScores := make(framework.PluginToNodeScores, len(f.scorePlugins))
for _, pl := range f.scorePlugins { for _, pl := range f.scorePlugins {
pluginToNodeScores[pl.Name()] = make(NodeScoreList, len(nodes)) pluginToNodeScores[pl.Name()] = make(framework.NodeScoreList, len(nodes))
} }
ctx, cancel := context.WithCancel(ctx) ctx, cancel := context.WithCancel(ctx)
errCh := parallelize.NewErrorChannel() errCh := parallelize.NewErrorChannel()
@ -608,7 +609,7 @@ func (f *framework) RunScorePlugins(ctx context.Context, state *CycleState, pod
errCh.SendErrorWithCancel(fmt.Errorf(status.Message()), cancel) errCh.SendErrorWithCancel(fmt.Errorf(status.Message()), cancel)
return return
} }
pluginToNodeScores[pl.Name()][index] = NodeScore{ pluginToNodeScores[pl.Name()][index] = framework.NodeScore{
Name: nodeName, Name: nodeName,
Score: int64(s), Score: int64(s),
} }
@ -617,7 +618,7 @@ func (f *framework) RunScorePlugins(ctx context.Context, state *CycleState, pod
if err := errCh.ReceiveError(); err != nil { if err := errCh.ReceiveError(); err != nil {
msg := fmt.Sprintf("error while running score plugin for pod %q: %v", pod.Name, err) msg := fmt.Sprintf("error while running score plugin for pod %q: %v", pod.Name, err)
klog.Error(msg) klog.Error(msg)
return nil, NewStatus(Error, msg) return nil, framework.NewStatus(framework.Error, msg)
} }
// Run NormalizeScore method for each ScorePlugin in parallel. // Run NormalizeScore method for each ScorePlugin in parallel.
@ -637,7 +638,7 @@ func (f *framework) RunScorePlugins(ctx context.Context, state *CycleState, pod
if err := errCh.ReceiveError(); err != nil { if err := errCh.ReceiveError(); err != nil {
msg := fmt.Sprintf("error while running normalize score plugin for pod %q: %v", pod.Name, err) msg := fmt.Sprintf("error while running normalize score plugin for pod %q: %v", pod.Name, err)
klog.Error(msg) klog.Error(msg)
return nil, NewStatus(Error, msg) return nil, framework.NewStatus(framework.Error, msg)
} }
// Apply score defaultWeights for each ScorePlugin in parallel. // Apply score defaultWeights for each ScorePlugin in parallel.
@ -649,8 +650,8 @@ func (f *framework) RunScorePlugins(ctx context.Context, state *CycleState, pod
for i, nodeScore := range nodeScoreList { for i, nodeScore := range nodeScoreList {
// return error if score plugin returns invalid score. // return error if score plugin returns invalid score.
if nodeScore.Score > int64(MaxNodeScore) || nodeScore.Score < int64(MinNodeScore) { if nodeScore.Score > int64(framework.MaxNodeScore) || nodeScore.Score < int64(framework.MinNodeScore) {
err := fmt.Errorf("score plugin %q returns an invalid score %v, it should in the range of [%v, %v] after normalizing", pl.Name(), nodeScore.Score, MinNodeScore, MaxNodeScore) err := fmt.Errorf("score plugin %q returns an invalid score %v, it should in the range of [%v, %v] after normalizing", pl.Name(), nodeScore.Score, framework.MinNodeScore, framework.MaxNodeScore)
errCh.SendErrorWithCancel(err, cancel) errCh.SendErrorWithCancel(err, cancel)
return return
} }
@ -660,13 +661,13 @@ func (f *framework) RunScorePlugins(ctx context.Context, state *CycleState, pod
if err := errCh.ReceiveError(); err != nil { if err := errCh.ReceiveError(); err != nil {
msg := fmt.Sprintf("error while applying score defaultWeights for pod %q: %v", pod.Name, err) msg := fmt.Sprintf("error while applying score defaultWeights for pod %q: %v", pod.Name, err)
klog.Error(msg) klog.Error(msg)
return nil, NewStatus(Error, msg) return nil, framework.NewStatus(framework.Error, msg)
} }
return pluginToNodeScores, nil return pluginToNodeScores, nil
} }
func (f *framework) runScorePlugin(ctx context.Context, pl ScorePlugin, state *CycleState, pod *v1.Pod, nodeName string) (int64, *Status) { func (f *frameworkImpl) runScorePlugin(ctx context.Context, pl framework.ScorePlugin, state *framework.CycleState, pod *v1.Pod, nodeName string) (int64, *framework.Status) {
if !state.ShouldRecordPluginMetrics() { if !state.ShouldRecordPluginMetrics() {
return pl.Score(ctx, state, pod, nodeName) return pl.Score(ctx, state, pod, nodeName)
} }
@ -676,7 +677,7 @@ func (f *framework) runScorePlugin(ctx context.Context, pl ScorePlugin, state *C
return s, status return s, status
} }
func (f *framework) runScoreExtension(ctx context.Context, pl ScorePlugin, state *CycleState, pod *v1.Pod, nodeScoreList NodeScoreList) *Status { func (f *frameworkImpl) runScoreExtension(ctx context.Context, pl framework.ScorePlugin, state *framework.CycleState, pod *v1.Pod, nodeScoreList framework.NodeScoreList) *framework.Status {
if !state.ShouldRecordPluginMetrics() { if !state.ShouldRecordPluginMetrics() {
return pl.ScoreExtensions().NormalizeScore(ctx, state, pod, nodeScoreList) return pl.ScoreExtensions().NormalizeScore(ctx, state, pod, nodeScoreList)
} }
@ -689,7 +690,7 @@ func (f *framework) runScoreExtension(ctx context.Context, pl ScorePlugin, state
// RunPreBindPlugins runs the set of configured prebind plugins. It returns a // RunPreBindPlugins runs the set of configured prebind plugins. It returns a
// failure (bool) if any of the plugins returns an error. It also returns an // failure (bool) if any of the plugins returns an error. It also returns an
// error containing the rejection message or the error occurred in the plugin. // error containing the rejection message or the error occurred in the plugin.
func (f *framework) RunPreBindPlugins(ctx context.Context, state *CycleState, pod *v1.Pod, nodeName string) (status *Status) { func (f *frameworkImpl) RunPreBindPlugins(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeName string) (status *framework.Status) {
startTime := time.Now() startTime := time.Now()
defer func() { defer func() {
metrics.FrameworkExtensionPointDuration.WithLabelValues(preBind, status.Code().String()).Observe(metrics.SinceInSeconds(startTime)) metrics.FrameworkExtensionPointDuration.WithLabelValues(preBind, status.Code().String()).Observe(metrics.SinceInSeconds(startTime))
@ -699,13 +700,13 @@ func (f *framework) RunPreBindPlugins(ctx context.Context, state *CycleState, po
if !status.IsSuccess() { if !status.IsSuccess() {
msg := fmt.Sprintf("error while running %q prebind plugin for pod %q: %v", pl.Name(), pod.Name, status.Message()) msg := fmt.Sprintf("error while running %q prebind plugin for pod %q: %v", pl.Name(), pod.Name, status.Message())
klog.Error(msg) klog.Error(msg)
return NewStatus(Error, msg) return framework.NewStatus(framework.Error, msg)
} }
} }
return nil return nil
} }
func (f *framework) runPreBindPlugin(ctx context.Context, pl PreBindPlugin, state *CycleState, pod *v1.Pod, nodeName string) *Status { func (f *frameworkImpl) runPreBindPlugin(ctx context.Context, pl framework.PreBindPlugin, state *framework.CycleState, pod *v1.Pod, nodeName string) *framework.Status {
if !state.ShouldRecordPluginMetrics() { if !state.ShouldRecordPluginMetrics() {
return pl.PreBind(ctx, state, pod, nodeName) return pl.PreBind(ctx, state, pod, nodeName)
} }
@ -716,30 +717,30 @@ func (f *framework) runPreBindPlugin(ctx context.Context, pl PreBindPlugin, stat
} }
// RunBindPlugins runs the set of configured bind plugins until one returns a non `Skip` status. // RunBindPlugins runs the set of configured bind plugins until one returns a non `Skip` status.
func (f *framework) RunBindPlugins(ctx context.Context, state *CycleState, pod *v1.Pod, nodeName string) (status *Status) { func (f *frameworkImpl) RunBindPlugins(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeName string) (status *framework.Status) {
startTime := time.Now() startTime := time.Now()
defer func() { defer func() {
metrics.FrameworkExtensionPointDuration.WithLabelValues(bind, status.Code().String()).Observe(metrics.SinceInSeconds(startTime)) metrics.FrameworkExtensionPointDuration.WithLabelValues(bind, status.Code().String()).Observe(metrics.SinceInSeconds(startTime))
}() }()
if len(f.bindPlugins) == 0 { if len(f.bindPlugins) == 0 {
return NewStatus(Skip, "") return framework.NewStatus(framework.Skip, "")
} }
for _, bp := range f.bindPlugins { for _, bp := range f.bindPlugins {
status = f.runBindPlugin(ctx, bp, state, pod, nodeName) status = f.runBindPlugin(ctx, bp, state, pod, nodeName)
if status != nil && status.Code() == Skip { if status != nil && status.Code() == framework.Skip {
continue continue
} }
if !status.IsSuccess() { if !status.IsSuccess() {
msg := fmt.Sprintf("plugin %q failed to bind pod \"%v/%v\": %v", bp.Name(), pod.Namespace, pod.Name, status.Message()) msg := fmt.Sprintf("plugin %q failed to bind pod \"%v/%v\": %v", bp.Name(), pod.Namespace, pod.Name, status.Message())
klog.Error(msg) klog.Error(msg)
return NewStatus(Error, msg) return framework.NewStatus(framework.Error, msg)
} }
return status return status
} }
return status return status
} }
func (f *framework) runBindPlugin(ctx context.Context, bp BindPlugin, state *CycleState, pod *v1.Pod, nodeName string) *Status { func (f *frameworkImpl) runBindPlugin(ctx context.Context, bp framework.BindPlugin, state *framework.CycleState, pod *v1.Pod, nodeName string) *framework.Status {
if !state.ShouldRecordPluginMetrics() { if !state.ShouldRecordPluginMetrics() {
return bp.Bind(ctx, state, pod, nodeName) return bp.Bind(ctx, state, pod, nodeName)
} }
@ -750,17 +751,17 @@ func (f *framework) runBindPlugin(ctx context.Context, bp BindPlugin, state *Cyc
} }
// RunPostBindPlugins runs the set of configured postbind plugins. // RunPostBindPlugins runs the set of configured postbind plugins.
func (f *framework) RunPostBindPlugins(ctx context.Context, state *CycleState, pod *v1.Pod, nodeName string) { func (f *frameworkImpl) RunPostBindPlugins(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeName string) {
startTime := time.Now() startTime := time.Now()
defer func() { defer func() {
metrics.FrameworkExtensionPointDuration.WithLabelValues(postBind, Success.String()).Observe(metrics.SinceInSeconds(startTime)) metrics.FrameworkExtensionPointDuration.WithLabelValues(postBind, framework.Success.String()).Observe(metrics.SinceInSeconds(startTime))
}() }()
for _, pl := range f.postBindPlugins { for _, pl := range f.postBindPlugins {
f.runPostBindPlugin(ctx, pl, state, pod, nodeName) f.runPostBindPlugin(ctx, pl, state, pod, nodeName)
} }
} }
func (f *framework) runPostBindPlugin(ctx context.Context, pl PostBindPlugin, state *CycleState, pod *v1.Pod, nodeName string) { func (f *frameworkImpl) runPostBindPlugin(ctx context.Context, pl framework.PostBindPlugin, state *framework.CycleState, pod *v1.Pod, nodeName string) {
if !state.ShouldRecordPluginMetrics() { if !state.ShouldRecordPluginMetrics() {
pl.PostBind(ctx, state, pod, nodeName) pl.PostBind(ctx, state, pod, nodeName)
return return
@ -773,7 +774,7 @@ func (f *framework) runPostBindPlugin(ctx context.Context, pl PostBindPlugin, st
// RunReservePlugins runs the set of configured reserve plugins. If any of these // RunReservePlugins runs the set of configured reserve plugins. If any of these
// plugins returns an error, it does not continue running the remaining ones and // plugins returns an error, it does not continue running the remaining ones and
// returns the error. In such case, pod will not be scheduled. // returns the error. In such case, pod will not be scheduled.
func (f *framework) RunReservePlugins(ctx context.Context, state *CycleState, pod *v1.Pod, nodeName string) (status *Status) { func (f *frameworkImpl) RunReservePlugins(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeName string) (status *framework.Status) {
startTime := time.Now() startTime := time.Now()
defer func() { defer func() {
metrics.FrameworkExtensionPointDuration.WithLabelValues(reserve, status.Code().String()).Observe(metrics.SinceInSeconds(startTime)) metrics.FrameworkExtensionPointDuration.WithLabelValues(reserve, status.Code().String()).Observe(metrics.SinceInSeconds(startTime))
@ -783,13 +784,13 @@ func (f *framework) RunReservePlugins(ctx context.Context, state *CycleState, po
if !status.IsSuccess() { if !status.IsSuccess() {
msg := fmt.Sprintf("error while running %q reserve plugin for pod %q: %v", pl.Name(), pod.Name, status.Message()) msg := fmt.Sprintf("error while running %q reserve plugin for pod %q: %v", pl.Name(), pod.Name, status.Message())
klog.Error(msg) klog.Error(msg)
return NewStatus(Error, msg) return framework.NewStatus(framework.Error, msg)
} }
} }
return nil return nil
} }
func (f *framework) runReservePlugin(ctx context.Context, pl ReservePlugin, state *CycleState, pod *v1.Pod, nodeName string) *Status { func (f *frameworkImpl) runReservePlugin(ctx context.Context, pl framework.ReservePlugin, state *framework.CycleState, pod *v1.Pod, nodeName string) *framework.Status {
if !state.ShouldRecordPluginMetrics() { if !state.ShouldRecordPluginMetrics() {
return pl.Reserve(ctx, state, pod, nodeName) return pl.Reserve(ctx, state, pod, nodeName)
} }
@ -800,17 +801,17 @@ func (f *framework) runReservePlugin(ctx context.Context, pl ReservePlugin, stat
} }
// RunUnreservePlugins runs the set of configured unreserve plugins. // RunUnreservePlugins runs the set of configured unreserve plugins.
func (f *framework) RunUnreservePlugins(ctx context.Context, state *CycleState, pod *v1.Pod, nodeName string) { func (f *frameworkImpl) RunUnreservePlugins(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeName string) {
startTime := time.Now() startTime := time.Now()
defer func() { defer func() {
metrics.FrameworkExtensionPointDuration.WithLabelValues(unreserve, Success.String()).Observe(metrics.SinceInSeconds(startTime)) metrics.FrameworkExtensionPointDuration.WithLabelValues(unreserve, framework.Success.String()).Observe(metrics.SinceInSeconds(startTime))
}() }()
for _, pl := range f.unreservePlugins { for _, pl := range f.unreservePlugins {
f.runUnreservePlugin(ctx, pl, state, pod, nodeName) f.runUnreservePlugin(ctx, pl, state, pod, nodeName)
} }
} }
func (f *framework) runUnreservePlugin(ctx context.Context, pl UnreservePlugin, state *CycleState, pod *v1.Pod, nodeName string) { func (f *frameworkImpl) runUnreservePlugin(ctx context.Context, pl framework.UnreservePlugin, state *framework.CycleState, pod *v1.Pod, nodeName string) {
if !state.ShouldRecordPluginMetrics() { if !state.ShouldRecordPluginMetrics() {
pl.Unreserve(ctx, state, pod, nodeName) pl.Unreserve(ctx, state, pod, nodeName)
return return
@ -826,46 +827,46 @@ func (f *framework) runUnreservePlugin(ctx context.Context, pl UnreservePlugin,
// plugins returns "Wait", then this function will create and add waiting pod // plugins returns "Wait", then this function will create and add waiting pod
// to a map of currently waiting pods and return status with "Wait" code. // to a map of currently waiting pods and return status with "Wait" code.
// Pod will remain waiting pod for the minimum duration returned by the permit plugins. // Pod will remain waiting pod for the minimum duration returned by the permit plugins.
func (f *framework) RunPermitPlugins(ctx context.Context, state *CycleState, pod *v1.Pod, nodeName string) (status *Status) { func (f *frameworkImpl) RunPermitPlugins(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeName string) (status *framework.Status) {
startTime := time.Now() startTime := time.Now()
defer func() { defer func() {
metrics.FrameworkExtensionPointDuration.WithLabelValues(permit, status.Code().String()).Observe(metrics.SinceInSeconds(startTime)) metrics.FrameworkExtensionPointDuration.WithLabelValues(permit, status.Code().String()).Observe(metrics.SinceInSeconds(startTime))
}() }()
pluginsWaitTime := make(map[string]time.Duration) pluginsWaitTime := make(map[string]time.Duration)
statusCode := Success statusCode := framework.Success
for _, pl := range f.permitPlugins { for _, pl := range f.permitPlugins {
status, timeout := f.runPermitPlugin(ctx, pl, state, pod, nodeName) status, timeout := f.runPermitPlugin(ctx, pl, state, pod, nodeName)
if !status.IsSuccess() { if !status.IsSuccess() {
if status.IsUnschedulable() { if status.IsUnschedulable() {
msg := fmt.Sprintf("rejected pod %q by permit plugin %q: %v", pod.Name, pl.Name(), status.Message()) msg := fmt.Sprintf("rejected pod %q by permit plugin %q: %v", pod.Name, pl.Name(), status.Message())
klog.V(4).Infof(msg) klog.V(4).Infof(msg)
return NewStatus(status.Code(), msg) return framework.NewStatus(status.Code(), msg)
} }
if status.Code() == Wait { if status.Code() == framework.Wait {
// Not allowed to be greater than maxTimeout. // Not allowed to be greater than maxTimeout.
if timeout > maxTimeout { if timeout > maxTimeout {
timeout = maxTimeout timeout = maxTimeout
} }
pluginsWaitTime[pl.Name()] = timeout pluginsWaitTime[pl.Name()] = timeout
statusCode = Wait statusCode = framework.Wait
} else { } else {
msg := fmt.Sprintf("error while running %q permit plugin for pod %q: %v", pl.Name(), pod.Name, status.Message()) msg := fmt.Sprintf("error while running %q permit plugin for pod %q: %v", pl.Name(), pod.Name, status.Message())
klog.Error(msg) klog.Error(msg)
return NewStatus(Error, msg) return framework.NewStatus(framework.Error, msg)
} }
} }
} }
if statusCode == Wait { if statusCode == framework.Wait {
waitingPod := newWaitingPod(pod, pluginsWaitTime) waitingPod := newWaitingPod(pod, pluginsWaitTime)
f.waitingPods.add(waitingPod) f.waitingPods.add(waitingPod)
msg := fmt.Sprintf("one or more plugins asked to wait and no plugin rejected pod %q", pod.Name) msg := fmt.Sprintf("one or more plugins asked to wait and no plugin rejected pod %q", pod.Name)
klog.V(4).Infof(msg) klog.V(4).Infof(msg)
return NewStatus(Wait, msg) return framework.NewStatus(framework.Wait, msg)
} }
return nil return nil
} }
func (f *framework) runPermitPlugin(ctx context.Context, pl PermitPlugin, state *CycleState, pod *v1.Pod, nodeName string) (*Status, time.Duration) { func (f *frameworkImpl) runPermitPlugin(ctx context.Context, pl framework.PermitPlugin, state *framework.CycleState, pod *v1.Pod, nodeName string) (*framework.Status, time.Duration) {
if !state.ShouldRecordPluginMetrics() { if !state.ShouldRecordPluginMetrics() {
return pl.Permit(ctx, state, pod, nodeName) return pl.Permit(ctx, state, pod, nodeName)
} }
@ -876,7 +877,7 @@ func (f *framework) runPermitPlugin(ctx context.Context, pl PermitPlugin, state
} }
// WaitOnPermit will block, if the pod is a waiting pod, until the waiting pod is rejected or allowed. // WaitOnPermit will block, if the pod is a waiting pod, until the waiting pod is rejected or allowed.
func (f *framework) WaitOnPermit(ctx context.Context, pod *v1.Pod) (status *Status) { func (f *frameworkImpl) WaitOnPermit(ctx context.Context, pod *v1.Pod) (status *framework.Status) {
waitingPod := f.waitingPods.get(pod.UID) waitingPod := f.waitingPods.get(pod.UID)
if waitingPod == nil { if waitingPod == nil {
return nil return nil
@ -892,11 +893,11 @@ func (f *framework) WaitOnPermit(ctx context.Context, pod *v1.Pod) (status *Stat
if s.IsUnschedulable() { if s.IsUnschedulable() {
msg := fmt.Sprintf("pod %q rejected while waiting on permit: %v", pod.Name, s.Message()) msg := fmt.Sprintf("pod %q rejected while waiting on permit: %v", pod.Name, s.Message())
klog.V(4).Infof(msg) klog.V(4).Infof(msg)
return NewStatus(s.Code(), msg) return framework.NewStatus(s.Code(), msg)
} }
msg := fmt.Sprintf("error received while waiting on permit for pod %q: %v", pod.Name, s.Message()) msg := fmt.Sprintf("error received while waiting on permit for pod %q: %v", pod.Name, s.Message())
klog.Error(msg) klog.Error(msg)
return NewStatus(Error, msg) return framework.NewStatus(framework.Error, msg)
} }
return nil return nil
} }
@ -905,17 +906,17 @@ func (f *framework) WaitOnPermit(ctx context.Context, pod *v1.Pod) (status *Stat
// snapshot. The snapshot is taken at the beginning of a scheduling cycle and remains // snapshot. The snapshot is taken at the beginning of a scheduling cycle and remains
// unchanged until a pod finishes "Reserve". There is no guarantee that the information // unchanged until a pod finishes "Reserve". There is no guarantee that the information
// remains unchanged after "Reserve". // remains unchanged after "Reserve".
func (f *framework) SnapshotSharedLister() SharedLister { func (f *frameworkImpl) SnapshotSharedLister() framework.SharedLister {
return f.snapshotSharedLister return f.snapshotSharedLister
} }
// IterateOverWaitingPods acquires a read lock and iterates over the WaitingPods map. // IterateOverWaitingPods acquires a read lock and iterates over the WaitingPods map.
func (f *framework) IterateOverWaitingPods(callback func(WaitingPod)) { func (f *frameworkImpl) IterateOverWaitingPods(callback func(framework.WaitingPod)) {
f.waitingPods.iterate(callback) f.waitingPods.iterate(callback)
} }
// GetWaitingPod returns a reference to a WaitingPod given its UID. // GetWaitingPod returns a reference to a WaitingPod given its UID.
func (f *framework) GetWaitingPod(uid types.UID) WaitingPod { func (f *frameworkImpl) GetWaitingPod(uid types.UID) framework.WaitingPod {
if wp := f.waitingPods.get(uid); wp != nil { if wp := f.waitingPods.get(uid); wp != nil {
return wp return wp
} }
@ -923,7 +924,7 @@ func (f *framework) GetWaitingPod(uid types.UID) WaitingPod {
} }
// RejectWaitingPod rejects a WaitingPod given its UID. // RejectWaitingPod rejects a WaitingPod given its UID.
func (f *framework) RejectWaitingPod(uid types.UID) { func (f *frameworkImpl) RejectWaitingPod(uid types.UID) {
waitingPod := f.waitingPods.get(uid) waitingPod := f.waitingPods.get(uid)
if waitingPod != nil { if waitingPod != nil {
waitingPod.Reject("removed") waitingPod.Reject("removed")
@ -931,18 +932,18 @@ func (f *framework) RejectWaitingPod(uid types.UID) {
} }
// HasFilterPlugins returns true if at least one filter plugin is defined. // HasFilterPlugins returns true if at least one filter plugin is defined.
func (f *framework) HasFilterPlugins() bool { func (f *frameworkImpl) HasFilterPlugins() bool {
return len(f.filterPlugins) > 0 return len(f.filterPlugins) > 0
} }
// HasScorePlugins returns true if at least one score plugin is defined. // HasScorePlugins returns true if at least one score plugin is defined.
func (f *framework) HasScorePlugins() bool { func (f *frameworkImpl) HasScorePlugins() bool {
return len(f.scorePlugins) > 0 return len(f.scorePlugins) > 0
} }
// ListPlugins returns a map of extension point name to plugin names configured at each extension // ListPlugins returns a map of extension point name to plugin names configured at each extension
// point. Returns nil if no plugins where configured. // point. Returns nil if no plugins where configured.
func (f *framework) ListPlugins() map[string][]config.Plugin { func (f *frameworkImpl) ListPlugins() map[string][]config.Plugin {
m := make(map[string][]config.Plugin) m := make(map[string][]config.Plugin)
for _, e := range f.getExtensionPoints(&config.Plugins{}) { for _, e := range f.getExtensionPoints(&config.Plugins{}) {
@ -950,7 +951,7 @@ func (f *framework) ListPlugins() map[string][]config.Plugin {
extName := plugins.Type().Elem().Name() extName := plugins.Type().Elem().Name()
var cfgs []config.Plugin var cfgs []config.Plugin
for i := 0; i < plugins.Len(); i++ { for i := 0; i < plugins.Len(); i++ {
name := plugins.Index(i).Interface().(Plugin).Name() name := plugins.Index(i).Interface().(framework.Plugin).Name()
p := config.Plugin{Name: name} p := config.Plugin{Name: name}
if extName == "ScorePlugin" { if extName == "ScorePlugin" {
// Weights apply only to score plugins. // Weights apply only to score plugins.
@ -969,21 +970,21 @@ func (f *framework) ListPlugins() map[string][]config.Plugin {
} }
// ClientSet returns a kubernetes clientset. // ClientSet returns a kubernetes clientset.
func (f *framework) ClientSet() clientset.Interface { func (f *frameworkImpl) ClientSet() clientset.Interface {
return f.clientSet return f.clientSet
} }
// EventRecorder returns an event recorder. // EventRecorder returns an event recorder.
func (f *framework) EventRecorder() events.EventRecorder { func (f *frameworkImpl) EventRecorder() events.EventRecorder {
return f.eventRecorder return f.eventRecorder
} }
// SharedInformerFactory returns a shared informer factory. // SharedInformerFactory returns a shared informer factory.
func (f *framework) SharedInformerFactory() informers.SharedInformerFactory { func (f *frameworkImpl) SharedInformerFactory() informers.SharedInformerFactory {
return f.informerFactory return f.informerFactory
} }
func (f *framework) pluginsNeeded(plugins *config.Plugins) map[string]config.Plugin { func (f *frameworkImpl) pluginsNeeded(plugins *config.Plugins) map[string]config.Plugin {
pgMap := make(map[string]config.Plugin) pgMap := make(map[string]config.Plugin)
if plugins == nil { if plugins == nil {
@ -1005,6 +1006,6 @@ func (f *framework) pluginsNeeded(plugins *config.Plugins) map[string]config.Plu
} }
// PreemptHandle returns the internal preemptHandle object. // PreemptHandle returns the internal preemptHandle object.
func (f *framework) PreemptHandle() PreemptHandle { func (f *frameworkImpl) PreemptHandle() framework.PreemptHandle {
return f.preemptHandle return f.preemptHandle
} }

View File

@ -14,12 +14,13 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package v1alpha1 package runtime
import ( import (
"time" "time"
k8smetrics "k8s.io/component-base/metrics" k8smetrics "k8s.io/component-base/metrics"
"k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
"k8s.io/kubernetes/pkg/scheduler/metrics" "k8s.io/kubernetes/pkg/scheduler/metrics"
) )
@ -62,7 +63,7 @@ func newMetricsRecorder(bufferSize int, interval time.Duration) *metricsRecorder
// observePluginDurationAsync observes the plugin_execution_duration_seconds metric. // observePluginDurationAsync observes the plugin_execution_duration_seconds metric.
// The metric will be flushed to Prometheus asynchronously. // The metric will be flushed to Prometheus asynchronously.
func (r *metricsRecorder) observePluginDurationAsync(extensionPoint, pluginName string, status *Status, value float64) { func (r *metricsRecorder) observePluginDurationAsync(extensionPoint, pluginName string, status *v1alpha1.Status, value float64) {
newMetric := &frameworkMetric{ newMetric := &frameworkMetric{
metric: metrics.PluginExecutionDuration, metric: metrics.PluginExecutionDuration,
labelValues: []string{pluginName, extensionPoint, status.Code().String()}, labelValues: []string{pluginName, extensionPoint, status.Code().String()},

View File

@ -14,18 +14,19 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package v1alpha1 package runtime
import ( import (
"fmt" "fmt"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/json" "k8s.io/apimachinery/pkg/util/json"
"k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
"sigs.k8s.io/yaml" "sigs.k8s.io/yaml"
) )
// PluginFactory is a function that builds a plugin. // PluginFactory is a function that builds a plugin.
type PluginFactory = func(configuration runtime.Object, f FrameworkHandle) (Plugin, error) type PluginFactory = func(configuration runtime.Object, f v1alpha1.FrameworkHandle) (v1alpha1.Plugin, error)
// DecodeInto decodes configuration whose type is *runtime.Unknown to the interface into. // DecodeInto decodes configuration whose type is *runtime.Unknown to the interface into.
func DecodeInto(obj runtime.Object, into interface{}) error { func DecodeInto(obj runtime.Object, into interface{}) error {

View File

@ -14,13 +14,14 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package v1alpha1 package runtime
import ( import (
"reflect" "reflect"
"testing" "testing"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
) )
func TestDecodeInto(t *testing.T) { func TestDecodeInto(t *testing.T) {
@ -102,7 +103,7 @@ func (p *mockNoopPlugin) Name() string {
} }
func NewMockNoopPluginFactory() PluginFactory { func NewMockNoopPluginFactory() PluginFactory {
return func(_ runtime.Object, _ FrameworkHandle) (Plugin, error) { return func(_ runtime.Object, _ v1alpha1.FrameworkHandle) (v1alpha1.Plugin, error) {
return &mockNoopPlugin{}, nil return &mockNoopPlugin{}, nil
} }
} }

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package v1alpha1 package runtime
import ( import (
"fmt" "fmt"
@ -23,6 +23,7 @@ import (
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
) )
// waitingPodsMap a thread-safe map used to maintain pods waiting in the permit phase. // waitingPodsMap a thread-safe map used to maintain pods waiting in the permit phase.
@ -60,7 +61,7 @@ func (m *waitingPodsMap) get(uid types.UID) *waitingPod {
} }
// iterate acquires a read lock and iterates over the WaitingPods map. // iterate acquires a read lock and iterates over the WaitingPods map.
func (m *waitingPodsMap) iterate(callback func(WaitingPod)) { func (m *waitingPodsMap) iterate(callback func(v1alpha1.WaitingPod)) {
m.mu.RLock() m.mu.RLock()
defer m.mu.RUnlock() defer m.mu.RUnlock()
for _, v := range m.pods { for _, v := range m.pods {
@ -72,11 +73,11 @@ func (m *waitingPodsMap) iterate(callback func(WaitingPod)) {
type waitingPod struct { type waitingPod struct {
pod *v1.Pod pod *v1.Pod
pendingPlugins map[string]*time.Timer pendingPlugins map[string]*time.Timer
s chan *Status s chan *v1alpha1.Status
mu sync.RWMutex mu sync.RWMutex
} }
var _ WaitingPod = &waitingPod{} var _ v1alpha1.WaitingPod = &waitingPod{}
// newWaitingPod returns a new waitingPod instance. // newWaitingPod returns a new waitingPod instance.
func newWaitingPod(pod *v1.Pod, pluginsMaxWaitTime map[string]time.Duration) *waitingPod { func newWaitingPod(pod *v1.Pod, pluginsMaxWaitTime map[string]time.Duration) *waitingPod {
@ -86,7 +87,7 @@ func newWaitingPod(pod *v1.Pod, pluginsMaxWaitTime map[string]time.Duration) *wa
// by using non-blocking send to this channel. This channel has a buffer of size 1 // by using non-blocking send to this channel. This channel has a buffer of size 1
// to ensure that non-blocking send will not be ignored - possible situation when // to ensure that non-blocking send will not be ignored - possible situation when
// receiving from this channel happens after non-blocking send. // receiving from this channel happens after non-blocking send.
s: make(chan *Status, 1), s: make(chan *v1alpha1.Status, 1),
} }
wp.pendingPlugins = make(map[string]*time.Timer, len(pluginsMaxWaitTime)) wp.pendingPlugins = make(map[string]*time.Timer, len(pluginsMaxWaitTime))
@ -142,7 +143,7 @@ func (w *waitingPod) Allow(pluginName string) {
// The select clause works as a non-blocking send. // The select clause works as a non-blocking send.
// If there is no receiver, it's a no-op (default case). // If there is no receiver, it's a no-op (default case).
select { select {
case w.s <- NewStatus(Success, ""): case w.s <- v1alpha1.NewStatus(v1alpha1.Success, ""):
default: default:
} }
} }
@ -158,7 +159,7 @@ func (w *waitingPod) Reject(msg string) {
// The select clause works as a non-blocking send. // The select clause works as a non-blocking send.
// If there is no receiver, it's a no-op (default case). // If there is no receiver, it's a no-op (default case).
select { select {
case w.s <- NewStatus(Unschedulable, msg): case w.s <- v1alpha1.NewStatus(v1alpha1.Unschedulable, msg):
default: default:
} }
} }

View File

@ -5,13 +5,9 @@ go_library(
srcs = [ srcs = [
"cycle_state.go", "cycle_state.go",
"extender.go", "extender.go",
"framework.go",
"interface.go", "interface.go",
"listers.go", "listers.go",
"metrics_recorder.go",
"registry.go",
"types.go", "types.go",
"waiting_pods_map.go",
], ],
importpath = "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1", importpath = "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1",
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
@ -19,27 +15,19 @@ go_library(
"//pkg/apis/core/v1/helper:go_default_library", "//pkg/apis/core/v1/helper:go_default_library",
"//pkg/features:go_default_library", "//pkg/features:go_default_library",
"//pkg/scheduler/apis/config:go_default_library", "//pkg/scheduler/apis/config:go_default_library",
"//pkg/scheduler/apis/config/scheme:go_default_library",
"//pkg/scheduler/internal/parallelize:go_default_library",
"//pkg/scheduler/metrics:go_default_library",
"//pkg/scheduler/util:go_default_library", "//pkg/scheduler/util:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/resource:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/api/resource:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/json:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library", "//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
"//staging/src/k8s.io/client-go/informers:go_default_library", "//staging/src/k8s.io/client-go/informers:go_default_library",
"//staging/src/k8s.io/client-go/kubernetes:go_default_library", "//staging/src/k8s.io/client-go/kubernetes:go_default_library",
"//staging/src/k8s.io/client-go/tools/events:go_default_library", "//staging/src/k8s.io/client-go/tools/events:go_default_library",
"//staging/src/k8s.io/component-base/metrics:go_default_library",
"//staging/src/k8s.io/kube-scheduler/config/v1beta1:go_default_library",
"//staging/src/k8s.io/kube-scheduler/extender/v1:go_default_library", "//staging/src/k8s.io/kube-scheduler/extender/v1:go_default_library",
"//vendor/k8s.io/klog/v2:go_default_library", "//vendor/k8s.io/klog/v2:go_default_library",
"//vendor/sigs.k8s.io/yaml:go_default_library",
], ],
) )
@ -64,22 +52,14 @@ go_test(
name = "go_default_test", name = "go_default_test",
srcs = [ srcs = [
"cycle_state_test.go", "cycle_state_test.go",
"framework_test.go",
"interface_test.go", "interface_test.go",
"registry_test.go",
"types_test.go", "types_test.go",
], ],
embed = [":go_default_library"], embed = [":go_default_library"],
deps = [ deps = [
"//pkg/scheduler/apis/config:go_default_library",
"//pkg/scheduler/metrics:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/resource:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/api/resource:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
"//vendor/github.com/google/go-cmp/cmp:go_default_library",
"//vendor/github.com/prometheus/client_golang/prometheus:go_default_library",
"//vendor/github.com/prometheus/client_model/go:go_default_library",
], ],
) )

View File

@ -7,6 +7,7 @@ go_library(
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
deps = [ deps = [
"//pkg/scheduler/apis/config:go_default_library", "//pkg/scheduler/apis/config:go_default_library",
"//pkg/scheduler/framework/runtime:go_default_library",
"//pkg/scheduler/framework/v1alpha1:go_default_library", "//pkg/scheduler/framework/v1alpha1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//staging/src/k8s.io/client-go/kubernetes/scheme:go_default_library", "//staging/src/k8s.io/client-go/kubernetes/scheme:go_default_library",
@ -35,6 +36,7 @@ go_test(
embed = [":go_default_library"], embed = [":go_default_library"],
deps = [ deps = [
"//pkg/scheduler/apis/config:go_default_library", "//pkg/scheduler/apis/config:go_default_library",
"//pkg/scheduler/framework/runtime:go_default_library",
"//pkg/scheduler/framework/v1alpha1:go_default_library", "//pkg/scheduler/framework/v1alpha1:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/api/events/v1beta1:go_default_library", "//staging/src/k8s.io/api/events/v1beta1:go_default_library",

View File

@ -26,6 +26,7 @@ import (
"k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/tools/events" "k8s.io/client-go/tools/events"
"k8s.io/kubernetes/pkg/scheduler/apis/config" "k8s.io/kubernetes/pkg/scheduler/apis/config"
frameworkruntime "k8s.io/kubernetes/pkg/scheduler/framework/runtime"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
) )
@ -33,7 +34,7 @@ import (
type RecorderFactory func(string) events.EventRecorder type RecorderFactory func(string) events.EventRecorder
// FrameworkFactory builds a Framework for a given profile configuration. // FrameworkFactory builds a Framework for a given profile configuration.
type FrameworkFactory func(config.KubeSchedulerProfile, ...framework.Option) (framework.Framework, error) type FrameworkFactory func(config.KubeSchedulerProfile, ...frameworkruntime.Option) (framework.Framework, error)
// Profile is a scheduling profile. // Profile is a scheduling profile.
type Profile struct { type Profile struct {
@ -43,9 +44,9 @@ type Profile struct {
// NewProfile builds a Profile for the given configuration. // NewProfile builds a Profile for the given configuration.
func NewProfile(cfg config.KubeSchedulerProfile, frameworkFact FrameworkFactory, recorderFact RecorderFactory, func NewProfile(cfg config.KubeSchedulerProfile, frameworkFact FrameworkFactory, recorderFact RecorderFactory,
opts ...framework.Option) (*Profile, error) { opts ...frameworkruntime.Option) (*Profile, error) {
r := recorderFact(cfg.SchedulerName) r := recorderFact(cfg.SchedulerName)
f, err := frameworkFact(cfg, append(opts, framework.WithEventRecorder(r))...) f, err := frameworkFact(cfg, append(opts, frameworkruntime.WithEventRecorder(r))...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -60,7 +61,7 @@ type Map map[string]*Profile
// NewMap builds the profiles given by the configuration, indexed by name. // NewMap builds the profiles given by the configuration, indexed by name.
func NewMap(cfgs []config.KubeSchedulerProfile, frameworkFact FrameworkFactory, recorderFact RecorderFactory, func NewMap(cfgs []config.KubeSchedulerProfile, frameworkFact FrameworkFactory, recorderFact RecorderFactory,
opts ...framework.Option) (Map, error) { opts ...frameworkruntime.Option) (Map, error) {
m := make(Map) m := make(Map)
v := cfgValidator{m: m} v := cfgValidator{m: m}

View File

@ -28,10 +28,11 @@ import (
"k8s.io/client-go/kubernetes/fake" "k8s.io/client-go/kubernetes/fake"
"k8s.io/client-go/tools/events" "k8s.io/client-go/tools/events"
"k8s.io/kubernetes/pkg/scheduler/apis/config" "k8s.io/kubernetes/pkg/scheduler/apis/config"
frameworkruntime "k8s.io/kubernetes/pkg/scheduler/framework/runtime"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
) )
var fakeRegistry = framework.Registry{ var fakeRegistry = frameworkruntime.Registry{
"QueueSort": newFakePlugin, "QueueSort": newFakePlugin,
"Bind1": newFakePlugin, "Bind1": newFakePlugin,
"Bind2": newFakePlugin, "Bind2": newFakePlugin,
@ -351,8 +352,8 @@ func newFakePlugin(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plu
return &fakePlugin{}, nil return &fakePlugin{}, nil
} }
func fakeFrameworkFactory(cfg config.KubeSchedulerProfile, opts ...framework.Option) (framework.Framework, error) { func fakeFrameworkFactory(cfg config.KubeSchedulerProfile, opts ...frameworkruntime.Option) (framework.Framework, error) {
return framework.NewFramework(fakeRegistry, cfg.Plugins, cfg.PluginConfig, opts...) return frameworkruntime.NewFramework(fakeRegistry, cfg.Plugins, cfg.PluginConfig, opts...)
} }
func nilRecorderFactory(_ string) events.EventRecorder { func nilRecorderFactory(_ string) events.EventRecorder {

View File

@ -38,6 +38,7 @@ import (
"k8s.io/kubernetes/pkg/scheduler/apis/config/scheme" "k8s.io/kubernetes/pkg/scheduler/apis/config/scheme"
"k8s.io/kubernetes/pkg/scheduler/core" "k8s.io/kubernetes/pkg/scheduler/core"
frameworkplugins "k8s.io/kubernetes/pkg/scheduler/framework/plugins" frameworkplugins "k8s.io/kubernetes/pkg/scheduler/framework/plugins"
frameworkruntime "k8s.io/kubernetes/pkg/scheduler/framework/runtime"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
internalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache" internalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache"
internalqueue "k8s.io/kubernetes/pkg/scheduler/internal/queue" internalqueue "k8s.io/kubernetes/pkg/scheduler/internal/queue"
@ -101,7 +102,7 @@ type schedulerOptions struct {
podInitialBackoffSeconds int64 podInitialBackoffSeconds int64
podMaxBackoffSeconds int64 podMaxBackoffSeconds int64
// Contains out-of-tree plugins to be merged with the in-tree registry. // Contains out-of-tree plugins to be merged with the in-tree registry.
frameworkOutOfTreeRegistry framework.Registry frameworkOutOfTreeRegistry frameworkruntime.Registry
profiles []schedulerapi.KubeSchedulerProfile profiles []schedulerapi.KubeSchedulerProfile
extenders []schedulerapi.Extender extenders []schedulerapi.Extender
frameworkCapturer FrameworkCapturer frameworkCapturer FrameworkCapturer
@ -141,7 +142,7 @@ func WithPercentageOfNodesToScore(percentageOfNodesToScore int32) Option {
// WithFrameworkOutOfTreeRegistry sets the registry for out-of-tree plugins. Those plugins // WithFrameworkOutOfTreeRegistry sets the registry for out-of-tree plugins. Those plugins
// will be appended to the default registry. // will be appended to the default registry.
func WithFrameworkOutOfTreeRegistry(registry framework.Registry) Option { func WithFrameworkOutOfTreeRegistry(registry frameworkruntime.Registry) Option {
return func(o *schedulerOptions) { return func(o *schedulerOptions) {
o.frameworkOutOfTreeRegistry = registry o.frameworkOutOfTreeRegistry = registry
} }

View File

@ -55,6 +55,7 @@ import (
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/noderesources" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/noderesources"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/queuesort" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/queuesort"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumebinding" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumebinding"
frameworkruntime "k8s.io/kubernetes/pkg/scheduler/framework/runtime"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
internalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache" internalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache"
fakecache "k8s.io/kubernetes/pkg/scheduler/internal/cache/fake" fakecache "k8s.io/kubernetes/pkg/scheduler/internal/cache/fake"
@ -121,10 +122,10 @@ func (es mockScheduler) Extenders() []framework.Extender {
} }
func TestSchedulerCreation(t *testing.T) { func TestSchedulerCreation(t *testing.T) {
invalidRegistry := map[string]framework.PluginFactory{ invalidRegistry := map[string]frameworkruntime.PluginFactory{
defaultbinder.Name: defaultbinder.New, defaultbinder.Name: defaultbinder.New,
} }
validRegistry := map[string]framework.PluginFactory{ validRegistry := map[string]frameworkruntime.PluginFactory{
"Foo": defaultbinder.New, "Foo": defaultbinder.New,
} }
cases := []struct { cases := []struct {
@ -298,7 +299,7 @@ func TestSchedulerScheduleOne(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),
}, framework.WithClientSet(client)) }, frameworkruntime.WithClientSet(client))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -361,7 +362,7 @@ type fakeNodeSelector struct {
func newFakeNodeSelector(args runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) { func newFakeNodeSelector(args runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) {
pl := &fakeNodeSelector{} pl := &fakeNodeSelector{}
if err := framework.DecodeInto(args, &pl.fakeNodeSelectorArgs); err != nil { if err := frameworkruntime.DecodeInto(args, &pl.fakeNodeSelectorArgs); err != nil {
return nil, err return nil, err
} }
return pl, nil return pl, nil
@ -444,7 +445,7 @@ func TestSchedulerMultipleProfilesScheduling(t *testing.T) {
}, },
}, },
), ),
WithFrameworkOutOfTreeRegistry(framework.Registry{ WithFrameworkOutOfTreeRegistry(frameworkruntime.Registry{
"FakeNodeSelector": newFakeNodeSelector, "FakeNodeSelector": newFakeNodeSelector,
}), }),
) )
@ -765,7 +766,7 @@ func setupTestScheduler(queuedPodStore *clientcache.FIFO, scache internalcache.C
return true, b, nil return true, b, nil
}) })
fwk, _ := st.NewFramework(fns, framework.WithClientSet(client)) fwk, _ := st.NewFramework(fns, frameworkruntime.WithClientSet(client))
prof := &profile.Profile{ prof := &profile.Profile{
Framework: fwk, Framework: fwk,
Recorder: &events.FakeRecorder{}, Recorder: &events.FakeRecorder{},
@ -1118,7 +1119,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),
}, framework.WithClientSet(client)) }, frameworkruntime.WithClientSet(client))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -15,6 +15,7 @@ go_library(
deps = [ deps = [
"//pkg/api/v1/pod:go_default_library", "//pkg/api/v1/pod:go_default_library",
"//pkg/scheduler/apis/config:go_default_library", "//pkg/scheduler/apis/config:go_default_library",
"//pkg/scheduler/framework/runtime:go_default_library",
"//pkg/scheduler/framework/v1alpha1:go_default_library", "//pkg/scheduler/framework/v1alpha1:go_default_library",
"//pkg/scheduler/util:go_default_library", "//pkg/scheduler/util:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library",

View File

@ -25,6 +25,7 @@ import (
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
extenderv1 "k8s.io/kube-scheduler/extender/v1" extenderv1 "k8s.io/kube-scheduler/extender/v1"
podutil "k8s.io/kubernetes/pkg/api/v1/pod" podutil "k8s.io/kubernetes/pkg/api/v1/pod"
frameworkruntime "k8s.io/kubernetes/pkg/scheduler/framework/runtime"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
"k8s.io/kubernetes/pkg/scheduler/util" "k8s.io/kubernetes/pkg/scheduler/util"
) )
@ -110,7 +111,7 @@ func Machine2PrioritizerExtender(pod *v1.Pod, nodes []*v1.Node) (*framework.Node
type machine2PrioritizerPlugin struct{} type machine2PrioritizerPlugin struct{}
// NewMachine2PrioritizerPlugin returns a factory function to build machine2PrioritizerPlugin. // NewMachine2PrioritizerPlugin returns a factory function to build machine2PrioritizerPlugin.
func NewMachine2PrioritizerPlugin() framework.PluginFactory { func NewMachine2PrioritizerPlugin() frameworkruntime.PluginFactory {
return func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) { return func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) {
return &machine2PrioritizerPlugin{}, nil return &machine2PrioritizerPlugin{}, nil
} }

View File

@ -23,6 +23,7 @@ import (
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
frameworkruntime "k8s.io/kubernetes/pkg/scheduler/framework/runtime"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
) )
@ -89,7 +90,7 @@ func (pl *FakeFilterPlugin) Filter(_ context.Context, _ *framework.CycleState, p
} }
// NewFakeFilterPlugin initializes a fakeFilterPlugin and returns it. // NewFakeFilterPlugin initializes a fakeFilterPlugin and returns it.
func NewFakeFilterPlugin(failedNodeReturnCodeMap map[string]framework.Code) framework.PluginFactory { func NewFakeFilterPlugin(failedNodeReturnCodeMap map[string]framework.Code) frameworkruntime.PluginFactory {
return func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) { return func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) {
return &FakeFilterPlugin{ return &FakeFilterPlugin{
FailedNodeReturnCodeMap: failedNodeReturnCodeMap, FailedNodeReturnCodeMap: failedNodeReturnCodeMap,

View File

@ -18,57 +18,58 @@ package testing
import ( import (
schedulerapi "k8s.io/kubernetes/pkg/scheduler/apis/config" schedulerapi "k8s.io/kubernetes/pkg/scheduler/apis/config"
"k8s.io/kubernetes/pkg/scheduler/framework/runtime"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
) )
// 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 ...framework.Option) (framework.Framework, error) { func NewFramework(fns []RegisterPluginFunc, opts ...runtime.Option) (framework.Framework, error) {
registry := framework.Registry{} registry := runtime.Registry{}
plugins := &schedulerapi.Plugins{} plugins := &schedulerapi.Plugins{}
var pluginConfigs []schedulerapi.PluginConfig var pluginConfigs []schedulerapi.PluginConfig
for _, f := range fns { for _, f := range fns {
f(&registry, plugins, pluginConfigs) f(&registry, plugins, pluginConfigs)
} }
return framework.NewFramework(registry, plugins, pluginConfigs, opts...) return runtime.NewFramework(registry, plugins, pluginConfigs, opts...)
} }
// RegisterPluginFunc is a function signature used in method RegisterFilterPlugin() // RegisterPluginFunc is a function signature used in method RegisterFilterPlugin()
// to register a Filter Plugin to a given registry. // to register a Filter Plugin to a given registry.
type RegisterPluginFunc func(reg *framework.Registry, plugins *schedulerapi.Plugins, pluginConfigs []schedulerapi.PluginConfig) type RegisterPluginFunc func(reg *runtime.Registry, plugins *schedulerapi.Plugins, pluginConfigs []schedulerapi.PluginConfig)
// RegisterQueueSortPlugin returns a function to register a QueueSort Plugin to a given registry. // RegisterQueueSortPlugin returns a function to register a QueueSort Plugin to a given registry.
func RegisterQueueSortPlugin(pluginName string, pluginNewFunc framework.PluginFactory) RegisterPluginFunc { func RegisterQueueSortPlugin(pluginName string, pluginNewFunc runtime.PluginFactory) RegisterPluginFunc {
return RegisterPluginAsExtensions(pluginName, pluginNewFunc, "QueueSort") return RegisterPluginAsExtensions(pluginName, pluginNewFunc, "QueueSort")
} }
// RegisterFilterPlugin returns a function to register a Filter Plugin to a given registry. // RegisterFilterPlugin returns a function to register a Filter Plugin to a given registry.
func RegisterFilterPlugin(pluginName string, pluginNewFunc framework.PluginFactory) RegisterPluginFunc { func RegisterFilterPlugin(pluginName string, pluginNewFunc runtime.PluginFactory) RegisterPluginFunc {
return RegisterPluginAsExtensions(pluginName, pluginNewFunc, "Filter") return RegisterPluginAsExtensions(pluginName, pluginNewFunc, "Filter")
} }
// RegisterScorePlugin returns a function to register a Score Plugin to a given registry. // RegisterScorePlugin returns a function to register a Score Plugin to a given registry.
func RegisterScorePlugin(pluginName string, pluginNewFunc framework.PluginFactory, weight int32) RegisterPluginFunc { func RegisterScorePlugin(pluginName string, pluginNewFunc runtime.PluginFactory, weight int32) RegisterPluginFunc {
return RegisterPluginAsExtensionsWithWeight(pluginName, weight, pluginNewFunc, "Score") return RegisterPluginAsExtensionsWithWeight(pluginName, weight, pluginNewFunc, "Score")
} }
// RegisterPreScorePlugin returns a function to register a Score Plugin to a given registry. // RegisterPreScorePlugin returns a function to register a Score Plugin to a given registry.
func RegisterPreScorePlugin(pluginName string, pluginNewFunc framework.PluginFactory) RegisterPluginFunc { func RegisterPreScorePlugin(pluginName string, pluginNewFunc runtime.PluginFactory) RegisterPluginFunc {
return RegisterPluginAsExtensions(pluginName, pluginNewFunc, "PreScore") return RegisterPluginAsExtensions(pluginName, pluginNewFunc, "PreScore")
} }
// RegisterBindPlugin returns a function to register a Bind Plugin to a given registry. // RegisterBindPlugin returns a function to register a Bind Plugin to a given registry.
func RegisterBindPlugin(pluginName string, pluginNewFunc framework.PluginFactory) RegisterPluginFunc { func RegisterBindPlugin(pluginName string, pluginNewFunc runtime.PluginFactory) RegisterPluginFunc {
return RegisterPluginAsExtensions(pluginName, pluginNewFunc, "Bind") return RegisterPluginAsExtensions(pluginName, pluginNewFunc, "Bind")
} }
// RegisterPluginAsExtensions returns a function to register a Plugin as given extensionPoints to a given registry. // RegisterPluginAsExtensions returns a function to register a Plugin as given extensionPoints to a given registry.
func RegisterPluginAsExtensions(pluginName string, pluginNewFunc framework.PluginFactory, extensions ...string) RegisterPluginFunc { func RegisterPluginAsExtensions(pluginName string, pluginNewFunc runtime.PluginFactory, extensions ...string) RegisterPluginFunc {
return RegisterPluginAsExtensionsWithWeight(pluginName, 1, pluginNewFunc, extensions...) return RegisterPluginAsExtensionsWithWeight(pluginName, 1, pluginNewFunc, extensions...)
} }
// RegisterPluginAsExtensionsWithWeight returns a function to register a Plugin as given extensionPoints with weight to a given registry. // RegisterPluginAsExtensionsWithWeight returns a function to register a Plugin as given extensionPoints with weight to a given registry.
func RegisterPluginAsExtensionsWithWeight(pluginName string, weight int32, pluginNewFunc framework.PluginFactory, extensions ...string) RegisterPluginFunc { func RegisterPluginAsExtensionsWithWeight(pluginName string, weight int32, pluginNewFunc runtime.PluginFactory, extensions ...string) RegisterPluginFunc {
return func(reg *framework.Registry, plugins *schedulerapi.Plugins, pluginConfigs []schedulerapi.PluginConfig) { return func(reg *runtime.Registry, plugins *schedulerapi.Plugins, pluginConfigs []schedulerapi.PluginConfig) {
reg.Register(pluginName, pluginNewFunc) reg.Register(pluginName, pluginNewFunc)
for _, extension := range extensions { for _, extension := range extensions {
ps := getPluginSetByExtension(plugins, extension) ps := getPluginSetByExtension(plugins, extension)

View File

@ -187,6 +187,7 @@ rules:
- k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodeports - k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodeports
- k8s.io/kubernetes/pkg/scheduler/framework/plugins/noderesources - k8s.io/kubernetes/pkg/scheduler/framework/plugins/noderesources
- k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1 - k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1
- k8s.io/kubernetes/pkg/scheduler/framework/runtime
- k8s.io/kubernetes/pkg/scheduler/internal/parallelize - k8s.io/kubernetes/pkg/scheduler/internal/parallelize
- k8s.io/kubernetes/pkg/scheduler/listers - k8s.io/kubernetes/pkg/scheduler/listers
- k8s.io/kubernetes/pkg/scheduler/metrics - k8s.io/kubernetes/pkg/scheduler/metrics

View File

@ -29,6 +29,7 @@ go_test(
"//pkg/scheduler:go_default_library", "//pkg/scheduler:go_default_library",
"//pkg/scheduler/apis/config:go_default_library", "//pkg/scheduler/apis/config:go_default_library",
"//pkg/scheduler/framework/plugins/defaultbinder:go_default_library", "//pkg/scheduler/framework/plugins/defaultbinder:go_default_library",
"//pkg/scheduler/framework/runtime:go_default_library",
"//pkg/scheduler/framework/v1alpha1:go_default_library", "//pkg/scheduler/framework/v1alpha1:go_default_library",
"//pkg/scheduler/profile:go_default_library", "//pkg/scheduler/profile:go_default_library",
"//pkg/scheduler/testing:go_default_library", "//pkg/scheduler/testing:go_default_library",

View File

@ -31,6 +31,7 @@ import (
"k8s.io/kubernetes/pkg/scheduler" "k8s.io/kubernetes/pkg/scheduler"
schedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config" schedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/defaultbinder" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/defaultbinder"
frameworkruntime "k8s.io/kubernetes/pkg/scheduler/framework/runtime"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
testutils "k8s.io/kubernetes/test/integration/util" testutils "k8s.io/kubernetes/test/integration/util"
) )
@ -145,14 +146,14 @@ var _ framework.UnreservePlugin = &UnreservePlugin{}
var _ framework.PermitPlugin = &PermitPlugin{} var _ framework.PermitPlugin = &PermitPlugin{}
// newPlugin returns a plugin factory with specified Plugin. // newPlugin returns a plugin factory with specified Plugin.
func newPlugin(plugin framework.Plugin) framework.PluginFactory { func newPlugin(plugin framework.Plugin) frameworkruntime.PluginFactory {
return func(_ runtime.Object, fh framework.FrameworkHandle) (framework.Plugin, error) { return func(_ runtime.Object, fh framework.FrameworkHandle) (framework.Plugin, error) {
return plugin, nil return plugin, nil
} }
} }
// newPlugin returns a plugin factory with specified Plugin. // newPlugin returns a plugin factory with specified Plugin.
func newPostFilterPlugin(plugin *PostFilterPlugin) framework.PluginFactory { func newPostFilterPlugin(plugin *PostFilterPlugin) frameworkruntime.PluginFactory {
return func(_ runtime.Object, fh framework.FrameworkHandle) (framework.Plugin, error) { return func(_ runtime.Object, fh framework.FrameworkHandle) (framework.Plugin, error) {
plugin.fh = fh plugin.fh = fh
return plugin, nil return plugin, nil
@ -498,7 +499,7 @@ func (pp *PermitPlugin) reset() {
} }
// newPermitPlugin returns a factory for permit plugin with specified PermitPlugin. // newPermitPlugin returns a factory for permit plugin with specified PermitPlugin.
func newPermitPlugin(permitPlugin *PermitPlugin) framework.PluginFactory { func newPermitPlugin(permitPlugin *PermitPlugin) frameworkruntime.PluginFactory {
return func(_ runtime.Object, fh framework.FrameworkHandle) (framework.Plugin, error) { return func(_ runtime.Object, fh framework.FrameworkHandle) (framework.Plugin, error) {
permitPlugin.fh = fh permitPlugin.fh = fh
return permitPlugin, nil return permitPlugin, nil
@ -509,7 +510,7 @@ func newPermitPlugin(permitPlugin *PermitPlugin) framework.PluginFactory {
func TestPreFilterPlugin(t *testing.T) { func TestPreFilterPlugin(t *testing.T) {
// Create a plugin registry for testing. Register only a pre-filter plugin. // Create a plugin registry for testing. Register only a pre-filter plugin.
preFilterPlugin := &PreFilterPlugin{} preFilterPlugin := &PreFilterPlugin{}
registry := framework.Registry{prefilterPluginName: newPlugin(preFilterPlugin)} registry := frameworkruntime.Registry{prefilterPluginName: newPlugin(preFilterPlugin)}
// Setup initial prefilter plugin for testing. // Setup initial prefilter plugin for testing.
prof := schedulerconfig.KubeSchedulerProfile{ prof := schedulerconfig.KubeSchedulerProfile{
@ -626,7 +627,7 @@ func TestPostFilterPlugin(t *testing.T) {
) )
filterPlugin.rejectFilter = tt.rejectFilter filterPlugin.rejectFilter = tt.rejectFilter
postFilterPlugin.rejectPostFilter = tt.rejectPostFilter postFilterPlugin.rejectPostFilter = tt.rejectPostFilter
registry := framework.Registry{ registry := frameworkruntime.Registry{
filterPluginName: newPlugin(filterPlugin), filterPluginName: newPlugin(filterPlugin),
postfilterPluginName: newPostFilterPlugin(postFilterPlugin), postfilterPluginName: newPostFilterPlugin(postFilterPlugin),
} }
@ -688,7 +689,7 @@ func TestPostFilterPlugin(t *testing.T) {
func TestScorePlugin(t *testing.T) { func TestScorePlugin(t *testing.T) {
// Create a plugin registry for testing. Register only a score plugin. // Create a plugin registry for testing. Register only a score plugin.
scorePlugin := &ScorePlugin{} scorePlugin := &ScorePlugin{}
registry := framework.Registry{ registry := frameworkruntime.Registry{
scorePluginName: newPlugin(scorePlugin), scorePluginName: newPlugin(scorePlugin),
} }
@ -763,7 +764,7 @@ func TestScorePlugin(t *testing.T) {
func TestNormalizeScorePlugin(t *testing.T) { func TestNormalizeScorePlugin(t *testing.T) {
// Create a plugin registry for testing. Register only a normalize score plugin. // Create a plugin registry for testing. Register only a normalize score plugin.
scoreWithNormalizePlugin := &ScoreWithNormalizePlugin{} scoreWithNormalizePlugin := &ScoreWithNormalizePlugin{}
registry := framework.Registry{ registry := frameworkruntime.Registry{
scoreWithNormalizePluginName: newPlugin(scoreWithNormalizePlugin), scoreWithNormalizePluginName: newPlugin(scoreWithNormalizePlugin),
} }
@ -809,7 +810,7 @@ func TestNormalizeScorePlugin(t *testing.T) {
func TestReservePlugin(t *testing.T) { func TestReservePlugin(t *testing.T) {
// Create a plugin registry for testing. Register only a reserve plugin. // Create a plugin registry for testing. Register only a reserve plugin.
reservePlugin := &ReservePlugin{} reservePlugin := &ReservePlugin{}
registry := framework.Registry{reservePluginName: newPlugin(reservePlugin)} registry := frameworkruntime.Registry{reservePluginName: newPlugin(reservePlugin)}
// Setup initial reserve plugin for testing. // Setup initial reserve plugin for testing.
prof := schedulerconfig.KubeSchedulerProfile{ prof := schedulerconfig.KubeSchedulerProfile{
@ -880,7 +881,7 @@ func TestReservePlugin(t *testing.T) {
func TestPrebindPlugin(t *testing.T) { func TestPrebindPlugin(t *testing.T) {
// Create a plugin registry for testing. Register only a prebind plugin. // Create a plugin registry for testing. Register only a prebind plugin.
preBindPlugin := &PreBindPlugin{} preBindPlugin := &PreBindPlugin{}
registry := framework.Registry{preBindPluginName: newPlugin(preBindPlugin)} registry := frameworkruntime.Registry{preBindPluginName: newPlugin(preBindPlugin)}
// Setup initial prebind plugin for testing. // Setup initial prebind plugin for testing.
prof := schedulerconfig.KubeSchedulerProfile{ prof := schedulerconfig.KubeSchedulerProfile{
@ -963,7 +964,7 @@ func TestUnreservePlugin(t *testing.T) {
// TODO: register more plugin which would trigger un-reserve plugin // TODO: register more plugin which would trigger un-reserve plugin
preBindPlugin := &PreBindPlugin{} preBindPlugin := &PreBindPlugin{}
unreservePlugin := &UnreservePlugin{name: unreservePluginName} unreservePlugin := &UnreservePlugin{name: unreservePluginName}
registry := framework.Registry{ registry := frameworkruntime.Registry{
unreservePluginName: newPlugin(unreservePlugin), unreservePluginName: newPlugin(unreservePlugin),
preBindPluginName: newPlugin(preBindPlugin), preBindPluginName: newPlugin(preBindPlugin),
} }
@ -1055,7 +1056,7 @@ func TestBindPlugin(t *testing.T) {
unreservePlugin := &UnreservePlugin{name: "mock-unreserve-plugin"} unreservePlugin := &UnreservePlugin{name: "mock-unreserve-plugin"}
postBindPlugin := &PostBindPlugin{name: "mock-post-bind-plugin"} postBindPlugin := &PostBindPlugin{name: "mock-post-bind-plugin"}
// Create a plugin registry for testing. Register an unreserve, a bind plugin and a postBind plugin. // Create a plugin registry for testing. Register an unreserve, a bind plugin and a postBind plugin.
registry := framework.Registry{ registry := frameworkruntime.Registry{
unreservePlugin.Name(): func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) { unreservePlugin.Name(): func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) {
return unreservePlugin, nil return unreservePlugin, nil
}, },
@ -1230,7 +1231,7 @@ func TestPostBindPlugin(t *testing.T) {
// Create a plugin registry for testing. Register a prebind and a postbind plugin. // Create a plugin registry for testing. Register a prebind and a postbind plugin.
preBindPlugin := &PreBindPlugin{} preBindPlugin := &PreBindPlugin{}
postBindPlugin := &PostBindPlugin{name: postBindPluginName} postBindPlugin := &PostBindPlugin{name: postBindPluginName}
registry := framework.Registry{ registry := frameworkruntime.Registry{
preBindPluginName: newPlugin(preBindPlugin), preBindPluginName: newPlugin(preBindPlugin),
postBindPluginName: newPlugin(postBindPlugin), postBindPluginName: newPlugin(postBindPlugin),
} }
@ -1594,7 +1595,7 @@ func TestCoSchedulingWithPermitPlugin(t *testing.T) {
func TestFilterPlugin(t *testing.T) { func TestFilterPlugin(t *testing.T) {
// Create a plugin registry for testing. Register only a filter plugin. // Create a plugin registry for testing. Register only a filter plugin.
filterPlugin := &FilterPlugin{} filterPlugin := &FilterPlugin{}
registry := framework.Registry{filterPluginName: newPlugin(filterPlugin)} registry := frameworkruntime.Registry{filterPluginName: newPlugin(filterPlugin)}
// Setup initial filter plugin for testing. // Setup initial filter plugin for testing.
prof := schedulerconfig.KubeSchedulerProfile{ prof := schedulerconfig.KubeSchedulerProfile{
@ -1664,7 +1665,7 @@ func TestFilterPlugin(t *testing.T) {
func TestPreScorePlugin(t *testing.T) { func TestPreScorePlugin(t *testing.T) {
// Create a plugin registry for testing. Register only a pre-score plugin. // Create a plugin registry for testing. Register only a pre-score plugin.
preScorePlugin := &PreScorePlugin{} preScorePlugin := &PreScorePlugin{}
registry := framework.Registry{preScorePluginName: newPlugin(preScorePlugin)} registry := frameworkruntime.Registry{preScorePluginName: newPlugin(preScorePlugin)}
// Setup initial pre-score plugin for testing. // Setup initial pre-score plugin for testing.
prof := schedulerconfig.KubeSchedulerProfile{ prof := schedulerconfig.KubeSchedulerProfile{
@ -1818,12 +1819,12 @@ func initTestSchedulerForFrameworkTest(t *testing.T, testCtx *testutils.TestCont
// initRegistryAndConfig returns registry and plugins config based on give plugins. // initRegistryAndConfig returns registry and plugins config based on give plugins.
// TODO: refactor it to a more generic functions that accepts all kinds of Plugins as arguments // TODO: refactor it to a more generic functions that accepts all kinds of Plugins as arguments
func initRegistryAndConfig(pp ...*PermitPlugin) (registry framework.Registry, prof schedulerconfig.KubeSchedulerProfile) { func initRegistryAndConfig(pp ...*PermitPlugin) (registry frameworkruntime.Registry, prof schedulerconfig.KubeSchedulerProfile) {
if len(pp) == 0 { if len(pp) == 0 {
return return
} }
registry = framework.Registry{} registry = frameworkruntime.Registry{}
var plugins []schedulerconfig.Plugin var plugins []schedulerconfig.Plugin
for _, p := range pp { for _, p := range pp {
registry.Register(p.Name(), newPermitPlugin(p)) registry.Register(p.Name(), newPermitPlugin(p))

View File

@ -45,6 +45,7 @@ import (
"k8s.io/kubernetes/pkg/features" "k8s.io/kubernetes/pkg/features"
"k8s.io/kubernetes/pkg/scheduler" "k8s.io/kubernetes/pkg/scheduler"
schedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config" schedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
frameworkruntime "k8s.io/kubernetes/pkg/scheduler/framework/runtime"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
"k8s.io/kubernetes/plugin/pkg/admission/priority" "k8s.io/kubernetes/plugin/pkg/admission/priority"
testutils "k8s.io/kubernetes/test/integration/util" testutils "k8s.io/kubernetes/test/integration/util"
@ -124,7 +125,7 @@ var _ framework.FilterPlugin = &tokenFilter{}
func TestPreemption(t *testing.T) { func TestPreemption(t *testing.T) {
// Initialize scheduler with a filter plugin. // Initialize scheduler with a filter plugin.
var filter tokenFilter var filter tokenFilter
registry := make(framework.Registry) registry := make(frameworkruntime.Registry)
err := registry.Register(filterPluginName, func(_ runtime.Object, fh framework.FrameworkHandle) (framework.Plugin, error) { err := registry.Register(filterPluginName, func(_ runtime.Object, fh framework.FrameworkHandle) (framework.Plugin, error) {
return &filter, nil return &filter, nil
}) })