diff --git a/build/visible_to/BUILD b/build/visible_to/BUILD index edfc4743525..efa83c4fe5a 100644 --- a/build/visible_to/BUILD +++ b/build/visible_to/BUILD @@ -429,7 +429,7 @@ package_group( name = "vendor_githubcom_prometheus_CONSUMERS", packages = [ "//cluster/images/etcd-version-monitor", - "//pkg/scheduler/framework/v1alpha1", + "//pkg/scheduler/framework/runtime", "//pkg/volume/util/operationexecutor", "//staging/src/k8s.io/apiserver/pkg/admission/metrics", "//staging/src/k8s.io/component-base/metrics/...", diff --git a/cmd/kube-scheduler/app/BUILD b/cmd/kube-scheduler/app/BUILD index cfbe557293a..ec377b17fe8 100644 --- a/cmd/kube-scheduler/app/BUILD +++ b/cmd/kube-scheduler/app/BUILD @@ -16,7 +16,7 @@ go_library( "//pkg/api/legacyscheme:go_default_library", "//pkg/scheduler: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/profile:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library", diff --git a/cmd/kube-scheduler/app/server.go b/cmd/kube-scheduler/app/server.go index 3694ac803b6..0d7ea066e48 100644 --- a/cmd/kube-scheduler/app/server.go +++ b/cmd/kube-scheduler/app/server.go @@ -57,13 +57,13 @@ import ( "k8s.io/kubernetes/pkg/api/legacyscheme" "k8s.io/kubernetes/pkg/scheduler" 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/profile" ) // 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 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, // hence there are no references to it from the kubernetes scheduler code base. -func WithPlugin(name string, factory framework.PluginFactory) Option { - return func(registry framework.Registry) error { +func WithPlugin(name string, factory runtime.PluginFactory) Option { + return func(registry runtime.Registry) error { return registry.Register(name, factory) } } @@ -319,7 +319,7 @@ func Setup(ctx context.Context, opts *options.Options, outOfTreeRegistryOptions // Get the completed config cc := c.Complete() - outOfTreeRegistry := make(framework.Registry) + outOfTreeRegistry := make(runtime.Registry) for _, option := range outOfTreeRegistryOptions { if err := option(outOfTreeRegistry); err != nil { return nil, nil, err diff --git a/pkg/scheduler/BUILD b/pkg/scheduler/BUILD index 5f4c5b5cc85..1948f1527ce 100644 --- a/pkg/scheduler/BUILD +++ b/pkg/scheduler/BUILD @@ -21,6 +21,7 @@ go_library( "//pkg/scheduler/framework/plugins/defaultbinder:go_default_library", "//pkg/scheduler/framework/plugins/noderesources: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/internal/cache: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/serviceaffinity: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/internal/cache:go_default_library", "//pkg/scheduler/internal/cache/fake:go_default_library", diff --git a/pkg/scheduler/core/BUILD b/pkg/scheduler/core/BUILD index b72c559a105..6696aaa933d 100644 --- a/pkg/scheduler/core/BUILD +++ b/pkg/scheduler/core/BUILD @@ -12,6 +12,7 @@ go_library( "//pkg/api/v1/pod:go_default_library", "//pkg/features: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/internal/cache: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/volumerestrictions: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/fake:go_default_library", "//pkg/scheduler/internal/cache:go_default_library", diff --git a/pkg/scheduler/core/extender_test.go b/pkg/scheduler/core/extender_test.go index f02aa25cb65..53367786048 100644 --- a/pkg/scheduler/core/extender_test.go +++ b/pkg/scheduler/core/extender_test.go @@ -32,6 +32,7 @@ import ( schedulerapi "k8s.io/kubernetes/pkg/scheduler/apis/config" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/defaultbinder" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/queuesort" + "k8s.io/kubernetes/pkg/scheduler/framework/runtime" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" internalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache" internalqueue "k8s.io/kubernetes/pkg/scheduler/internal/queue" @@ -269,7 +270,7 @@ func TestGenericSchedulerWithExtenders(t *testing.T) { } 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 { t.Fatal(err) } diff --git a/pkg/scheduler/core/generic_scheduler.go b/pkg/scheduler/core/generic_scheduler.go index 1ea72edeba3..5a5541423ab 100644 --- a/pkg/scheduler/core/generic_scheduler.go +++ b/pkg/scheduler/core/generic_scheduler.go @@ -38,6 +38,7 @@ import ( extenderv1 "k8s.io/kube-scheduler/extender/v1" podutil "k8s.io/kubernetes/pkg/api/v1/pod" kubefeatures "k8s.io/kubernetes/pkg/features" + "k8s.io/kubernetes/pkg/scheduler/framework/runtime" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" internalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache" "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 // 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. - 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 diff --git a/pkg/scheduler/core/generic_scheduler_test.go b/pkg/scheduler/core/generic_scheduler_test.go index a1e13a2ed1e..98922a639e1 100644 --- a/pkg/scheduler/core/generic_scheduler_test.go +++ b/pkg/scheduler/core/generic_scheduler_test.go @@ -54,6 +54,7 @@ import ( "k8s.io/kubernetes/pkg/scheduler/framework/plugins/tainttoleration" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumerestrictions" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumezone" + frameworkruntime "k8s.io/kubernetes/pkg/scheduler/framework/runtime" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" fakeframework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1/fake" internalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache" @@ -89,7 +90,7 @@ func NewNoPodsFilterPlugin(_ runtime.Object, _ framework.FrameworkHandle) (frame type numericMapPlugin struct{} -func newNumericMapPlugin() framework.PluginFactory { +func newNumericMapPlugin() frameworkruntime.PluginFactory { return func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) { return &numericMapPlugin{}, nil } @@ -113,7 +114,7 @@ func (pl *numericMapPlugin) ScoreExtensions() framework.ScoreExtensions { type reverseNumericMapPlugin struct{} -func newReverseNumericMapPlugin() framework.PluginFactory { +func newReverseNumericMapPlugin() frameworkruntime.PluginFactory { return func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) { return &reverseNumericMapPlugin{}, nil } @@ -154,7 +155,7 @@ func (pl *reverseNumericMapPlugin) NormalizeScore(_ context.Context, _ *framewor type trueMapPlugin struct{} -func newTrueMapPlugin() framework.PluginFactory { +func newTrueMapPlugin() frameworkruntime.PluginFactory { return func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) { return &trueMapPlugin{}, nil } @@ -183,7 +184,7 @@ func (pl *trueMapPlugin) NormalizeScore(_ context.Context, _ *framework.CycleSta type falseMapPlugin struct{} -func newFalseMapPlugin() framework.PluginFactory { +func newFalseMapPlugin() frameworkruntime.PluginFactory { return func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) { return &falseMapPlugin{}, nil } @@ -705,7 +706,7 @@ func TestGenericScheduler(t *testing.T) { } 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 { t.Fatal(err) } @@ -1026,9 +1027,9 @@ func TestZeroRequest(t *testing.T) { } fwk, err := st.NewFramework( pluginRegistrations, - framework.WithInformerFactory(informerFactory), - framework.WithSnapshotSharedLister(snapshot), - framework.WithClientSet(client), + frameworkruntime.WithInformerFactory(informerFactory), + frameworkruntime.WithSnapshotSharedLister(snapshot), + frameworkruntime.WithClientSet(client), ) if err != nil { t.Fatalf("error creating framework: %+v", err) @@ -1538,7 +1539,7 @@ func TestSelectNodesForPreemption(t *testing.T) { registerPlugins := append([]st.RegisterPluginFunc{registerFakeFilterFunc}, test.registerPlugins...) // Use a real snapshot since it's needed in some Filter Plugin (e.g., PodAffinity) 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 { t.Fatal(err) } @@ -1825,7 +1826,7 @@ func TestPickOneNodeForPreemption(t *testing.T) { nodes = append(nodes, makeNode(n, schedutil.DefaultMilliCPURequest*5, schedutil.DefaultMemoryRequest*5)) } 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 { t.Fatal(err) } @@ -2338,12 +2339,12 @@ func TestPreempt(t *testing.T) { snapshot := internalcache.NewSnapshot(test.pods, nodes) fwk, err := st.NewFramework( test.registerPlugins, - framework.WithClientSet(client), - framework.WithEventRecorder(&events.FakeRecorder{}), - framework.WithExtenders(extenders), - framework.WithPodNominator(podNominator), - framework.WithSnapshotSharedLister(snapshot), - framework.WithInformerFactory(informers.NewSharedInformerFactory(client, 0)), + frameworkruntime.WithClientSet(client), + frameworkruntime.WithEventRecorder(&events.FakeRecorder{}), + frameworkruntime.WithExtenders(extenders), + frameworkruntime.WithPodNominator(podNominator), + frameworkruntime.WithSnapshotSharedLister(snapshot), + frameworkruntime.WithInformerFactory(informers.NewSharedInformerFactory(client, 0)), ) if err != nil { t.Fatal(err) diff --git a/pkg/scheduler/factory.go b/pkg/scheduler/factory.go index 4b02dbbb30b..948550c56d6 100644 --- a/pkg/scheduler/factory.go +++ b/pkg/scheduler/factory.go @@ -44,6 +44,7 @@ import ( "k8s.io/kubernetes/pkg/scheduler/framework/plugins/defaultbinder" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/noderesources" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/queuesort" + frameworkruntime "k8s.io/kubernetes/pkg/scheduler/framework/runtime" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" internalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache" cachedebugger "k8s.io/kubernetes/pkg/scheduler/internal/cache/debugger" @@ -86,23 +87,23 @@ type Configurator struct { podMaxBackoffSeconds int64 profiles []schedulerapi.KubeSchedulerProfile - registry framework.Registry + registry frameworkruntime.Registry nodeInfoSnapshot *internalcache.Snapshot extenders []schedulerapi.Extender 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 { c.frameworkCapturer(p) } - opts = append([]framework.Option{ - framework.WithClientSet(c.client), - framework.WithInformerFactory(c.informerFactory), - framework.WithSnapshotSharedLister(c.nodeInfoSnapshot), - framework.WithRunAllFilters(c.alwaysCheckAllPredicates), + opts = append([]frameworkruntime.Option{ + frameworkruntime.WithClientSet(c.client), + frameworkruntime.WithInformerFactory(c.informerFactory), + frameworkruntime.WithSnapshotSharedLister(c.nodeInfoSnapshot), + frameworkruntime.WithRunAllFilters(c.alwaysCheckAllPredicates), }, opts...) - return framework.NewFramework( + return frameworkruntime.NewFramework( c.registry, p.Plugins, p.PluginConfig, @@ -158,7 +159,7 @@ func (c *Configurator) create() (*Scheduler, error) { // The nominator will be passed all the way to framework instantiation. nominator := internalqueue.NewPodNominator() profiles, err := profile.NewMap(c.profiles, c.buildFramework, c.recorderFactory, - framework.WithPodNominator(nominator)) + frameworkruntime.WithPodNominator(nominator)) if err != nil { return nil, fmt.Errorf("initializing profiles: %v", err) } diff --git a/pkg/scheduler/factory_test.go b/pkg/scheduler/factory_test.go index 2fc8dcf9959..0c6412c02e6 100644 --- a/pkg/scheduler/factory_test.go +++ b/pkg/scheduler/factory_test.go @@ -44,6 +44,7 @@ import ( "k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodelabel" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/queuesort" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/serviceaffinity" + frameworkruntime "k8s.io/kubernetes/pkg/scheduler/framework/runtime" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" internalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache" internalqueue "k8s.io/kubernetes/pkg/scheduler/internal/queue" @@ -445,7 +446,7 @@ func getPodFromPriorityQueue(queue *internalqueue.PriorityQueue, pod *v1.Pod) *v func newConfigFactoryWithFrameworkRegistry( client clientset.Interface, stopCh <-chan struct{}, - registry framework.Registry) *Configurator { + registry frameworkruntime.Registry) *Configurator { informerFactory := informers.NewSharedInformerFactory(client, 0) snapshot := internalcache.NewEmptySnapshot() recorderFactory := profile.NewRecorderFactory(events.NewBroadcaster(&events.EventSinkImpl{Interface: client.EventsV1beta1().Events("")})) diff --git a/pkg/scheduler/framework/BUILD b/pkg/scheduler/framework/BUILD index cc7ff21bbc8..e74a5ba44dd 100644 --- a/pkg/scheduler/framework/BUILD +++ b/pkg/scheduler/framework/BUILD @@ -10,6 +10,7 @@ filegroup( srcs = [ ":package-srcs", "//pkg/scheduler/framework/plugins:all-srcs", + "//pkg/scheduler/framework/runtime:all-srcs", "//pkg/scheduler/framework/v1alpha1:all-srcs", ], tags = ["automanaged"], diff --git a/pkg/scheduler/framework/plugins/BUILD b/pkg/scheduler/framework/plugins/BUILD index a65144171cb..2587603af10 100644 --- a/pkg/scheduler/framework/plugins/BUILD +++ b/pkg/scheduler/framework/plugins/BUILD @@ -29,7 +29,7 @@ go_library( "//pkg/scheduler/framework/plugins/volumebinding:go_default_library", "//pkg/scheduler/framework/plugins/volumerestrictions: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", "//vendor/k8s.io/klog/v2:go_default_library", ], diff --git a/pkg/scheduler/framework/plugins/defaultbinder/BUILD b/pkg/scheduler/framework/plugins/defaultbinder/BUILD index 9f468860455..003165618a2 100644 --- a/pkg/scheduler/framework/plugins/defaultbinder/BUILD +++ b/pkg/scheduler/framework/plugins/defaultbinder/BUILD @@ -19,7 +19,7 @@ go_test( srcs = ["default_binder_test.go"], embed = [":go_default_library"], 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/apimachinery/pkg/apis/meta/v1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", diff --git a/pkg/scheduler/framework/plugins/defaultbinder/default_binder_test.go b/pkg/scheduler/framework/plugins/defaultbinder/default_binder_test.go index ae765ab13fd..76d68eb08f3 100644 --- a/pkg/scheduler/framework/plugins/defaultbinder/default_binder_test.go +++ b/pkg/scheduler/framework/plugins/defaultbinder/default_binder_test.go @@ -27,7 +27,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/kubernetes/fake" 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) { @@ -66,7 +66,7 @@ func TestDefaultBinder(t *testing.T) { 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 { t.Fatal(err) } diff --git a/pkg/scheduler/framework/plugins/defaultpodtopologyspread/BUILD b/pkg/scheduler/framework/plugins/defaultpodtopologyspread/BUILD index 6b40217b153..56c0a81a1b0 100644 --- a/pkg/scheduler/framework/plugins/defaultpodtopologyspread/BUILD +++ b/pkg/scheduler/framework/plugins/defaultpodtopologyspread/BUILD @@ -23,6 +23,7 @@ go_test( ], embed = [":go_default_library"], deps = [ + "//pkg/scheduler/framework/runtime:go_default_library", "//pkg/scheduler/framework/v1alpha1:go_default_library", "//pkg/scheduler/internal/cache:go_default_library", "//pkg/scheduler/internal/parallelize:go_default_library", diff --git a/pkg/scheduler/framework/plugins/defaultpodtopologyspread/default_pod_topology_spread_perf_test.go b/pkg/scheduler/framework/plugins/defaultpodtopologyspread/default_pod_topology_spread_perf_test.go index 212e70a1f26..bbe3aa7a26e 100644 --- a/pkg/scheduler/framework/plugins/defaultpodtopologyspread/default_pod_topology_spread_perf_test.go +++ b/pkg/scheduler/framework/plugins/defaultpodtopologyspread/default_pod_topology_spread_perf_test.go @@ -23,6 +23,7 @@ import ( v1 "k8s.io/api/core/v1" "k8s.io/client-go/informers" "k8s.io/client-go/kubernetes/fake" + "k8s.io/kubernetes/pkg/scheduler/framework/runtime" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" "k8s.io/kubernetes/pkg/scheduler/internal/cache" "k8s.io/kubernetes/pkg/scheduler/internal/parallelize" @@ -67,7 +68,7 @@ func BenchmarkTestSelectorSpreadPriority(b *testing.B) { 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} b.ResetTimer() diff --git a/pkg/scheduler/framework/plugins/defaultpodtopologyspread/default_pod_topology_spread_test.go b/pkg/scheduler/framework/plugins/defaultpodtopologyspread/default_pod_topology_spread_test.go index feec7694b1d..8d7febbfcbb 100644 --- a/pkg/scheduler/framework/plugins/defaultpodtopologyspread/default_pod_topology_spread_test.go +++ b/pkg/scheduler/framework/plugins/defaultpodtopologyspread/default_pod_topology_spread_test.go @@ -29,6 +29,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/informers" clientsetfake "k8s.io/client-go/kubernetes/fake" + frameworkruntime "k8s.io/kubernetes/pkg/scheduler/framework/runtime" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" "k8s.io/kubernetes/pkg/scheduler/internal/cache" ) @@ -375,7 +376,7 @@ func TestDefaultPodTopologySpreadScore(t *testing.T) { if err != nil { 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 { t.Errorf("error creating new framework handle: %+v", err) } @@ -629,7 +630,7 @@ func TestZoneSelectorSpreadPriority(t *testing.T) { if err != nil { 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 { t.Errorf("error creating new framework handle: %+v", err) } diff --git a/pkg/scheduler/framework/plugins/imagelocality/BUILD b/pkg/scheduler/framework/plugins/imagelocality/BUILD index ea4bac8eaec..9cd2d89ae39 100644 --- a/pkg/scheduler/framework/plugins/imagelocality/BUILD +++ b/pkg/scheduler/framework/plugins/imagelocality/BUILD @@ -17,6 +17,7 @@ go_test( srcs = ["image_locality_test.go"], embed = [":go_default_library"], deps = [ + "//pkg/scheduler/framework/runtime:go_default_library", "//pkg/scheduler/framework/v1alpha1:go_default_library", "//pkg/scheduler/internal/cache:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library", diff --git a/pkg/scheduler/framework/plugins/imagelocality/image_locality_test.go b/pkg/scheduler/framework/plugins/imagelocality/image_locality_test.go index 04c59ab6b41..81e9b53a138 100644 --- a/pkg/scheduler/framework/plugins/imagelocality/image_locality_test.go +++ b/pkg/scheduler/framework/plugins/imagelocality/image_locality_test.go @@ -25,6 +25,7 @@ import ( v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/kubernetes/pkg/scheduler/framework/runtime" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" "k8s.io/kubernetes/pkg/scheduler/internal/cache" ) @@ -334,7 +335,7 @@ func TestImageLocalityPriority(t *testing.T) { 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) var gotList framework.NodeScoreList diff --git a/pkg/scheduler/framework/plugins/interpodaffinity/BUILD b/pkg/scheduler/framework/plugins/interpodaffinity/BUILD index 3c4ac73435b..3600870ef5b 100644 --- a/pkg/scheduler/framework/plugins/interpodaffinity/BUILD +++ b/pkg/scheduler/framework/plugins/interpodaffinity/BUILD @@ -30,6 +30,7 @@ go_test( embed = [":go_default_library"], deps = [ "//pkg/scheduler/apis/config:go_default_library", + "//pkg/scheduler/framework/runtime:go_default_library", "//pkg/scheduler/framework/v1alpha1:go_default_library", "//pkg/scheduler/internal/cache:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library", diff --git a/pkg/scheduler/framework/plugins/interpodaffinity/scoring_test.go b/pkg/scheduler/framework/plugins/interpodaffinity/scoring_test.go index 8c3fc6e930a..766e4fc35f1 100644 --- a/pkg/scheduler/framework/plugins/interpodaffinity/scoring_test.go +++ b/pkg/scheduler/framework/plugins/interpodaffinity/scoring_test.go @@ -24,6 +24,7 @@ import ( v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/kubernetes/pkg/scheduler/apis/config" + "k8s.io/kubernetes/pkg/scheduler/framework/runtime" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" "k8s.io/kubernetes/pkg/scheduler/internal/cache" ) @@ -625,7 +626,7 @@ func TestPreferredAffinityWithHardPodAffinitySymmetricWeight(t *testing.T) { t.Run(test.name, func(t *testing.T) { state := framework.NewCycleState() 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} p, err := New(args, fh) diff --git a/pkg/scheduler/framework/plugins/nodeaffinity/BUILD b/pkg/scheduler/framework/plugins/nodeaffinity/BUILD index 986561ca45e..9bbb9ba0dfa 100644 --- a/pkg/scheduler/framework/plugins/nodeaffinity/BUILD +++ b/pkg/scheduler/framework/plugins/nodeaffinity/BUILD @@ -35,6 +35,7 @@ go_test( embed = [":go_default_library"], deps = [ "//pkg/apis/core:go_default_library", + "//pkg/scheduler/framework/runtime:go_default_library", "//pkg/scheduler/framework/v1alpha1:go_default_library", "//pkg/scheduler/internal/cache:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library", diff --git a/pkg/scheduler/framework/plugins/nodeaffinity/node_affinity_test.go b/pkg/scheduler/framework/plugins/nodeaffinity/node_affinity_test.go index fdefc85479c..a6f03b48614 100644 --- a/pkg/scheduler/framework/plugins/nodeaffinity/node_affinity_test.go +++ b/pkg/scheduler/framework/plugins/nodeaffinity/node_affinity_test.go @@ -24,6 +24,7 @@ import ( v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" api "k8s.io/kubernetes/pkg/apis/core" + "k8s.io/kubernetes/pkg/scheduler/framework/runtime" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" "k8s.io/kubernetes/pkg/scheduler/internal/cache" ) @@ -848,7 +849,7 @@ func TestNodeAffinityPriority(t *testing.T) { t.Run(test.name, func(t *testing.T) { 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) var gotList framework.NodeScoreList for _, n := range test.nodes { diff --git a/pkg/scheduler/framework/plugins/nodelabel/BUILD b/pkg/scheduler/framework/plugins/nodelabel/BUILD index 9e1b636d1a3..8fde2c0d3e9 100644 --- a/pkg/scheduler/framework/plugins/nodelabel/BUILD +++ b/pkg/scheduler/framework/plugins/nodelabel/BUILD @@ -21,6 +21,7 @@ go_test( embed = [":go_default_library"], deps = [ "//pkg/scheduler/apis/config:go_default_library", + "//pkg/scheduler/framework/runtime:go_default_library", "//pkg/scheduler/framework/v1alpha1:go_default_library", "//pkg/scheduler/internal/cache:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library", diff --git a/pkg/scheduler/framework/plugins/nodelabel/node_label_test.go b/pkg/scheduler/framework/plugins/nodelabel/node_label_test.go index af1e4646fa4..b536651b37d 100644 --- a/pkg/scheduler/framework/plugins/nodelabel/node_label_test.go +++ b/pkg/scheduler/framework/plugins/nodelabel/node_label_test.go @@ -23,6 +23,7 @@ import ( v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/kubernetes/pkg/scheduler/apis/config" + "k8s.io/kubernetes/pkg/scheduler/framework/runtime" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" "k8s.io/kubernetes/pkg/scheduler/internal/cache" ) @@ -236,7 +237,7 @@ func TestNodeLabelScore(t *testing.T) { t.Run(test.name, func(t *testing.T) { state := framework.NewCycleState() node := &v1.Node{ObjectMeta: metav1.ObjectMeta{Name: "machine1", Labels: map[string]string{"foo": "", "bar": ""}}} - fh, _ := 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) if err != nil { t.Fatalf("Failed to create plugin: %+v", err) @@ -270,7 +271,7 @@ func TestNodeLabelFilterWithoutNode(t *testing.T) { func TestNodeLabelScoreWithoutNode(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) if err != nil { t.Fatalf("Failed to create plugin: %+v", err) diff --git a/pkg/scheduler/framework/plugins/nodepreferavoidpods/BUILD b/pkg/scheduler/framework/plugins/nodepreferavoidpods/BUILD index 7beedb8fed2..6aa284192d3 100644 --- a/pkg/scheduler/framework/plugins/nodepreferavoidpods/BUILD +++ b/pkg/scheduler/framework/plugins/nodepreferavoidpods/BUILD @@ -19,6 +19,7 @@ go_test( srcs = ["node_prefer_avoid_pods_test.go"], embed = [":go_default_library"], deps = [ + "//pkg/scheduler/framework/runtime:go_default_library", "//pkg/scheduler/framework/v1alpha1:go_default_library", "//pkg/scheduler/internal/cache:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library", diff --git a/pkg/scheduler/framework/plugins/nodepreferavoidpods/node_prefer_avoid_pods_test.go b/pkg/scheduler/framework/plugins/nodepreferavoidpods/node_prefer_avoid_pods_test.go index e7d85fb608c..8369407b2fc 100644 --- a/pkg/scheduler/framework/plugins/nodepreferavoidpods/node_prefer_avoid_pods_test.go +++ b/pkg/scheduler/framework/plugins/nodepreferavoidpods/node_prefer_avoid_pods_test.go @@ -23,6 +23,7 @@ import ( v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/kubernetes/pkg/scheduler/framework/runtime" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" "k8s.io/kubernetes/pkg/scheduler/internal/cache" ) @@ -143,7 +144,7 @@ func TestNodePreferAvoidPods(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { 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) var gotList framework.NodeScoreList for _, n := range test.nodes { diff --git a/pkg/scheduler/framework/plugins/noderesources/BUILD b/pkg/scheduler/framework/plugins/noderesources/BUILD index ca0b1ad4848..e15554bea3b 100644 --- a/pkg/scheduler/framework/plugins/noderesources/BUILD +++ b/pkg/scheduler/framework/plugins/noderesources/BUILD @@ -58,6 +58,7 @@ go_test( "//pkg/apis/core/v1/helper:go_default_library", "//pkg/features: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/internal/cache:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library", diff --git a/pkg/scheduler/framework/plugins/noderesources/balanced_allocation_test.go b/pkg/scheduler/framework/plugins/noderesources/balanced_allocation_test.go index 575bce1aa7c..9e7412a65d0 100644 --- a/pkg/scheduler/framework/plugins/noderesources/balanced_allocation_test.go +++ b/pkg/scheduler/framework/plugins/noderesources/balanced_allocation_test.go @@ -27,6 +27,7 @@ import ( utilfeature "k8s.io/apiserver/pkg/util/feature" featuregatetesting "k8s.io/component-base/featuregate/testing" "k8s.io/kubernetes/pkg/features" + "k8s.io/kubernetes/pkg/scheduler/framework/runtime" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" "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) } } - fh, _ := framework.NewFramework(nil, nil, nil, framework.WithSnapshotSharedLister(snapshot)) + fh, _ := runtime.NewFramework(nil, nil, nil, runtime.WithSnapshotSharedLister(snapshot)) p, _ := NewBalancedAllocation(nil, fh) for i := range test.nodes { diff --git a/pkg/scheduler/framework/plugins/noderesources/least_allocated_test.go b/pkg/scheduler/framework/plugins/noderesources/least_allocated_test.go index aa5cbeb1a69..127a2981275 100644 --- a/pkg/scheduler/framework/plugins/noderesources/least_allocated_test.go +++ b/pkg/scheduler/framework/plugins/noderesources/least_allocated_test.go @@ -25,6 +25,7 @@ import ( "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/kubernetes/pkg/scheduler/apis/config" + "k8s.io/kubernetes/pkg/scheduler/framework/runtime" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" "k8s.io/kubernetes/pkg/scheduler/internal/cache" ) @@ -286,7 +287,7 @@ func TestNodeResourcesLeastAllocated(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { snapshot := cache.NewSnapshot(test.pods, test.nodes) - fh, _ := framework.NewFramework(nil, nil, nil, framework.WithSnapshotSharedLister(snapshot)) + fh, _ := runtime.NewFramework(nil, nil, nil, runtime.WithSnapshotSharedLister(snapshot)) p, err := NewLeastAllocated(&test.args, fh) if len(test.wantErr) != 0 { diff --git a/pkg/scheduler/framework/plugins/noderesources/most_allocated_test.go b/pkg/scheduler/framework/plugins/noderesources/most_allocated_test.go index bc03ef0ed54..d10e87e8dc0 100644 --- a/pkg/scheduler/framework/plugins/noderesources/most_allocated_test.go +++ b/pkg/scheduler/framework/plugins/noderesources/most_allocated_test.go @@ -25,6 +25,7 @@ import ( "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/kubernetes/pkg/scheduler/apis/config" + "k8s.io/kubernetes/pkg/scheduler/framework/runtime" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" "k8s.io/kubernetes/pkg/scheduler/internal/cache" ) @@ -246,7 +247,7 @@ func TestNodeResourcesMostAllocated(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { snapshot := cache.NewSnapshot(test.pods, test.nodes) - fh, _ := framework.NewFramework(nil, nil, nil, framework.WithSnapshotSharedLister(snapshot)) + fh, _ := runtime.NewFramework(nil, nil, nil, runtime.WithSnapshotSharedLister(snapshot)) p, err := NewMostAllocated(&test.args, fh) if len(test.wantErr) != 0 { diff --git a/pkg/scheduler/framework/plugins/noderesources/requested_to_capacity_ratio_test.go b/pkg/scheduler/framework/plugins/noderesources/requested_to_capacity_ratio_test.go index 4afac0bfca0..b21966afd11 100644 --- a/pkg/scheduler/framework/plugins/noderesources/requested_to_capacity_ratio_test.go +++ b/pkg/scheduler/framework/plugins/noderesources/requested_to_capacity_ratio_test.go @@ -25,6 +25,7 @@ import ( v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" "k8s.io/kubernetes/pkg/scheduler/apis/config" + "k8s.io/kubernetes/pkg/scheduler/framework/runtime" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" "k8s.io/kubernetes/pkg/scheduler/internal/cache" ) @@ -66,7 +67,7 @@ func TestRequestedToCapacityRatio(t *testing.T) { t.Run(test.name, func(t *testing.T) { state := framework.NewCycleState() snapshot := cache.NewSnapshot(test.scheduledPods, test.nodes) - fh, _ := framework.NewFramework(nil, nil, nil, framework.WithSnapshotSharedLister(snapshot)) + fh, _ := runtime.NewFramework(nil, nil, nil, runtime.WithSnapshotSharedLister(snapshot)) args := config.RequestedToCapacityRatioArgs{ Shape: []config.UtilizationShapePoint{ {Utilization: 0, Score: 10}, @@ -318,7 +319,7 @@ func TestResourceBinPackingSingleExtended(t *testing.T) { t.Run(test.name, func(t *testing.T) { state := framework.NewCycleState() snapshot := cache.NewSnapshot(test.pods, test.nodes) - fh, _ := framework.NewFramework(nil, nil, nil, framework.WithSnapshotSharedLister(snapshot)) + fh, _ := runtime.NewFramework(nil, nil, nil, runtime.WithSnapshotSharedLister(snapshot)) args := config.RequestedToCapacityRatioArgs{ Shape: []config.UtilizationShapePoint{ {Utilization: 0, Score: 0}, @@ -561,7 +562,7 @@ func TestResourceBinPackingMultipleExtended(t *testing.T) { t.Run(test.name, func(t *testing.T) { state := framework.NewCycleState() snapshot := cache.NewSnapshot(test.pods, test.nodes) - fh, _ := framework.NewFramework(nil, nil, nil, framework.WithSnapshotSharedLister(snapshot)) + fh, _ := runtime.NewFramework(nil, nil, nil, runtime.WithSnapshotSharedLister(snapshot)) args := config.RequestedToCapacityRatioArgs{ Shape: []config.UtilizationShapePoint{ {Utilization: 0, Score: 0}, diff --git a/pkg/scheduler/framework/plugins/registry.go b/pkg/scheduler/framework/plugins/registry.go index f21c3af4e48..2cb4b8d7d93 100644 --- a/pkg/scheduler/framework/plugins/registry.go +++ b/pkg/scheduler/framework/plugins/registry.go @@ -36,14 +36,14 @@ import ( "k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumebinding" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumerestrictions" "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. // A scheduler that runs out of tree plugins can register additional plugins // through the WithFrameworkOutOfTreeRegistry option. -func NewInTreeRegistry() framework.Registry { - return framework.Registry{ +func NewInTreeRegistry() runtime.Registry { + return runtime.Registry{ defaultpodtopologyspread.Name: defaultpodtopologyspread.New, imagelocality.Name: imagelocality.New, tainttoleration.Name: tainttoleration.New, diff --git a/pkg/scheduler/framework/plugins/tainttoleration/BUILD b/pkg/scheduler/framework/plugins/tainttoleration/BUILD index 7fb3f837601..52557086536 100644 --- a/pkg/scheduler/framework/plugins/tainttoleration/BUILD +++ b/pkg/scheduler/framework/plugins/tainttoleration/BUILD @@ -33,6 +33,7 @@ go_test( srcs = ["taint_toleration_test.go"], embed = [":go_default_library"], deps = [ + "//pkg/scheduler/framework/runtime:go_default_library", "//pkg/scheduler/framework/v1alpha1:go_default_library", "//pkg/scheduler/internal/cache:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library", diff --git a/pkg/scheduler/framework/plugins/tainttoleration/taint_toleration_test.go b/pkg/scheduler/framework/plugins/tainttoleration/taint_toleration_test.go index a3377b3308f..093d4e12f17 100644 --- a/pkg/scheduler/framework/plugins/tainttoleration/taint_toleration_test.go +++ b/pkg/scheduler/framework/plugins/tainttoleration/taint_toleration_test.go @@ -23,6 +23,7 @@ import ( v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/kubernetes/pkg/scheduler/framework/runtime" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" "k8s.io/kubernetes/pkg/scheduler/internal/cache" ) @@ -229,7 +230,7 @@ func TestTaintTolerationScore(t *testing.T) { t.Run(test.name, func(t *testing.T) { state := framework.NewCycleState() snapshot := cache.NewSnapshot(nil, test.nodes) - fh, _ := framework.NewFramework(nil, nil, nil, framework.WithSnapshotSharedLister(snapshot)) + fh, _ := runtime.NewFramework(nil, nil, nil, runtime.WithSnapshotSharedLister(snapshot)) p, _ := New(nil, fh) status := p.(framework.PreScorePlugin).PreScore(context.Background(), state, test.pod, test.nodes) diff --git a/pkg/scheduler/framework/plugins/volumebinding/BUILD b/pkg/scheduler/framework/plugins/volumebinding/BUILD index 7119da3810a..09593e452a7 100644 --- a/pkg/scheduler/framework/plugins/volumebinding/BUILD +++ b/pkg/scheduler/framework/plugins/volumebinding/BUILD @@ -39,6 +39,7 @@ go_test( "//pkg/controller/volume/persistentvolume/util:go_default_library", "//pkg/controller/volume/scheduling:go_default_library", "//pkg/scheduler/apis/config:go_default_library", + "//pkg/scheduler/framework/runtime: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/storage/v1:go_default_library", diff --git a/pkg/scheduler/framework/plugins/volumebinding/volume_binding_test.go b/pkg/scheduler/framework/plugins/volumebinding/volume_binding_test.go index f2df794c023..0708332de07 100644 --- a/pkg/scheduler/framework/plugins/volumebinding/volume_binding_test.go +++ b/pkg/scheduler/framework/plugins/volumebinding/volume_binding_test.go @@ -29,6 +29,7 @@ import ( pvutil "k8s.io/kubernetes/pkg/controller/volume/persistentvolume/util" "k8s.io/kubernetes/pkg/controller/volume/scheduling" "k8s.io/kubernetes/pkg/scheduler/apis/config" + "k8s.io/kubernetes/pkg/scheduler/framework/runtime" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" "k8s.io/utils/pointer" ) @@ -231,11 +232,11 @@ func TestVolumeBinding(t *testing.T) { ctx := context.Background() client := fake.NewSimpleClientset() informerFactory := informers.NewSharedInformerFactory(client, 0) - opts := []framework.Option{ - framework.WithClientSet(client), - framework.WithInformerFactory(informerFactory), + opts := []runtime.Option{ + runtime.WithClientSet(client), + runtime.WithInformerFactory(informerFactory), } - fh, err := framework.NewFramework(nil, nil, nil, opts...) + fh, err := runtime.NewFramework(nil, nil, nil, opts...) if err != nil { t.Fatal(err) } diff --git a/pkg/scheduler/framework/runtime/BUILD b/pkg/scheduler/framework/runtime/BUILD new file mode 100644 index 00000000000..78d1912d59f --- /dev/null +++ b/pkg/scheduler/framework/runtime/BUILD @@ -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"], +) diff --git a/pkg/scheduler/framework/v1alpha1/framework.go b/pkg/scheduler/framework/runtime/framework.go similarity index 74% rename from pkg/scheduler/framework/v1alpha1/framework.go rename to pkg/scheduler/framework/runtime/framework.go index 3857e3a5c4e..480168d3011 100644 --- a/pkg/scheduler/framework/v1alpha1/framework.go +++ b/pkg/scheduler/framework/runtime/framework.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v1alpha1 +package runtime import ( "context" @@ -33,6 +33,7 @@ import ( "k8s.io/kube-scheduler/config/v1beta1" "k8s.io/kubernetes/pkg/scheduler/apis/config" "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/metrics" ) @@ -59,25 +60,25 @@ const ( 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. -type framework struct { +type frameworkImpl struct { registry Registry - snapshotSharedLister SharedLister + snapshotSharedLister framework.SharedLister waitingPods *waitingPodsMap pluginNameToWeightMap map[string]int - queueSortPlugins []QueueSortPlugin - preFilterPlugins []PreFilterPlugin - filterPlugins []FilterPlugin - postFilterPlugins []PostFilterPlugin - preScorePlugins []PreScorePlugin - scorePlugins []ScorePlugin - reservePlugins []ReservePlugin - preBindPlugins []PreBindPlugin - bindPlugins []BindPlugin - postBindPlugins []PostBindPlugin - unreservePlugins []UnreservePlugin - permitPlugins []PermitPlugin + queueSortPlugins []framework.QueueSortPlugin + preFilterPlugins []framework.PreFilterPlugin + filterPlugins []framework.FilterPlugin + postFilterPlugins []framework.PostFilterPlugin + preScorePlugins []framework.PreScorePlugin + scorePlugins []framework.ScorePlugin + reservePlugins []framework.ReservePlugin + preBindPlugins []framework.PreBindPlugin + bindPlugins []framework.BindPlugin + postBindPlugins []framework.PostBindPlugin + unreservePlugins []framework.UnreservePlugin + permitPlugins []framework.PermitPlugin clientSet clientset.Interface eventRecorder events.EventRecorder @@ -85,7 +86,7 @@ type framework struct { metricsRecorder *metricsRecorder - preemptHandle PreemptHandle + preemptHandle framework.PreemptHandle // Indicates that RunFilterPlugins should accumulate all failed statuses and not return // after the first failure. @@ -94,7 +95,7 @@ type framework struct { // 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 -// framework. +// frameworkImpl. type extensionPoint struct { // the set of plugins to be configured at this extension point. plugins *config.PluginSet @@ -103,7 +104,7 @@ type extensionPoint struct { slicePtr interface{} } -func (f *framework) getExtensionPoints(plugins *config.Plugins) []extensionPoint { +func (f *frameworkImpl) getExtensionPoints(plugins *config.Plugins) []extensionPoint { return []extensionPoint{ {plugins.PreFilter, &f.preFilterPlugins}, {plugins.Filter, &f.filterPlugins}, @@ -124,31 +125,31 @@ type frameworkOptions struct { clientSet clientset.Interface eventRecorder events.EventRecorder informerFactory informers.SharedInformerFactory - snapshotSharedLister SharedLister + snapshotSharedLister framework.SharedLister metricsRecorder *metricsRecorder - podNominator PodNominator - extenders []Extender + podNominator framework.PodNominator + extenders []framework.Extender runAllFilters bool } -// Option for the framework. +// Option for the frameworkImpl. type Option func(*frameworkOptions) -// WithClientSet sets clientSet for the scheduling framework. +// WithClientSet sets clientSet for the scheduling frameworkImpl. func WithClientSet(clientSet clientset.Interface) Option { return func(o *frameworkOptions) { o.clientSet = clientSet } } -// WithEventRecorder sets clientSet for the scheduling framework. +// WithEventRecorder sets clientSet for the scheduling frameworkImpl. func WithEventRecorder(recorder events.EventRecorder) Option { return func(o *frameworkOptions) { 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 { return func(o *frameworkOptions) { o.informerFactory = informerFactory @@ -156,7 +157,7 @@ func WithInformerFactory(informerFactory informers.SharedInformerFactory) Option } // WithSnapshotSharedLister sets the SharedLister of the snapshot. -func WithSnapshotSharedLister(snapshotSharedLister SharedLister) Option { +func WithSnapshotSharedLister(snapshotSharedLister framework.SharedLister) Option { return func(o *frameworkOptions) { o.snapshotSharedLister = snapshotSharedLister } @@ -177,15 +178,15 @@ func withMetricsRecorder(recorder *metricsRecorder) Option { } } -// WithPodNominator sets podNominator for the scheduling framework. -func WithPodNominator(nominator PodNominator) Option { +// WithPodNominator sets podNominator for the scheduling frameworkImpl. +func WithPodNominator(nominator framework.PodNominator) Option { return func(o *frameworkOptions) { o.podNominator = nominator } } -// WithExtenders sets extenders for the scheduling framework. -func WithExtenders(extenders []Extender) Option { +// WithExtenders sets extenders for the scheduling frameworkImpl. +func WithExtenders(extenders []framework.Extender) Option { return func(o *frameworkOptions) { o.extenders = extenders } @@ -195,30 +196,30 @@ var defaultFrameworkOptions = frameworkOptions{ metricsRecorder: newMetricsRecorder(1000, time.Second), } -// TODO(#91029): move this to framework runtime package. -var _ PreemptHandle = &preemptHandle{} +// TODO(#91029): move this to frameworkImpl runtime package. +var _ framework.PreemptHandle = &preemptHandle{} type preemptHandle struct { - extenders []Extender - PodNominator - PluginsRunner + extenders []framework.Extender + framework.PodNominator + framework.PluginsRunner } // Extenders returns the registered extenders. -func (ph *preemptHandle) Extenders() []Extender { +func (ph *preemptHandle) Extenders() []framework.Extender { return ph.extenders } -var _ Framework = &framework{} +var _ framework.Framework = &frameworkImpl{} // NewFramework initializes plugins given the configuration and the registry. -func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfig, opts ...Option) (Framework, error) { +func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfig, opts ...Option) (framework.Framework, error) { options := defaultFrameworkOptions for _, opt := range opts { opt(&options) } - f := &framework{ + f := &frameworkImpl{ registry: r, snapshotSharedLister: options.snapshotSharedLister, pluginNameToWeightMap: make(map[string]int), @@ -250,7 +251,7 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi pluginConfig[name] = args[i].Args } - pluginsMap := make(map[string]Plugin) + pluginsMap := make(map[string]framework.Plugin) var totalPriority int64 for name, factory := range r { // initialize only needed plugins. @@ -275,10 +276,10 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi f.pluginNameToWeightMap[name] = 1 } // 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") } - totalPriority += int64(f.pluginNameToWeightMap[name]) * MaxNodeScore + totalPriority += int64(f.pluginNameToWeightMap[name]) * framework.MaxNodeScore } for _, e := range f.getExtensionPoints(plugins) { @@ -327,7 +328,7 @@ func getPluginArgsOrDefault(pluginConfig map[string]runtime.Object, name string) 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 { return nil } @@ -358,15 +359,15 @@ func updatePluginList(pluginList interface{}, pluginSet *config.PluginSet, plugi } // 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 framework is nil, simply keep their order unchanged. + // If frameworkImpl is nil, simply keep their order unchanged. // NOTE: this is primarily for tests. - return func(_, _ *QueuedPodInfo) bool { return false } + return func(_, _ *framework.QueuedPodInfo) bool { return false } } 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. @@ -377,7 +378,7 @@ func (f *framework) QueueSortFunc() LessFunc { // *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 // 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() defer func() { 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() { msg := fmt.Sprintf("rejected by %q at prefilter: %v", pl.Name(), status.Message()) 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()) klog.Error(msg) - return NewStatus(Error, msg) + return framework.NewStatus(framework.Error, msg) } } 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() { 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 // PreFilter plugins. It returns directly if any of the plugins return any // status other than Success. -func (f *framework) RunPreFilterExtensionAddPod( +func (f *frameworkImpl) RunPreFilterExtensionAddPod( ctx context.Context, - state *CycleState, + state *framework.CycleState, podToSchedule *v1.Pod, podToAdd *v1.Pod, - nodeInfo *NodeInfo, -) (status *Status) { + nodeInfo *framework.NodeInfo, +) (status *framework.Status) { for _, pl := range f.preFilterPlugins { if pl.PreFilterExtensions() == nil { continue @@ -428,14 +429,14 @@ func (f *framework) RunPreFilterExtensionAddPod( msg := fmt.Sprintf("error while running AddPod for plugin %q while scheduling pod %q: %v", pl.Name(), podToSchedule.Name, status.Message()) klog.Error(msg) - return NewStatus(Error, msg) + return framework.NewStatus(framework.Error, msg) } } 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() { 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 // PreFilter plugins. It returns directly if any of the plugins return any // status other than Success. -func (f *framework) RunPreFilterExtensionRemovePod( +func (f *frameworkImpl) RunPreFilterExtensionRemovePod( ctx context.Context, - state *CycleState, + state *framework.CycleState, podToSchedule *v1.Pod, podToRemove *v1.Pod, - nodeInfo *NodeInfo, -) (status *Status) { + nodeInfo *framework.NodeInfo, +) (status *framework.Status) { for _, pl := range f.preFilterPlugins { if pl.PreFilterExtensions() == nil { continue @@ -464,14 +465,14 @@ func (f *framework) RunPreFilterExtensionRemovePod( msg := fmt.Sprintf("error while running RemovePod for plugin %q while scheduling pod %q: %v", pl.Name(), podToSchedule.Name, status.Message()) klog.Error(msg) - return NewStatus(Error, msg) + return framework.NewStatus(framework.Error, msg) } } 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() { 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 // given node is not suitable for running pod. // Meanwhile, the failure message and status are set for the given node. -func (f *framework) RunFilterPlugins( +func (f *frameworkImpl) RunFilterPlugins( ctx context.Context, - state *CycleState, + state *framework.CycleState, pod *v1.Pod, - nodeInfo *NodeInfo, -) PluginToStatus { - statuses := make(PluginToStatus) + nodeInfo *framework.NodeInfo, +) framework.PluginToStatus { + statuses := make(framework.PluginToStatus) for _, pl := range f.filterPlugins { pluginStatus := f.runFilterPlugin(ctx, pl, state, pod, nodeInfo) if !pluginStatus.IsSuccess() { if !pluginStatus.IsUnschedulable() { // Filter plugins are not supposed to return any status other than // Success or Unschedulable. - errStatus := NewStatus(Error, fmt.Sprintf("running %q filter plugin for pod %q: %v", pl.Name(), pod.Name, pluginStatus.Message())) - return map[string]*Status{pl.Name(): errStatus} + errStatus := framework.NewStatus(framework.Error, fmt.Sprintf("running %q filter plugin for pod %q: %v", pl.Name(), pod.Name, pluginStatus.Message())) + return map[string]*framework.Status{pl.Name(): errStatus} } statuses[pl.Name()] = pluginStatus if !f.runAllFilters { @@ -512,7 +513,7 @@ func (f *framework) RunFilterPlugins( 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() { 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 // 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) { - statuses := make(PluginToStatus) +func (f *frameworkImpl) RunPostFilterPlugins(ctx context.Context, state *framework.CycleState, pod *v1.Pod, filteredNodeStatusMap framework.NodeToStatusMap) (*framework.PostFilterResult, *framework.Status) { + statuses := make(framework.PluginToStatus) for _, pl := range f.postFilterPlugins { r, s := f.runPostFilterPlugin(ctx, pl, state, pod, filteredNodeStatusMap) if s.IsSuccess() { return r, s } else if !s.IsUnschedulable() { // 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 } 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() { 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 // 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, - state *CycleState, + state *framework.CycleState, pod *v1.Pod, nodes []*v1.Node, -) (status *Status) { +) (status *framework.Status) { startTime := time.Now() defer func() { metrics.FrameworkExtensionPointDuration.WithLabelValues(preScore, status.Code().String()).Observe(metrics.SinceInSeconds(startTime)) @@ -566,14 +567,14 @@ func (f *framework) RunPreScorePlugins( if !status.IsSuccess() { msg := fmt.Sprintf("error while running %q prescore plugin for pod %q: %v", pl.Name(), pod.Name, status.Message()) klog.Error(msg) - return NewStatus(Error, msg) + return framework.NewStatus(framework.Error, msg) } } 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() { 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). // It also returns *Status, which is set to non-success if any of the plugins returns // 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() defer func() { 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 { - pluginToNodeScores[pl.Name()] = make(NodeScoreList, len(nodes)) + pluginToNodeScores[pl.Name()] = make(framework.NodeScoreList, len(nodes)) } ctx, cancel := context.WithCancel(ctx) errCh := parallelize.NewErrorChannel() @@ -608,7 +609,7 @@ func (f *framework) RunScorePlugins(ctx context.Context, state *CycleState, pod errCh.SendErrorWithCancel(fmt.Errorf(status.Message()), cancel) return } - pluginToNodeScores[pl.Name()][index] = NodeScore{ + pluginToNodeScores[pl.Name()][index] = framework.NodeScore{ Name: nodeName, Score: int64(s), } @@ -617,7 +618,7 @@ func (f *framework) RunScorePlugins(ctx context.Context, state *CycleState, pod if err := errCh.ReceiveError(); err != nil { msg := fmt.Sprintf("error while running score plugin for pod %q: %v", pod.Name, err) klog.Error(msg) - return nil, NewStatus(Error, msg) + return nil, framework.NewStatus(framework.Error, msg) } // 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 { msg := fmt.Sprintf("error while running normalize score plugin for pod %q: %v", pod.Name, err) klog.Error(msg) - return nil, NewStatus(Error, msg) + return nil, framework.NewStatus(framework.Error, msg) } // 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 { // return error if score plugin returns invalid score. - if nodeScore.Score > int64(MaxNodeScore) || nodeScore.Score < int64(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) + 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, framework.MinNodeScore, framework.MaxNodeScore) errCh.SendErrorWithCancel(err, cancel) return } @@ -660,13 +661,13 @@ func (f *framework) RunScorePlugins(ctx context.Context, state *CycleState, pod if err := errCh.ReceiveError(); err != nil { msg := fmt.Sprintf("error while applying score defaultWeights for pod %q: %v", pod.Name, err) klog.Error(msg) - return nil, NewStatus(Error, msg) + return nil, framework.NewStatus(framework.Error, msg) } 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() { 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 } -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() { 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 // 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. -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() defer func() { 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() { msg := fmt.Sprintf("error while running %q prebind plugin for pod %q: %v", pl.Name(), pod.Name, status.Message()) klog.Error(msg) - return NewStatus(Error, msg) + return framework.NewStatus(framework.Error, msg) } } 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() { 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. -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() defer func() { metrics.FrameworkExtensionPointDuration.WithLabelValues(bind, status.Code().String()).Observe(metrics.SinceInSeconds(startTime)) }() if len(f.bindPlugins) == 0 { - return NewStatus(Skip, "") + return framework.NewStatus(framework.Skip, "") } for _, bp := range f.bindPlugins { status = f.runBindPlugin(ctx, bp, state, pod, nodeName) - if status != nil && status.Code() == Skip { + if status != nil && status.Code() == framework.Skip { continue } if !status.IsSuccess() { msg := fmt.Sprintf("plugin %q failed to bind pod \"%v/%v\": %v", bp.Name(), pod.Namespace, pod.Name, status.Message()) klog.Error(msg) - return NewStatus(Error, msg) + return framework.NewStatus(framework.Error, msg) } 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() { 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. -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() 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 { 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() { pl.PostBind(ctx, state, pod, nodeName) 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 // plugins returns an error, it does not continue running the remaining ones and // 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() defer func() { 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() { msg := fmt.Sprintf("error while running %q reserve plugin for pod %q: %v", pl.Name(), pod.Name, status.Message()) klog.Error(msg) - return NewStatus(Error, msg) + return framework.NewStatus(framework.Error, msg) } } 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() { 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. -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() 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 { 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() { pl.Unreserve(ctx, state, pod, nodeName) 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 // 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. -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() defer func() { metrics.FrameworkExtensionPointDuration.WithLabelValues(permit, status.Code().String()).Observe(metrics.SinceInSeconds(startTime)) }() pluginsWaitTime := make(map[string]time.Duration) - statusCode := Success + statusCode := framework.Success for _, pl := range f.permitPlugins { status, timeout := f.runPermitPlugin(ctx, pl, state, pod, nodeName) if !status.IsSuccess() { if status.IsUnschedulable() { msg := fmt.Sprintf("rejected pod %q by permit plugin %q: %v", pod.Name, pl.Name(), status.Message()) 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. if timeout > maxTimeout { timeout = maxTimeout } pluginsWaitTime[pl.Name()] = timeout - statusCode = Wait + statusCode = framework.Wait } else { msg := fmt.Sprintf("error while running %q permit plugin for pod %q: %v", pl.Name(), pod.Name, status.Message()) klog.Error(msg) - return NewStatus(Error, msg) + return framework.NewStatus(framework.Error, msg) } } } - if statusCode == Wait { + if statusCode == framework.Wait { waitingPod := newWaitingPod(pod, pluginsWaitTime) f.waitingPods.add(waitingPod) msg := fmt.Sprintf("one or more plugins asked to wait and no plugin rejected pod %q", pod.Name) klog.V(4).Infof(msg) - return NewStatus(Wait, msg) + return framework.NewStatus(framework.Wait, msg) } 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() { 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. -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) if waitingPod == nil { return nil @@ -892,11 +893,11 @@ func (f *framework) WaitOnPermit(ctx context.Context, pod *v1.Pod) (status *Stat if s.IsUnschedulable() { msg := fmt.Sprintf("pod %q rejected while waiting on permit: %v", pod.Name, s.Message()) 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()) klog.Error(msg) - return NewStatus(Error, msg) + return framework.NewStatus(framework.Error, msg) } 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 // unchanged until a pod finishes "Reserve". There is no guarantee that the information // remains unchanged after "Reserve". -func (f *framework) SnapshotSharedLister() SharedLister { +func (f *frameworkImpl) SnapshotSharedLister() framework.SharedLister { return f.snapshotSharedLister } // 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) } // 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 { return wp } @@ -923,7 +924,7 @@ func (f *framework) GetWaitingPod(uid types.UID) WaitingPod { } // 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) if waitingPod != nil { 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. -func (f *framework) HasFilterPlugins() bool { +func (f *frameworkImpl) HasFilterPlugins() bool { return len(f.filterPlugins) > 0 } // 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 } // ListPlugins returns a map of extension point name to plugin names configured at each extension // 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) for _, e := range f.getExtensionPoints(&config.Plugins{}) { @@ -950,7 +951,7 @@ func (f *framework) ListPlugins() map[string][]config.Plugin { extName := plugins.Type().Elem().Name() var cfgs []config.Plugin 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} if extName == "ScorePlugin" { // Weights apply only to score plugins. @@ -969,21 +970,21 @@ func (f *framework) ListPlugins() map[string][]config.Plugin { } // ClientSet returns a kubernetes clientset. -func (f *framework) ClientSet() clientset.Interface { +func (f *frameworkImpl) ClientSet() clientset.Interface { return f.clientSet } // EventRecorder returns an event recorder. -func (f *framework) EventRecorder() events.EventRecorder { +func (f *frameworkImpl) EventRecorder() events.EventRecorder { return f.eventRecorder } // SharedInformerFactory returns a shared informer factory. -func (f *framework) SharedInformerFactory() informers.SharedInformerFactory { +func (f *frameworkImpl) SharedInformerFactory() informers.SharedInformerFactory { 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) if plugins == nil { @@ -1005,6 +1006,6 @@ func (f *framework) pluginsNeeded(plugins *config.Plugins) map[string]config.Plu } // PreemptHandle returns the internal preemptHandle object. -func (f *framework) PreemptHandle() PreemptHandle { +func (f *frameworkImpl) PreemptHandle() framework.PreemptHandle { return f.preemptHandle } diff --git a/pkg/scheduler/framework/v1alpha1/framework_test.go b/pkg/scheduler/framework/runtime/framework_test.go similarity index 66% rename from pkg/scheduler/framework/v1alpha1/framework_test.go rename to pkg/scheduler/framework/runtime/framework_test.go index 120b419ae18..91fe8decceb 100644 --- a/pkg/scheduler/framework/v1alpha1/framework_test.go +++ b/pkg/scheduler/framework/runtime/framework_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v1alpha1 +package runtime import ( "context" @@ -32,6 +32,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" "k8s.io/kubernetes/pkg/scheduler/apis/config" + "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" "k8s.io/kubernetes/pkg/scheduler/metrics" ) @@ -51,10 +52,10 @@ const ( // TestScoreWithNormalizePlugin implements ScoreWithNormalizePlugin interface. // TestScorePlugin only implements ScorePlugin interface. -var _ ScorePlugin = &TestScoreWithNormalizePlugin{} -var _ ScorePlugin = &TestScorePlugin{} +var _ v1alpha1.ScorePlugin = &TestScoreWithNormalizePlugin{} +var _ v1alpha1.ScorePlugin = &TestScorePlugin{} -func newScoreWithNormalizePlugin1(injArgs runtime.Object, f FrameworkHandle) (Plugin, error) { +func newScoreWithNormalizePlugin1(injArgs runtime.Object, f v1alpha1.FrameworkHandle) (v1alpha1.Plugin, error) { var inj injectedResult if err := DecodeInto(injArgs, &inj); err != nil { return nil, err @@ -62,7 +63,7 @@ func newScoreWithNormalizePlugin1(injArgs runtime.Object, f FrameworkHandle) (Pl return &TestScoreWithNormalizePlugin{scoreWithNormalizePlugin1, inj}, nil } -func newScoreWithNormalizePlugin2(injArgs runtime.Object, f FrameworkHandle) (Plugin, error) { +func newScoreWithNormalizePlugin2(injArgs runtime.Object, f v1alpha1.FrameworkHandle) (v1alpha1.Plugin, error) { var inj injectedResult if err := DecodeInto(injArgs, &inj); err != nil { return nil, err @@ -70,7 +71,7 @@ func newScoreWithNormalizePlugin2(injArgs runtime.Object, f FrameworkHandle) (Pl return &TestScoreWithNormalizePlugin{scoreWithNormalizePlugin2, inj}, nil } -func newScorePlugin1(injArgs runtime.Object, f FrameworkHandle) (Plugin, error) { +func newScorePlugin1(injArgs runtime.Object, f v1alpha1.FrameworkHandle) (v1alpha1.Plugin, error) { var inj injectedResult if err := DecodeInto(injArgs, &inj); err != nil { return nil, err @@ -78,7 +79,7 @@ func newScorePlugin1(injArgs runtime.Object, f FrameworkHandle) (Plugin, error) return &TestScorePlugin{scorePlugin1, inj}, nil } -func newPluginNotImplementingScore(_ runtime.Object, _ FrameworkHandle) (Plugin, error) { +func newPluginNotImplementingScore(_ runtime.Object, _ v1alpha1.FrameworkHandle) (v1alpha1.Plugin, error) { return &PluginNotImplementingScore{}, nil } @@ -91,15 +92,15 @@ func (pl *TestScoreWithNormalizePlugin) Name() string { return pl.name } -func (pl *TestScoreWithNormalizePlugin) NormalizeScore(ctx context.Context, state *CycleState, pod *v1.Pod, scores NodeScoreList) *Status { +func (pl *TestScoreWithNormalizePlugin) NormalizeScore(ctx context.Context, state *v1alpha1.CycleState, pod *v1.Pod, scores v1alpha1.NodeScoreList) *v1alpha1.Status { return injectNormalizeRes(pl.inj, scores) } -func (pl *TestScoreWithNormalizePlugin) Score(ctx context.Context, state *CycleState, p *v1.Pod, nodeName string) (int64, *Status) { +func (pl *TestScoreWithNormalizePlugin) Score(ctx context.Context, state *v1alpha1.CycleState, p *v1.Pod, nodeName string) (int64, *v1alpha1.Status) { return setScoreRes(pl.inj) } -func (pl *TestScoreWithNormalizePlugin) ScoreExtensions() ScoreExtensions { +func (pl *TestScoreWithNormalizePlugin) ScoreExtensions() v1alpha1.ScoreExtensions { return pl } @@ -113,11 +114,11 @@ func (pl *TestScorePlugin) Name() string { return pl.name } -func (pl *TestScorePlugin) Score(ctx context.Context, state *CycleState, p *v1.Pod, nodeName string) (int64, *Status) { +func (pl *TestScorePlugin) Score(ctx context.Context, state *v1alpha1.CycleState, p *v1.Pod, nodeName string) (int64, *v1alpha1.Status) { return setScoreRes(pl.inj) } -func (pl *TestScorePlugin) ScoreExtensions() ScoreExtensions { +func (pl *TestScorePlugin) ScoreExtensions() v1alpha1.ScoreExtensions { return nil } @@ -134,67 +135,69 @@ type TestPlugin struct { inj injectedResult } -func (pl *TestPlugin) AddPod(ctx context.Context, state *CycleState, podToSchedule *v1.Pod, podToAdd *v1.Pod, nodeInfo *NodeInfo) *Status { - return NewStatus(Code(pl.inj.PreFilterAddPodStatus), "injected status") +func (pl *TestPlugin) AddPod(ctx context.Context, state *v1alpha1.CycleState, podToSchedule *v1.Pod, podToAdd *v1.Pod, nodeInfo *v1alpha1.NodeInfo) *v1alpha1.Status { + return v1alpha1.NewStatus(v1alpha1.Code(pl.inj.PreFilterAddPodStatus), "injected status") } -func (pl *TestPlugin) RemovePod(ctx context.Context, state *CycleState, podToSchedule *v1.Pod, podToRemove *v1.Pod, nodeInfo *NodeInfo) *Status { - return NewStatus(Code(pl.inj.PreFilterRemovePodStatus), "injected status") +func (pl *TestPlugin) RemovePod(ctx context.Context, state *v1alpha1.CycleState, podToSchedule *v1.Pod, podToRemove *v1.Pod, nodeInfo *v1alpha1.NodeInfo) *v1alpha1.Status { + return v1alpha1.NewStatus(v1alpha1.Code(pl.inj.PreFilterRemovePodStatus), "injected status") } func (pl *TestPlugin) Name() string { return pl.name } -func (pl *TestPlugin) Less(*QueuedPodInfo, *QueuedPodInfo) bool { +func (pl *TestPlugin) Less(*v1alpha1.QueuedPodInfo, *v1alpha1.QueuedPodInfo) bool { return false } -func (pl *TestPlugin) Score(ctx context.Context, state *CycleState, p *v1.Pod, nodeName string) (int64, *Status) { - return 0, NewStatus(Code(pl.inj.ScoreStatus), "injected status") +func (pl *TestPlugin) Score(ctx context.Context, state *v1alpha1.CycleState, p *v1.Pod, nodeName string) (int64, *v1alpha1.Status) { + return 0, v1alpha1.NewStatus(v1alpha1.Code(pl.inj.ScoreStatus), "injected status") } -func (pl *TestPlugin) ScoreExtensions() ScoreExtensions { +func (pl *TestPlugin) ScoreExtensions() v1alpha1.ScoreExtensions { return nil } -func (pl *TestPlugin) PreFilter(ctx context.Context, state *CycleState, p *v1.Pod) *Status { - return NewStatus(Code(pl.inj.PreFilterStatus), "injected status") +func (pl *TestPlugin) PreFilter(ctx context.Context, state *v1alpha1.CycleState, p *v1.Pod) *v1alpha1.Status { + return v1alpha1.NewStatus(v1alpha1.Code(pl.inj.PreFilterStatus), "injected status") } -func (pl *TestPlugin) PreFilterExtensions() PreFilterExtensions { +func (pl *TestPlugin) PreFilterExtensions() v1alpha1.PreFilterExtensions { return pl } -func (pl *TestPlugin) Filter(ctx context.Context, state *CycleState, pod *v1.Pod, nodeInfo *NodeInfo) *Status { - return NewStatus(Code(pl.inj.FilterStatus), "injected filter status") +func (pl *TestPlugin) Filter(ctx context.Context, state *v1alpha1.CycleState, pod *v1.Pod, nodeInfo *v1alpha1.NodeInfo) *v1alpha1.Status { + return v1alpha1.NewStatus(v1alpha1.Code(pl.inj.FilterStatus), "injected filter status") } -func (pl *TestPlugin) PostFilter(_ context.Context, _ *CycleState, _ *v1.Pod, _ NodeToStatusMap) (*PostFilterResult, *Status) { - return nil, NewStatus(Code(pl.inj.PostFilterStatus), "injected status") +func (pl *TestPlugin) PostFilter(_ context.Context, _ *v1alpha1.CycleState, _ *v1.Pod, _ v1alpha1.NodeToStatusMap) (*v1alpha1.PostFilterResult, *v1alpha1.Status) { + return nil, v1alpha1.NewStatus(v1alpha1.Code(pl.inj.PostFilterStatus), "injected status") } -func (pl *TestPlugin) PreScore(ctx context.Context, state *CycleState, pod *v1.Pod, nodes []*v1.Node) *Status { - return NewStatus(Code(pl.inj.PreScoreStatus), "injected status") +func (pl *TestPlugin) PreScore(ctx context.Context, state *v1alpha1.CycleState, pod *v1.Pod, nodes []*v1.Node) *v1alpha1.Status { + return v1alpha1.NewStatus(v1alpha1.Code(pl.inj.PreScoreStatus), "injected status") } -func (pl *TestPlugin) Reserve(ctx context.Context, state *CycleState, p *v1.Pod, nodeName string) *Status { - return NewStatus(Code(pl.inj.ReserveStatus), "injected status") +func (pl *TestPlugin) Reserve(ctx context.Context, state *v1alpha1.CycleState, p *v1.Pod, nodeName string) *v1alpha1.Status { + return v1alpha1.NewStatus(v1alpha1.Code(pl.inj.ReserveStatus), "injected status") } -func (pl *TestPlugin) PreBind(ctx context.Context, state *CycleState, p *v1.Pod, nodeName string) *Status { - return NewStatus(Code(pl.inj.PreBindStatus), "injected status") +func (pl *TestPlugin) PreBind(ctx context.Context, state *v1alpha1.CycleState, p *v1.Pod, nodeName string) *v1alpha1.Status { + return v1alpha1.NewStatus(v1alpha1.Code(pl.inj.PreBindStatus), "injected status") } -func (pl *TestPlugin) PostBind(ctx context.Context, state *CycleState, p *v1.Pod, nodeName string) {} - -func (pl *TestPlugin) Unreserve(ctx context.Context, state *CycleState, p *v1.Pod, nodeName string) {} - -func (pl *TestPlugin) Permit(ctx context.Context, state *CycleState, p *v1.Pod, nodeName string) (*Status, time.Duration) { - return NewStatus(Code(pl.inj.PermitStatus), "injected status"), time.Duration(0) +func (pl *TestPlugin) PostBind(ctx context.Context, state *v1alpha1.CycleState, p *v1.Pod, nodeName string) { } -func (pl *TestPlugin) Bind(ctx context.Context, state *CycleState, p *v1.Pod, nodeName string) *Status { - return NewStatus(Code(pl.inj.BindStatus), "injected status") +func (pl *TestPlugin) Unreserve(ctx context.Context, state *v1alpha1.CycleState, p *v1.Pod, nodeName string) { +} + +func (pl *TestPlugin) Permit(ctx context.Context, state *v1alpha1.CycleState, p *v1.Pod, nodeName string) (*v1alpha1.Status, time.Duration) { + return v1alpha1.NewStatus(v1alpha1.Code(pl.inj.PermitStatus), "injected status"), time.Duration(0) +} + +func (pl *TestPlugin) Bind(ctx context.Context, state *v1alpha1.CycleState, p *v1.Pod, nodeName string) *v1alpha1.Status { + return v1alpha1.NewStatus(v1alpha1.Code(pl.inj.BindStatus), "injected status") } // TestPreFilterPlugin only implements PreFilterPlugin interface. @@ -206,12 +209,12 @@ func (pl *TestPreFilterPlugin) Name() string { return preFilterPluginName } -func (pl *TestPreFilterPlugin) PreFilter(ctx context.Context, state *CycleState, p *v1.Pod) *Status { +func (pl *TestPreFilterPlugin) PreFilter(ctx context.Context, state *v1alpha1.CycleState, p *v1.Pod) *v1alpha1.Status { pl.PreFilterCalled++ return nil } -func (pl *TestPreFilterPlugin) PreFilterExtensions() PreFilterExtensions { +func (pl *TestPreFilterPlugin) PreFilterExtensions() v1alpha1.PreFilterExtensions { return nil } @@ -226,24 +229,24 @@ func (pl *TestPreFilterWithExtensionsPlugin) Name() string { return preFilterWithExtensionsPluginName } -func (pl *TestPreFilterWithExtensionsPlugin) PreFilter(ctx context.Context, state *CycleState, p *v1.Pod) *Status { +func (pl *TestPreFilterWithExtensionsPlugin) PreFilter(ctx context.Context, state *v1alpha1.CycleState, p *v1.Pod) *v1alpha1.Status { pl.PreFilterCalled++ return nil } -func (pl *TestPreFilterWithExtensionsPlugin) AddPod(ctx context.Context, state *CycleState, podToSchedule *v1.Pod, - podToAdd *v1.Pod, nodeInfo *NodeInfo) *Status { +func (pl *TestPreFilterWithExtensionsPlugin) AddPod(ctx context.Context, state *v1alpha1.CycleState, podToSchedule *v1.Pod, + podToAdd *v1.Pod, nodeInfo *v1alpha1.NodeInfo) *v1alpha1.Status { pl.AddCalled++ return nil } -func (pl *TestPreFilterWithExtensionsPlugin) RemovePod(ctx context.Context, state *CycleState, podToSchedule *v1.Pod, - podToRemove *v1.Pod, nodeInfo *NodeInfo) *Status { +func (pl *TestPreFilterWithExtensionsPlugin) RemovePod(ctx context.Context, state *v1alpha1.CycleState, podToSchedule *v1.Pod, + podToRemove *v1.Pod, nodeInfo *v1alpha1.NodeInfo) *v1alpha1.Status { pl.RemoveCalled++ return nil } -func (pl *TestPreFilterWithExtensionsPlugin) PreFilterExtensions() PreFilterExtensions { +func (pl *TestPreFilterWithExtensionsPlugin) PreFilterExtensions() v1alpha1.PreFilterExtensions { return pl } @@ -254,17 +257,17 @@ func (dp *TestDuplicatePlugin) Name() string { return duplicatePluginName } -func (dp *TestDuplicatePlugin) PreFilter(ctx context.Context, state *CycleState, p *v1.Pod) *Status { +func (dp *TestDuplicatePlugin) PreFilter(ctx context.Context, state *v1alpha1.CycleState, p *v1.Pod) *v1alpha1.Status { return nil } -func (dp *TestDuplicatePlugin) PreFilterExtensions() PreFilterExtensions { +func (dp *TestDuplicatePlugin) PreFilterExtensions() v1alpha1.PreFilterExtensions { return nil } -var _ PreFilterPlugin = &TestDuplicatePlugin{} +var _ v1alpha1.PreFilterPlugin = &TestDuplicatePlugin{} -func newDuplicatePlugin(_ runtime.Object, _ FrameworkHandle) (Plugin, error) { +func newDuplicatePlugin(_ runtime.Object, _ v1alpha1.FrameworkHandle) (v1alpha1.Plugin, error) { return &TestDuplicatePlugin{}, nil } @@ -276,13 +279,13 @@ type TestPermitPlugin struct { func (pp *TestPermitPlugin) Name() string { return permitPlugin } -func (pp *TestPermitPlugin) Permit(ctx context.Context, state *CycleState, p *v1.Pod, nodeName string) (*Status, time.Duration) { - return NewStatus(Wait, ""), time.Duration(10 * time.Second) +func (pp *TestPermitPlugin) Permit(ctx context.Context, state *v1alpha1.CycleState, p *v1.Pod, nodeName string) (*v1alpha1.Status, time.Duration) { + return v1alpha1.NewStatus(v1alpha1.Wait, ""), time.Duration(10 * time.Second) } -var _ QueueSortPlugin = &TestQueueSortPlugin{} +var _ v1alpha1.QueueSortPlugin = &TestQueueSortPlugin{} -func newQueueSortPlugin(_ runtime.Object, _ FrameworkHandle) (Plugin, error) { +func newQueueSortPlugin(_ runtime.Object, _ v1alpha1.FrameworkHandle) (v1alpha1.Plugin, error) { return &TestQueueSortPlugin{}, nil } @@ -293,13 +296,13 @@ func (pl *TestQueueSortPlugin) Name() string { return queueSortPlugin } -func (pl *TestQueueSortPlugin) Less(_, _ *QueuedPodInfo) bool { +func (pl *TestQueueSortPlugin) Less(_, _ *v1alpha1.QueuedPodInfo) bool { return false } -var _ BindPlugin = &TestBindPlugin{} +var _ v1alpha1.BindPlugin = &TestBindPlugin{} -func newBindPlugin(_ runtime.Object, _ FrameworkHandle) (Plugin, error) { +func newBindPlugin(_ runtime.Object, _ v1alpha1.FrameworkHandle) (v1alpha1.Plugin, error) { return &TestBindPlugin{}, nil } @@ -310,7 +313,7 @@ func (t TestBindPlugin) Name() string { return bindPlugin } -func (t TestBindPlugin) Bind(ctx context.Context, state *CycleState, p *v1.Pod, nodeName string) *Status { +func (t TestBindPlugin) Bind(ctx context.Context, state *v1alpha1.CycleState, p *v1.Pod, nodeName string) *v1alpha1.Status { return nil } @@ -331,7 +334,7 @@ var defaultWeights = map[string]int32{ } var emptyArgs = make([]config.PluginConfig, 0) -var state = &CycleState{} +var state = &v1alpha1.CycleState{} // Pod is only used for logging errors. var pod = &v1.Pod{} @@ -340,7 +343,7 @@ var nodes = []*v1.Node{ {ObjectMeta: metav1.ObjectMeta{Name: "node2"}}, } -func newFrameworkWithQueueSortAndBind(r Registry, pl *config.Plugins, plc []config.PluginConfig, opts ...Option) (Framework, error) { +func newFrameworkWithQueueSortAndBind(r Registry, pl *config.Plugins, plc []config.PluginConfig, opts ...Option) (v1alpha1.Framework, error) { if _, ok := r[queueSortPlugin]; !ok { r[queueSortPlugin] = newQueueSortPlugin } @@ -464,7 +467,7 @@ func TestNewFrameworkErrors(t *testing.T) { } func recordingPluginFactory(name string, result map[string]runtime.Object) PluginFactory { - return func(args runtime.Object, f FrameworkHandle) (Plugin, error) { + return func(args runtime.Object, f v1alpha1.FrameworkHandle) (v1alpha1.Plugin, error) { result[name] = args return &TestPlugin{ name: name, @@ -617,14 +620,14 @@ func TestRunScorePlugins(t *testing.T) { registry Registry plugins *config.Plugins pluginConfigs []config.PluginConfig - want PluginToNodeScores + want v1alpha1.PluginToNodeScores // If err is true, we expect RunScorePlugin to fail. err bool }{ { name: "no Score plugins", plugins: buildScoreConfigDefaultWeights(), - want: PluginToNodeScores{}, + want: v1alpha1.PluginToNodeScores{}, }, { name: "single Score plugin", @@ -638,7 +641,7 @@ func TestRunScorePlugins(t *testing.T) { }, }, // scorePlugin1 Score returns 1, weight=1, so want=1. - want: PluginToNodeScores{ + want: v1alpha1.PluginToNodeScores{ scorePlugin1: {{Name: "node1", Score: 1}, {Name: "node2", Score: 1}}, }, }, @@ -655,7 +658,7 @@ func TestRunScorePlugins(t *testing.T) { }, }, // scoreWithNormalizePlugin1 Score returns 10, but NormalizeScore overrides to 5, weight=1, so want=5 - want: PluginToNodeScores{ + want: v1alpha1.PluginToNodeScores{ scoreWithNormalizePlugin1: {{Name: "node1", Score: 5}, {Name: "node2", Score: 5}}, }, }, @@ -685,7 +688,7 @@ func TestRunScorePlugins(t *testing.T) { // scorePlugin1 Score returns 1, weight =1, so want=1. // scoreWithNormalizePlugin1 Score returns 3, but NormalizeScore overrides to 4, weight=1, so want=4. // scoreWithNormalizePlugin2 Score returns 4, but NormalizeScore overrides to 5, weight=2, so want=10. - want: PluginToNodeScores{ + want: v1alpha1.PluginToNodeScores{ scorePlugin1: {{Name: "node1", Score: 1}, {Name: "node2", Score: 1}}, scoreWithNormalizePlugin1: {{Name: "node1", Score: 4}, {Name: "node2", Score: 4}}, scoreWithNormalizePlugin2: {{Name: "node1", Score: 10}, {Name: "node2", Score: 10}}, @@ -724,7 +727,7 @@ func TestRunScorePlugins(t *testing.T) { { Name: scorePlugin1, Args: &runtime.Unknown{ - Raw: []byte(fmt.Sprintf(`{ "scoreRes": %d }`, MaxNodeScore+1)), + Raw: []byte(fmt.Sprintf(`{ "scoreRes": %d }`, v1alpha1.MaxNodeScore+1)), }, }, }, @@ -737,7 +740,7 @@ func TestRunScorePlugins(t *testing.T) { { Name: scorePlugin1, Args: &runtime.Unknown{ - Raw: []byte(fmt.Sprintf(`{ "scoreRes": %d }`, MinNodeScore-1)), + Raw: []byte(fmt.Sprintf(`{ "scoreRes": %d }`, v1alpha1.MinNodeScore-1)), }, }, }, @@ -750,7 +753,7 @@ func TestRunScorePlugins(t *testing.T) { { Name: scoreWithNormalizePlugin1, Args: &runtime.Unknown{ - Raw: []byte(fmt.Sprintf(`{ "normalizeRes": %d }`, MaxNodeScore+1)), + Raw: []byte(fmt.Sprintf(`{ "normalizeRes": %d }`, v1alpha1.MaxNodeScore+1)), }, }, }, @@ -763,7 +766,7 @@ func TestRunScorePlugins(t *testing.T) { { Name: scoreWithNormalizePlugin1, Args: &runtime.Unknown{ - Raw: []byte(fmt.Sprintf(`{ "normalizeRes": %d }`, MinNodeScore-1)), + Raw: []byte(fmt.Sprintf(`{ "normalizeRes": %d }`, v1alpha1.MinNodeScore-1)), }, }, }, @@ -803,11 +806,11 @@ func TestPreFilterPlugins(t *testing.T) { preFilter2 := &TestPreFilterWithExtensionsPlugin{} r := make(Registry) r.Register(preFilterPluginName, - func(_ runtime.Object, fh FrameworkHandle) (Plugin, error) { + func(_ runtime.Object, fh v1alpha1.FrameworkHandle) (v1alpha1.Plugin, error) { return preFilter1, nil }) r.Register(preFilterWithExtensionsPluginName, - func(_ runtime.Object, fh FrameworkHandle) (Plugin, error) { + func(_ runtime.Object, fh v1alpha1.FrameworkHandle) (v1alpha1.Plugin, error) { return preFilter2, nil }) plugins := &config.Plugins{PreFilter: &config.PluginSet{Enabled: []config.Plugin{{Name: preFilterWithExtensionsPluginName}, {Name: preFilterPluginName}}}} @@ -839,8 +842,8 @@ func TestFilterPlugins(t *testing.T) { tests := []struct { name string plugins []*TestPlugin - wantStatus *Status - wantStatusMap PluginToStatus + wantStatus *v1alpha1.Status + wantStatusMap v1alpha1.PluginToStatus runAllFilters bool }{ { @@ -848,33 +851,33 @@ func TestFilterPlugins(t *testing.T) { plugins: []*TestPlugin{ { name: "TestPlugin", - inj: injectedResult{FilterStatus: int(Success)}, + inj: injectedResult{FilterStatus: int(v1alpha1.Success)}, }, }, wantStatus: nil, - wantStatusMap: PluginToStatus{}, + wantStatusMap: v1alpha1.PluginToStatus{}, }, { name: "ErrorFilter", plugins: []*TestPlugin{ { name: "TestPlugin", - inj: injectedResult{FilterStatus: int(Error)}, + inj: injectedResult{FilterStatus: int(v1alpha1.Error)}, }, }, - wantStatus: NewStatus(Error, `running "TestPlugin" filter plugin for pod "": injected filter status`), - wantStatusMap: PluginToStatus{"TestPlugin": NewStatus(Error, `running "TestPlugin" filter plugin for pod "": injected filter status`)}, + wantStatus: v1alpha1.NewStatus(v1alpha1.Error, `running "TestPlugin" filter plugin for pod "": injected filter status`), + wantStatusMap: v1alpha1.PluginToStatus{"TestPlugin": v1alpha1.NewStatus(v1alpha1.Error, `running "TestPlugin" filter plugin for pod "": injected filter status`)}, }, { name: "UnschedulableFilter", plugins: []*TestPlugin{ { name: "TestPlugin", - inj: injectedResult{FilterStatus: int(Unschedulable)}, + inj: injectedResult{FilterStatus: int(v1alpha1.Unschedulable)}, }, }, - wantStatus: NewStatus(Unschedulable, "injected filter status"), - wantStatusMap: PluginToStatus{"TestPlugin": NewStatus(Unschedulable, "injected filter status")}, + wantStatus: v1alpha1.NewStatus(v1alpha1.Unschedulable, "injected filter status"), + wantStatusMap: v1alpha1.PluginToStatus{"TestPlugin": v1alpha1.NewStatus(v1alpha1.Unschedulable, "injected filter status")}, }, { name: "UnschedulableAndUnresolvableFilter", @@ -882,11 +885,11 @@ func TestFilterPlugins(t *testing.T) { { name: "TestPlugin", inj: injectedResult{ - FilterStatus: int(UnschedulableAndUnresolvable)}, + FilterStatus: int(v1alpha1.UnschedulableAndUnresolvable)}, }, }, - wantStatus: NewStatus(UnschedulableAndUnresolvable, "injected filter status"), - wantStatusMap: PluginToStatus{"TestPlugin": NewStatus(UnschedulableAndUnresolvable, "injected filter status")}, + wantStatus: v1alpha1.NewStatus(v1alpha1.UnschedulableAndUnresolvable, "injected filter status"), + wantStatusMap: v1alpha1.PluginToStatus{"TestPlugin": v1alpha1.NewStatus(v1alpha1.UnschedulableAndUnresolvable, "injected filter status")}, }, // followings tests cover multiple-plugins scenarios { @@ -894,47 +897,47 @@ func TestFilterPlugins(t *testing.T) { plugins: []*TestPlugin{ { name: "TestPlugin1", - inj: injectedResult{FilterStatus: int(Error)}, + inj: injectedResult{FilterStatus: int(v1alpha1.Error)}, }, { name: "TestPlugin2", - inj: injectedResult{FilterStatus: int(Error)}, + inj: injectedResult{FilterStatus: int(v1alpha1.Error)}, }, }, - wantStatus: NewStatus(Error, `running "TestPlugin1" filter plugin for pod "": injected filter status`), - wantStatusMap: PluginToStatus{"TestPlugin1": NewStatus(Error, `running "TestPlugin1" filter plugin for pod "": injected filter status`)}, + wantStatus: v1alpha1.NewStatus(v1alpha1.Error, `running "TestPlugin1" filter plugin for pod "": injected filter status`), + wantStatusMap: v1alpha1.PluginToStatus{"TestPlugin1": v1alpha1.NewStatus(v1alpha1.Error, `running "TestPlugin1" filter plugin for pod "": injected filter status`)}, }, { name: "SuccessAndSuccessFilters", plugins: []*TestPlugin{ { name: "TestPlugin1", - inj: injectedResult{FilterStatus: int(Success)}, + inj: injectedResult{FilterStatus: int(v1alpha1.Success)}, }, { name: "TestPlugin2", - inj: injectedResult{FilterStatus: int(Success)}, + inj: injectedResult{FilterStatus: int(v1alpha1.Success)}, }, }, wantStatus: nil, - wantStatusMap: PluginToStatus{}, + wantStatusMap: v1alpha1.PluginToStatus{}, }, { name: "ErrorAndSuccessFilters", plugins: []*TestPlugin{ { name: "TestPlugin1", - inj: injectedResult{FilterStatus: int(Error)}, + inj: injectedResult{FilterStatus: int(v1alpha1.Error)}, }, { name: "TestPlugin2", - inj: injectedResult{FilterStatus: int(Success)}, + inj: injectedResult{FilterStatus: int(v1alpha1.Success)}, }, }, - wantStatus: NewStatus(Error, `running "TestPlugin1" filter plugin for pod "": injected filter status`), - wantStatusMap: PluginToStatus{"TestPlugin1": NewStatus(Error, `running "TestPlugin1" filter plugin for pod "": injected filter status`)}, + wantStatus: v1alpha1.NewStatus(v1alpha1.Error, `running "TestPlugin1" filter plugin for pod "": injected filter status`), + wantStatusMap: v1alpha1.PluginToStatus{"TestPlugin1": v1alpha1.NewStatus(v1alpha1.Error, `running "TestPlugin1" filter plugin for pod "": injected filter status`)}, }, { name: "SuccessAndErrorFilters", @@ -942,78 +945,78 @@ func TestFilterPlugins(t *testing.T) { { name: "TestPlugin1", - inj: injectedResult{FilterStatus: int(Success)}, + inj: injectedResult{FilterStatus: int(v1alpha1.Success)}, }, { name: "TestPlugin2", - inj: injectedResult{FilterStatus: int(Error)}, + inj: injectedResult{FilterStatus: int(v1alpha1.Error)}, }, }, - wantStatus: NewStatus(Error, `running "TestPlugin2" filter plugin for pod "": injected filter status`), - wantStatusMap: PluginToStatus{"TestPlugin2": NewStatus(Error, `running "TestPlugin2" filter plugin for pod "": injected filter status`)}, + wantStatus: v1alpha1.NewStatus(v1alpha1.Error, `running "TestPlugin2" filter plugin for pod "": injected filter status`), + wantStatusMap: v1alpha1.PluginToStatus{"TestPlugin2": v1alpha1.NewStatus(v1alpha1.Error, `running "TestPlugin2" filter plugin for pod "": injected filter status`)}, }, { name: "SuccessAndUnschedulableFilters", plugins: []*TestPlugin{ { name: "TestPlugin1", - inj: injectedResult{FilterStatus: int(Success)}, + inj: injectedResult{FilterStatus: int(v1alpha1.Success)}, }, { name: "TestPlugin2", - inj: injectedResult{FilterStatus: int(Unschedulable)}, + inj: injectedResult{FilterStatus: int(v1alpha1.Unschedulable)}, }, }, - wantStatus: NewStatus(Unschedulable, "injected filter status"), - wantStatusMap: PluginToStatus{"TestPlugin2": NewStatus(Unschedulable, "injected filter status")}, + wantStatus: v1alpha1.NewStatus(v1alpha1.Unschedulable, "injected filter status"), + wantStatusMap: v1alpha1.PluginToStatus{"TestPlugin2": v1alpha1.NewStatus(v1alpha1.Unschedulable, "injected filter status")}, }, { name: "SuccessFilterWithRunAllFilters", plugins: []*TestPlugin{ { name: "TestPlugin", - inj: injectedResult{FilterStatus: int(Success)}, + inj: injectedResult{FilterStatus: int(v1alpha1.Success)}, }, }, runAllFilters: true, wantStatus: nil, - wantStatusMap: PluginToStatus{}, + wantStatusMap: v1alpha1.PluginToStatus{}, }, { name: "ErrorAndErrorFilters", plugins: []*TestPlugin{ { name: "TestPlugin1", - inj: injectedResult{FilterStatus: int(Error)}, + inj: injectedResult{FilterStatus: int(v1alpha1.Error)}, }, { name: "TestPlugin2", - inj: injectedResult{FilterStatus: int(Error)}, + inj: injectedResult{FilterStatus: int(v1alpha1.Error)}, }, }, runAllFilters: true, - wantStatus: NewStatus(Error, `running "TestPlugin1" filter plugin for pod "": injected filter status`), - wantStatusMap: PluginToStatus{"TestPlugin1": NewStatus(Error, `running "TestPlugin1" filter plugin for pod "": injected filter status`)}, + wantStatus: v1alpha1.NewStatus(v1alpha1.Error, `running "TestPlugin1" filter plugin for pod "": injected filter status`), + wantStatusMap: v1alpha1.PluginToStatus{"TestPlugin1": v1alpha1.NewStatus(v1alpha1.Error, `running "TestPlugin1" filter plugin for pod "": injected filter status`)}, }, { name: "ErrorAndErrorFilters", plugins: []*TestPlugin{ { name: "TestPlugin1", - inj: injectedResult{FilterStatus: int(UnschedulableAndUnresolvable)}, + inj: injectedResult{FilterStatus: int(v1alpha1.UnschedulableAndUnresolvable)}, }, { name: "TestPlugin2", - inj: injectedResult{FilterStatus: int(Unschedulable)}, + inj: injectedResult{FilterStatus: int(v1alpha1.Unschedulable)}, }, }, runAllFilters: true, - wantStatus: NewStatus(UnschedulableAndUnresolvable, "injected filter status", "injected filter status"), - wantStatusMap: PluginToStatus{ - "TestPlugin1": NewStatus(UnschedulableAndUnresolvable, "injected filter status"), - "TestPlugin2": NewStatus(Unschedulable, "injected filter status"), + wantStatus: v1alpha1.NewStatus(v1alpha1.UnschedulableAndUnresolvable, "injected filter status", "injected filter status"), + wantStatusMap: v1alpha1.PluginToStatus{ + "TestPlugin1": v1alpha1.NewStatus(v1alpha1.UnschedulableAndUnresolvable, "injected filter status"), + "TestPlugin2": v1alpha1.NewStatus(v1alpha1.Unschedulable, "injected filter status"), }, }, } @@ -1026,7 +1029,7 @@ func TestFilterPlugins(t *testing.T) { // register all plugins tmpPl := pl if err := registry.Register(pl.name, - func(_ runtime.Object, _ FrameworkHandle) (Plugin, error) { + func(_ runtime.Object, _ v1alpha1.FrameworkHandle) (v1alpha1.Plugin, error) { return tmpPl, nil }); err != nil { t.Fatalf("fail to register filter plugin (%s)", pl.name) @@ -1058,45 +1061,45 @@ func TestPostFilterPlugins(t *testing.T) { tests := []struct { name string plugins []*TestPlugin - wantStatus *Status + wantStatus *v1alpha1.Status }{ { name: "a single plugin makes a Pod schedulable", plugins: []*TestPlugin{ { name: "TestPlugin", - inj: injectedResult{PostFilterStatus: int(Success)}, + inj: injectedResult{PostFilterStatus: int(v1alpha1.Success)}, }, }, - wantStatus: NewStatus(Success, "injected status"), + wantStatus: v1alpha1.NewStatus(v1alpha1.Success, "injected status"), }, { name: "plugin1 failed to make a Pod schedulable, followed by plugin2 which makes the Pod schedulable", plugins: []*TestPlugin{ { name: "TestPlugin1", - inj: injectedResult{PostFilterStatus: int(Unschedulable)}, + inj: injectedResult{PostFilterStatus: int(v1alpha1.Unschedulable)}, }, { name: "TestPlugin2", - inj: injectedResult{PostFilterStatus: int(Success)}, + inj: injectedResult{PostFilterStatus: int(v1alpha1.Success)}, }, }, - wantStatus: NewStatus(Success, "injected status"), + wantStatus: v1alpha1.NewStatus(v1alpha1.Success, "injected status"), }, { name: "plugin1 makes a Pod schedulable, followed by plugin2 which cannot make the Pod schedulable", plugins: []*TestPlugin{ { name: "TestPlugin1", - inj: injectedResult{PostFilterStatus: int(Success)}, + inj: injectedResult{PostFilterStatus: int(v1alpha1.Success)}, }, { name: "TestPlugin2", - inj: injectedResult{PostFilterStatus: int(Unschedulable)}, + inj: injectedResult{PostFilterStatus: int(v1alpha1.Unschedulable)}, }, }, - wantStatus: NewStatus(Success, "injected status"), + wantStatus: v1alpha1.NewStatus(v1alpha1.Success, "injected status"), }, } @@ -1108,7 +1111,7 @@ func TestPostFilterPlugins(t *testing.T) { // register all plugins tmpPl := pl if err := registry.Register(pl.name, - func(_ runtime.Object, _ FrameworkHandle) (Plugin, error) { + func(_ runtime.Object, _ v1alpha1.FrameworkHandle) (v1alpha1.Plugin, error) { return tmpPl, nil }); err != nil { t.Fatalf("fail to register postFilter plugin (%s)", pl.name) @@ -1136,7 +1139,7 @@ func TestPreBindPlugins(t *testing.T) { tests := []struct { name string plugins []*TestPlugin - wantStatus *Status + wantStatus *v1alpha1.Status }{ { name: "NoPreBindPlugin", @@ -1148,7 +1151,7 @@ func TestPreBindPlugins(t *testing.T) { plugins: []*TestPlugin{ { name: "TestPlugin", - inj: injectedResult{PreBindStatus: int(Success)}, + inj: injectedResult{PreBindStatus: int(v1alpha1.Success)}, }, }, wantStatus: nil, @@ -1158,69 +1161,69 @@ func TestPreBindPlugins(t *testing.T) { plugins: []*TestPlugin{ { name: "TestPlugin", - inj: injectedResult{PreBindStatus: int(Unschedulable)}, + inj: injectedResult{PreBindStatus: int(v1alpha1.Unschedulable)}, }, }, - wantStatus: NewStatus(Error, `error while running "TestPlugin" prebind plugin for pod "": injected status`), + wantStatus: v1alpha1.NewStatus(v1alpha1.Error, `error while running "TestPlugin" prebind plugin for pod "": injected status`), }, { name: "ErrorPreBindPlugin", plugins: []*TestPlugin{ { name: "TestPlugin", - inj: injectedResult{PreBindStatus: int(Error)}, + inj: injectedResult{PreBindStatus: int(v1alpha1.Error)}, }, }, - wantStatus: NewStatus(Error, `error while running "TestPlugin" prebind plugin for pod "": injected status`), + wantStatus: v1alpha1.NewStatus(v1alpha1.Error, `error while running "TestPlugin" prebind plugin for pod "": injected status`), }, { name: "UnschedulablePreBindPlugin", plugins: []*TestPlugin{ { name: "TestPlugin", - inj: injectedResult{PreBindStatus: int(UnschedulableAndUnresolvable)}, + inj: injectedResult{PreBindStatus: int(v1alpha1.UnschedulableAndUnresolvable)}, }, }, - wantStatus: NewStatus(Error, `error while running "TestPlugin" prebind plugin for pod "": injected status`), + wantStatus: v1alpha1.NewStatus(v1alpha1.Error, `error while running "TestPlugin" prebind plugin for pod "": injected status`), }, { name: "SuccessErrorPreBindPlugins", plugins: []*TestPlugin{ { name: "TestPlugin", - inj: injectedResult{PreBindStatus: int(Success)}, + inj: injectedResult{PreBindStatus: int(v1alpha1.Success)}, }, { name: "TestPlugin 1", - inj: injectedResult{PreBindStatus: int(Error)}, + inj: injectedResult{PreBindStatus: int(v1alpha1.Error)}, }, }, - wantStatus: NewStatus(Error, `error while running "TestPlugin 1" prebind plugin for pod "": injected status`), + wantStatus: v1alpha1.NewStatus(v1alpha1.Error, `error while running "TestPlugin 1" prebind plugin for pod "": injected status`), }, { name: "ErrorSuccessPreBindPlugin", plugins: []*TestPlugin{ { name: "TestPlugin", - inj: injectedResult{PreBindStatus: int(Error)}, + inj: injectedResult{PreBindStatus: int(v1alpha1.Error)}, }, { name: "TestPlugin 1", - inj: injectedResult{PreBindStatus: int(Success)}, + inj: injectedResult{PreBindStatus: int(v1alpha1.Success)}, }, }, - wantStatus: NewStatus(Error, `error while running "TestPlugin" prebind plugin for pod "": injected status`), + wantStatus: v1alpha1.NewStatus(v1alpha1.Error, `error while running "TestPlugin" prebind plugin for pod "": injected status`), }, { name: "SuccessSuccessPreBindPlugin", plugins: []*TestPlugin{ { name: "TestPlugin", - inj: injectedResult{PreBindStatus: int(Success)}, + inj: injectedResult{PreBindStatus: int(v1alpha1.Success)}, }, { name: "TestPlugin 1", - inj: injectedResult{PreBindStatus: int(Success)}, + inj: injectedResult{PreBindStatus: int(v1alpha1.Success)}, }, }, wantStatus: nil, @@ -1230,28 +1233,28 @@ func TestPreBindPlugins(t *testing.T) { plugins: []*TestPlugin{ { name: "TestPlugin", - inj: injectedResult{PreBindStatus: int(Error)}, + inj: injectedResult{PreBindStatus: int(v1alpha1.Error)}, }, { name: "TestPlugin 1", - inj: injectedResult{PreBindStatus: int(Error)}, + inj: injectedResult{PreBindStatus: int(v1alpha1.Error)}, }, }, - wantStatus: NewStatus(Error, `error while running "TestPlugin" prebind plugin for pod "": injected status`), + wantStatus: v1alpha1.NewStatus(v1alpha1.Error, `error while running "TestPlugin" prebind plugin for pod "": injected status`), }, { name: "UnschedulableAndSuccessPreBindPlugin", plugins: []*TestPlugin{ { name: "TestPlugin", - inj: injectedResult{PreBindStatus: int(Unschedulable)}, + inj: injectedResult{PreBindStatus: int(v1alpha1.Unschedulable)}, }, { name: "TestPlugin 1", - inj: injectedResult{PreBindStatus: int(Success)}, + inj: injectedResult{PreBindStatus: int(v1alpha1.Success)}, }, }, - wantStatus: NewStatus(Error, `error while running "TestPlugin" prebind plugin for pod "": injected status`), + wantStatus: v1alpha1.NewStatus(v1alpha1.Error, `error while running "TestPlugin" prebind plugin for pod "": injected status`), }, } @@ -1262,7 +1265,7 @@ func TestPreBindPlugins(t *testing.T) { for _, pl := range tt.plugins { tmpPl := pl - if err := registry.Register(pl.name, func(_ runtime.Object, _ FrameworkHandle) (Plugin, error) { + if err := registry.Register(pl.name, func(_ runtime.Object, _ v1alpha1.FrameworkHandle) (v1alpha1.Plugin, error) { return tmpPl, nil }); err != nil { t.Fatalf("Unable to register pre bind plugins: %s", pl.name) @@ -1292,7 +1295,7 @@ func TestReservePlugins(t *testing.T) { tests := []struct { name string plugins []*TestPlugin - wantStatus *Status + wantStatus *v1alpha1.Status }{ { name: "NoReservePlugin", @@ -1304,7 +1307,7 @@ func TestReservePlugins(t *testing.T) { plugins: []*TestPlugin{ { name: "TestPlugin", - inj: injectedResult{ReserveStatus: int(Success)}, + inj: injectedResult{ReserveStatus: int(v1alpha1.Success)}, }, }, wantStatus: nil, @@ -1314,41 +1317,41 @@ func TestReservePlugins(t *testing.T) { plugins: []*TestPlugin{ { name: "TestPlugin", - inj: injectedResult{ReserveStatus: int(Unschedulable)}, + inj: injectedResult{ReserveStatus: int(v1alpha1.Unschedulable)}, }, }, - wantStatus: NewStatus(Error, `error while running "TestPlugin" reserve plugin for pod "": injected status`), + wantStatus: v1alpha1.NewStatus(v1alpha1.Error, `error while running "TestPlugin" reserve plugin for pod "": injected status`), }, { name: "ErrorReservePlugin", plugins: []*TestPlugin{ { name: "TestPlugin", - inj: injectedResult{ReserveStatus: int(Error)}, + inj: injectedResult{ReserveStatus: int(v1alpha1.Error)}, }, }, - wantStatus: NewStatus(Error, `error while running "TestPlugin" reserve plugin for pod "": injected status`), + wantStatus: v1alpha1.NewStatus(v1alpha1.Error, `error while running "TestPlugin" reserve plugin for pod "": injected status`), }, { name: "UnschedulableReservePlugin", plugins: []*TestPlugin{ { name: "TestPlugin", - inj: injectedResult{ReserveStatus: int(UnschedulableAndUnresolvable)}, + inj: injectedResult{ReserveStatus: int(v1alpha1.UnschedulableAndUnresolvable)}, }, }, - wantStatus: NewStatus(Error, `error while running "TestPlugin" reserve plugin for pod "": injected status`), + wantStatus: v1alpha1.NewStatus(v1alpha1.Error, `error while running "TestPlugin" reserve plugin for pod "": injected status`), }, { name: "SuccessSuccessReservePlugins", plugins: []*TestPlugin{ { name: "TestPlugin", - inj: injectedResult{ReserveStatus: int(Success)}, + inj: injectedResult{ReserveStatus: int(v1alpha1.Success)}, }, { name: "TestPlugin 1", - inj: injectedResult{ReserveStatus: int(Success)}, + inj: injectedResult{ReserveStatus: int(v1alpha1.Success)}, }, }, wantStatus: nil, @@ -1358,56 +1361,56 @@ func TestReservePlugins(t *testing.T) { plugins: []*TestPlugin{ { name: "TestPlugin", - inj: injectedResult{ReserveStatus: int(Error)}, + inj: injectedResult{ReserveStatus: int(v1alpha1.Error)}, }, { name: "TestPlugin 1", - inj: injectedResult{ReserveStatus: int(Error)}, + inj: injectedResult{ReserveStatus: int(v1alpha1.Error)}, }, }, - wantStatus: NewStatus(Error, `error while running "TestPlugin" reserve plugin for pod "": injected status`), + wantStatus: v1alpha1.NewStatus(v1alpha1.Error, `error while running "TestPlugin" reserve plugin for pod "": injected status`), }, { name: "SuccessErrorReservePlugins", plugins: []*TestPlugin{ { name: "TestPlugin", - inj: injectedResult{ReserveStatus: int(Success)}, + inj: injectedResult{ReserveStatus: int(v1alpha1.Success)}, }, { name: "TestPlugin 1", - inj: injectedResult{ReserveStatus: int(Error)}, + inj: injectedResult{ReserveStatus: int(v1alpha1.Error)}, }, }, - wantStatus: NewStatus(Error, `error while running "TestPlugin 1" reserve plugin for pod "": injected status`), + wantStatus: v1alpha1.NewStatus(v1alpha1.Error, `error while running "TestPlugin 1" reserve plugin for pod "": injected status`), }, { name: "ErrorSuccessReservePlugin", plugins: []*TestPlugin{ { name: "TestPlugin", - inj: injectedResult{ReserveStatus: int(Error)}, + inj: injectedResult{ReserveStatus: int(v1alpha1.Error)}, }, { name: "TestPlugin 1", - inj: injectedResult{ReserveStatus: int(Success)}, + inj: injectedResult{ReserveStatus: int(v1alpha1.Success)}, }, }, - wantStatus: NewStatus(Error, `error while running "TestPlugin" reserve plugin for pod "": injected status`), + wantStatus: v1alpha1.NewStatus(v1alpha1.Error, `error while running "TestPlugin" reserve plugin for pod "": injected status`), }, { name: "UnschedulableAndSuccessReservePlugin", plugins: []*TestPlugin{ { name: "TestPlugin", - inj: injectedResult{ReserveStatus: int(Unschedulable)}, + inj: injectedResult{ReserveStatus: int(v1alpha1.Unschedulable)}, }, { name: "TestPlugin 1", - inj: injectedResult{ReserveStatus: int(Success)}, + inj: injectedResult{ReserveStatus: int(v1alpha1.Success)}, }, }, - wantStatus: NewStatus(Error, `error while running "TestPlugin" reserve plugin for pod "": injected status`), + wantStatus: v1alpha1.NewStatus(v1alpha1.Error, `error while running "TestPlugin" reserve plugin for pod "": injected status`), }, } @@ -1418,7 +1421,7 @@ func TestReservePlugins(t *testing.T) { for _, pl := range tt.plugins { tmpPl := pl - if err := registry.Register(pl.name, func(_ runtime.Object, _ FrameworkHandle) (Plugin, error) { + if err := registry.Register(pl.name, func(_ runtime.Object, _ v1alpha1.FrameworkHandle) (v1alpha1.Plugin, error) { return tmpPl, nil }); err != nil { t.Fatalf("Unable to register pre bind plugins: %s", pl.name) @@ -1448,7 +1451,7 @@ func TestPermitPlugins(t *testing.T) { tests := []struct { name string plugins []*TestPlugin - want *Status + want *v1alpha1.Status }{ { name: "NilPermitPlugin", @@ -1460,7 +1463,7 @@ func TestPermitPlugins(t *testing.T) { plugins: []*TestPlugin{ { name: "TestPlugin", - inj: injectedResult{PermitStatus: int(Success)}, + inj: injectedResult{PermitStatus: int(v1alpha1.Success)}, }, }, want: nil, @@ -1470,51 +1473,51 @@ func TestPermitPlugins(t *testing.T) { plugins: []*TestPlugin{ { name: "TestPlugin", - inj: injectedResult{PermitStatus: int(Unschedulable)}, + inj: injectedResult{PermitStatus: int(v1alpha1.Unschedulable)}, }, }, - want: NewStatus(Unschedulable, `rejected pod "" by permit plugin "TestPlugin": injected status`), + want: v1alpha1.NewStatus(v1alpha1.Unschedulable, `rejected pod "" by permit plugin "TestPlugin": injected status`), }, { name: "ErrorPermitPlugin", plugins: []*TestPlugin{ { name: "TestPlugin", - inj: injectedResult{PermitStatus: int(Error)}, + inj: injectedResult{PermitStatus: int(v1alpha1.Error)}, }, }, - want: NewStatus(Error, `error while running "TestPlugin" permit plugin for pod "": injected status`), + want: v1alpha1.NewStatus(v1alpha1.Error, `error while running "TestPlugin" permit plugin for pod "": injected status`), }, { name: "UnschedulableAndUnresolvablePermitPlugin", plugins: []*TestPlugin{ { name: "TestPlugin", - inj: injectedResult{PermitStatus: int(UnschedulableAndUnresolvable)}, + inj: injectedResult{PermitStatus: int(v1alpha1.UnschedulableAndUnresolvable)}, }, }, - want: NewStatus(UnschedulableAndUnresolvable, `rejected pod "" by permit plugin "TestPlugin": injected status`), + want: v1alpha1.NewStatus(v1alpha1.UnschedulableAndUnresolvable, `rejected pod "" by permit plugin "TestPlugin": injected status`), }, { name: "WaitPermitPlugin", plugins: []*TestPlugin{ { name: "TestPlugin", - inj: injectedResult{PermitStatus: int(Wait)}, + inj: injectedResult{PermitStatus: int(v1alpha1.Wait)}, }, }, - want: NewStatus(Wait, `one or more plugins asked to wait and no plugin rejected pod ""`), + want: v1alpha1.NewStatus(v1alpha1.Wait, `one or more plugins asked to wait and no plugin rejected pod ""`), }, { name: "SuccessSuccessPermitPlugin", plugins: []*TestPlugin{ { name: "TestPlugin", - inj: injectedResult{PermitStatus: int(Success)}, + inj: injectedResult{PermitStatus: int(v1alpha1.Success)}, }, { name: "TestPlugin 1", - inj: injectedResult{PermitStatus: int(Success)}, + inj: injectedResult{PermitStatus: int(v1alpha1.Success)}, }, }, want: nil, @@ -1524,14 +1527,14 @@ func TestPermitPlugins(t *testing.T) { plugins: []*TestPlugin{ { name: "TestPlugin", - inj: injectedResult{PermitStatus: int(Error)}, + inj: injectedResult{PermitStatus: int(v1alpha1.Error)}, }, { name: "TestPlugin 1", - inj: injectedResult{PermitStatus: int(Error)}, + inj: injectedResult{PermitStatus: int(v1alpha1.Error)}, }, }, - want: NewStatus(Error, `error while running "TestPlugin" permit plugin for pod "": injected status`), + want: v1alpha1.NewStatus(v1alpha1.Error, `error while running "TestPlugin" permit plugin for pod "": injected status`), }, } @@ -1541,7 +1544,7 @@ func TestPermitPlugins(t *testing.T) { for _, pl := range tt.plugins { tmpPl := pl - if err := registry.Register(pl.name, func(_ runtime.Object, _ FrameworkHandle) (Plugin, error) { + if err := registry.Register(pl.name, func(_ runtime.Object, _ v1alpha1.FrameworkHandle) (v1alpha1.Plugin, error) { return tmpPl, nil }); err != nil { t.Fatalf("Unable to register Permit plugin: %s", pl.name) @@ -1567,126 +1570,126 @@ func TestPermitPlugins(t *testing.T) { } func TestRecordingMetrics(t *testing.T) { - state := &CycleState{ - recordPluginMetrics: true, - } + state := &v1alpha1.CycleState{} + state.SetRecordPluginMetrics(true) + tests := []struct { name string - action func(f Framework) + action func(f v1alpha1.Framework) inject injectedResult wantExtensionPoint string - wantStatus Code + wantStatus v1alpha1.Code }{ { name: "PreFilter - Success", - action: func(f Framework) { f.RunPreFilterPlugins(context.Background(), state, pod) }, + action: func(f v1alpha1.Framework) { f.RunPreFilterPlugins(context.Background(), state, pod) }, wantExtensionPoint: "PreFilter", - wantStatus: Success, + wantStatus: v1alpha1.Success, }, { name: "PreScore - Success", - action: func(f Framework) { f.RunPreScorePlugins(context.Background(), state, pod, nil) }, + action: func(f v1alpha1.Framework) { f.RunPreScorePlugins(context.Background(), state, pod, nil) }, wantExtensionPoint: "PreScore", - wantStatus: Success, + wantStatus: v1alpha1.Success, }, { name: "Score - Success", - action: func(f Framework) { f.RunScorePlugins(context.Background(), state, pod, nodes) }, + action: func(f v1alpha1.Framework) { f.RunScorePlugins(context.Background(), state, pod, nodes) }, wantExtensionPoint: "Score", - wantStatus: Success, + wantStatus: v1alpha1.Success, }, { name: "Reserve - Success", - action: func(f Framework) { f.RunReservePlugins(context.Background(), state, pod, "") }, + action: func(f v1alpha1.Framework) { f.RunReservePlugins(context.Background(), state, pod, "") }, wantExtensionPoint: "Reserve", - wantStatus: Success, + wantStatus: v1alpha1.Success, }, { name: "Unreserve - Success", - action: func(f Framework) { f.RunUnreservePlugins(context.Background(), state, pod, "") }, + action: func(f v1alpha1.Framework) { f.RunUnreservePlugins(context.Background(), state, pod, "") }, wantExtensionPoint: "Unreserve", - wantStatus: Success, + wantStatus: v1alpha1.Success, }, { name: "PreBind - Success", - action: func(f Framework) { f.RunPreBindPlugins(context.Background(), state, pod, "") }, + action: func(f v1alpha1.Framework) { f.RunPreBindPlugins(context.Background(), state, pod, "") }, wantExtensionPoint: "PreBind", - wantStatus: Success, + wantStatus: v1alpha1.Success, }, { name: "Bind - Success", - action: func(f Framework) { f.RunBindPlugins(context.Background(), state, pod, "") }, + action: func(f v1alpha1.Framework) { f.RunBindPlugins(context.Background(), state, pod, "") }, wantExtensionPoint: "Bind", - wantStatus: Success, + wantStatus: v1alpha1.Success, }, { name: "PostBind - Success", - action: func(f Framework) { f.RunPostBindPlugins(context.Background(), state, pod, "") }, + action: func(f v1alpha1.Framework) { f.RunPostBindPlugins(context.Background(), state, pod, "") }, wantExtensionPoint: "PostBind", - wantStatus: Success, + wantStatus: v1alpha1.Success, }, { name: "Permit - Success", - action: func(f Framework) { f.RunPermitPlugins(context.Background(), state, pod, "") }, + action: func(f v1alpha1.Framework) { f.RunPermitPlugins(context.Background(), state, pod, "") }, wantExtensionPoint: "Permit", - wantStatus: Success, + wantStatus: v1alpha1.Success, }, { name: "PreFilter - Error", - action: func(f Framework) { f.RunPreFilterPlugins(context.Background(), state, pod) }, - inject: injectedResult{PreFilterStatus: int(Error)}, + action: func(f v1alpha1.Framework) { f.RunPreFilterPlugins(context.Background(), state, pod) }, + inject: injectedResult{PreFilterStatus: int(v1alpha1.Error)}, wantExtensionPoint: "PreFilter", - wantStatus: Error, + wantStatus: v1alpha1.Error, }, { name: "PreScore - Error", - action: func(f Framework) { f.RunPreScorePlugins(context.Background(), state, pod, nil) }, - inject: injectedResult{PreScoreStatus: int(Error)}, + action: func(f v1alpha1.Framework) { f.RunPreScorePlugins(context.Background(), state, pod, nil) }, + inject: injectedResult{PreScoreStatus: int(v1alpha1.Error)}, wantExtensionPoint: "PreScore", - wantStatus: Error, + wantStatus: v1alpha1.Error, }, { name: "Score - Error", - action: func(f Framework) { f.RunScorePlugins(context.Background(), state, pod, nodes) }, - inject: injectedResult{ScoreStatus: int(Error)}, + action: func(f v1alpha1.Framework) { f.RunScorePlugins(context.Background(), state, pod, nodes) }, + inject: injectedResult{ScoreStatus: int(v1alpha1.Error)}, wantExtensionPoint: "Score", - wantStatus: Error, + wantStatus: v1alpha1.Error, }, { name: "Reserve - Error", - action: func(f Framework) { f.RunReservePlugins(context.Background(), state, pod, "") }, - inject: injectedResult{ReserveStatus: int(Error)}, + action: func(f v1alpha1.Framework) { f.RunReservePlugins(context.Background(), state, pod, "") }, + inject: injectedResult{ReserveStatus: int(v1alpha1.Error)}, wantExtensionPoint: "Reserve", - wantStatus: Error, + wantStatus: v1alpha1.Error, }, { name: "PreBind - Error", - action: func(f Framework) { f.RunPreBindPlugins(context.Background(), state, pod, "") }, - inject: injectedResult{PreBindStatus: int(Error)}, + action: func(f v1alpha1.Framework) { f.RunPreBindPlugins(context.Background(), state, pod, "") }, + inject: injectedResult{PreBindStatus: int(v1alpha1.Error)}, wantExtensionPoint: "PreBind", - wantStatus: Error, + wantStatus: v1alpha1.Error, }, { name: "Bind - Error", - action: func(f Framework) { f.RunBindPlugins(context.Background(), state, pod, "") }, - inject: injectedResult{BindStatus: int(Error)}, + action: func(f v1alpha1.Framework) { f.RunBindPlugins(context.Background(), state, pod, "") }, + inject: injectedResult{BindStatus: int(v1alpha1.Error)}, wantExtensionPoint: "Bind", - wantStatus: Error, + wantStatus: v1alpha1.Error, }, { name: "Permit - Error", - action: func(f Framework) { f.RunPermitPlugins(context.Background(), state, pod, "") }, - inject: injectedResult{PermitStatus: int(Error)}, + action: func(f v1alpha1.Framework) { f.RunPermitPlugins(context.Background(), state, pod, "") }, + inject: injectedResult{PermitStatus: int(v1alpha1.Error)}, wantExtensionPoint: "Permit", - wantStatus: Error, + wantStatus: v1alpha1.Error, }, { name: "Permit - Wait", - action: func(f Framework) { f.RunPermitPlugins(context.Background(), state, pod, "") }, - inject: injectedResult{PermitStatus: int(Wait)}, + action: func(f v1alpha1.Framework) { f.RunPermitPlugins(context.Background(), state, pod, "") }, + inject: injectedResult{PermitStatus: int(v1alpha1.Wait)}, wantExtensionPoint: "Permit", - wantStatus: Wait, + wantStatus: v1alpha1.Wait, }, } @@ -1699,7 +1702,7 @@ func TestRecordingMetrics(t *testing.T) { plugin := &TestPlugin{name: testPlugin, inj: tt.inject} r := make(Registry) r.Register(testPlugin, - func(_ runtime.Object, fh FrameworkHandle) (Plugin, error) { + func(_ runtime.Object, fh v1alpha1.FrameworkHandle) (v1alpha1.Plugin, error) { return plugin, nil }) pluginSet := &config.PluginSet{Enabled: []config.Plugin{{Name: testPlugin, Weight: 1}}} @@ -1738,68 +1741,68 @@ func TestRecordingMetrics(t *testing.T) { func TestRunBindPlugins(t *testing.T) { tests := []struct { name string - injects []Code - wantStatus Code + injects []v1alpha1.Code + wantStatus v1alpha1.Code }{ { name: "simple success", - injects: []Code{Success}, - wantStatus: Success, + injects: []v1alpha1.Code{v1alpha1.Success}, + wantStatus: v1alpha1.Success, }, { name: "error on second", - injects: []Code{Skip, Error, Success}, - wantStatus: Error, + injects: []v1alpha1.Code{v1alpha1.Skip, v1alpha1.Error, v1alpha1.Success}, + wantStatus: v1alpha1.Error, }, { name: "all skip", - injects: []Code{Skip, Skip, Skip}, - wantStatus: Skip, + injects: []v1alpha1.Code{v1alpha1.Skip, v1alpha1.Skip, v1alpha1.Skip}, + wantStatus: v1alpha1.Skip, }, { name: "error on third, but not reached", - injects: []Code{Skip, Success, Error}, - wantStatus: Success, + injects: []v1alpha1.Code{v1alpha1.Skip, v1alpha1.Success, v1alpha1.Error}, + wantStatus: v1alpha1.Success, }, { name: "no bind plugin, returns default binder", - injects: []Code{}, - wantStatus: Success, + injects: []v1alpha1.Code{}, + wantStatus: v1alpha1.Success, }, { name: "invalid status", - injects: []Code{Unschedulable}, - wantStatus: Error, + injects: []v1alpha1.Code{v1alpha1.Unschedulable}, + wantStatus: v1alpha1.Error, }, { name: "simple error", - injects: []Code{Error}, - wantStatus: Error, + injects: []v1alpha1.Code{v1alpha1.Error}, + wantStatus: v1alpha1.Error, }, { name: "success on second, returns success", - injects: []Code{Skip, Success}, - wantStatus: Success, + injects: []v1alpha1.Code{v1alpha1.Skip, v1alpha1.Success}, + wantStatus: v1alpha1.Success, }, { name: "invalid status, returns error", - injects: []Code{Skip, UnschedulableAndUnresolvable}, - wantStatus: Error, + injects: []v1alpha1.Code{v1alpha1.Skip, v1alpha1.UnschedulableAndUnresolvable}, + wantStatus: v1alpha1.Error, }, { name: "error after success status, returns success", - injects: []Code{Success, Error}, - wantStatus: Success, + injects: []v1alpha1.Code{v1alpha1.Success, v1alpha1.Error}, + wantStatus: v1alpha1.Success, }, { name: "success before invalid status, returns success", - injects: []Code{Success, Error}, - wantStatus: Success, + injects: []v1alpha1.Code{v1alpha1.Success, v1alpha1.Error}, + wantStatus: v1alpha1.Success, }, { name: "success after error status, returns error", - injects: []Code{Error, Success}, - wantStatus: Error, + injects: []v1alpha1.Code{v1alpha1.Error, v1alpha1.Success}, + wantStatus: v1alpha1.Error, }, } for _, tt := range tests { @@ -1814,7 +1817,7 @@ func TestRunBindPlugins(t *testing.T) { name := fmt.Sprintf("bind-%d", i) plugin := &TestPlugin{name: name, inj: injectedResult{BindStatus: int(inj)}} r.Register(name, - func(_ runtime.Object, fh FrameworkHandle) (Plugin, error) { + func(_ runtime.Object, fh v1alpha1.FrameworkHandle) (v1alpha1.Plugin, error) { return plugin, nil }) pluginSet.Enabled = append(pluginSet.Enabled, config.Plugin{Name: name}) @@ -1852,7 +1855,7 @@ func TestPermitWaitDurationMetric(t *testing.T) { }, { name: "WaitOnPermit - Wait Timeout", - inject: injectedResult{PermitStatus: int(Wait)}, + inject: injectedResult{PermitStatus: int(v1alpha1.Wait)}, wantRes: "Unschedulable", }, } @@ -1865,7 +1868,7 @@ func TestPermitWaitDurationMetric(t *testing.T) { plugin := &TestPlugin{name: testPlugin, inj: tt.inject} r := make(Registry) err := r.Register(testPlugin, - func(_ runtime.Object, fh FrameworkHandle) (Plugin, error) { + func(_ runtime.Object, fh v1alpha1.FrameworkHandle) (v1alpha1.Plugin, error) { return plugin, nil }) if err != nil { @@ -1897,24 +1900,24 @@ func TestWaitOnPermit(t *testing.T) { tests := []struct { name string - action func(f Framework) - wantStatus Code + action func(f v1alpha1.Framework) + wantStatus v1alpha1.Code wantMessage string }{ { name: "Reject Waiting Pod", - action: func(f Framework) { + action: func(f v1alpha1.Framework) { f.GetWaitingPod(pod.UID).Reject("reject message") }, - wantStatus: Unschedulable, + wantStatus: v1alpha1.Unschedulable, wantMessage: "pod \"pod\" rejected while waiting on permit: reject message", }, { name: "Allow Waiting Pod", - action: func(f Framework) { + action: func(f v1alpha1.Framework) { f.GetWaitingPod(pod.UID).Allow(permitPlugin) }, - wantStatus: Success, + wantStatus: v1alpha1.Success, wantMessage: "", }, } @@ -1924,7 +1927,7 @@ func TestWaitOnPermit(t *testing.T) { testPermitPlugin := &TestPermitPlugin{} r := make(Registry) r.Register(permitPlugin, - func(_ runtime.Object, fh FrameworkHandle) (Plugin, error) { + func(_ runtime.Object, fh v1alpha1.FrameworkHandle) (v1alpha1.Plugin, error) { return testPermitPlugin, nil }) plugins := &config.Plugins{ @@ -1937,9 +1940,9 @@ func TestWaitOnPermit(t *testing.T) { } runPermitPluginsStatus := f.RunPermitPlugins(context.Background(), nil, pod, "") - if runPermitPluginsStatus.Code() != Wait { + if runPermitPluginsStatus.Code() != v1alpha1.Wait { t.Fatalf("Expected RunPermitPlugins to return status %v, but got %v", - Wait, runPermitPluginsStatus.Code()) + v1alpha1.Wait, runPermitPluginsStatus.Code()) } go tt.action(f) @@ -2021,16 +2024,16 @@ type injectedResult struct { PermitStatus int `json:"permitStatus,omitempty"` } -func setScoreRes(inj injectedResult) (int64, *Status) { - if Code(inj.ScoreStatus) != Success { - return 0, NewStatus(Code(inj.ScoreStatus), "injecting failure.") +func setScoreRes(inj injectedResult) (int64, *v1alpha1.Status) { + if v1alpha1.Code(inj.ScoreStatus) != v1alpha1.Success { + return 0, v1alpha1.NewStatus(v1alpha1.Code(inj.ScoreStatus), "injecting failure.") } return inj.ScoreRes, nil } -func injectNormalizeRes(inj injectedResult, scores NodeScoreList) *Status { - if Code(inj.NormalizeStatus) != Success { - return NewStatus(Code(inj.NormalizeStatus), "injecting failure.") +func injectNormalizeRes(inj injectedResult, scores v1alpha1.NodeScoreList) *v1alpha1.Status { + if v1alpha1.Code(inj.NormalizeStatus) != v1alpha1.Success { + return v1alpha1.NewStatus(v1alpha1.Code(inj.NormalizeStatus), "injecting failure.") } for i := range scores { scores[i].Score = inj.NormalizeRes @@ -2038,7 +2041,7 @@ func injectNormalizeRes(inj injectedResult, scores NodeScoreList) *Status { return nil } -func collectAndComparePluginMetrics(t *testing.T, wantExtensionPoint, wantPlugin string, wantStatus Code) { +func collectAndComparePluginMetrics(t *testing.T, wantExtensionPoint, wantPlugin string, wantStatus v1alpha1.Code) { t.Helper() m := collectHistogramMetric(metrics.PluginExecutionDuration) if len(m.Label) != 3 { @@ -2066,7 +2069,7 @@ func collectAndComparePluginMetrics(t *testing.T, wantExtensionPoint, wantPlugin } } -func collectAndCompareFrameworkMetrics(t *testing.T, wantExtensionPoint string, wantStatus Code) { +func collectAndCompareFrameworkMetrics(t *testing.T, wantExtensionPoint string, wantStatus v1alpha1.Code) { t.Helper() m := collectHistogramMetric(metrics.FrameworkExtensionPointDuration) diff --git a/pkg/scheduler/framework/v1alpha1/metrics_recorder.go b/pkg/scheduler/framework/runtime/metrics_recorder.go similarity index 95% rename from pkg/scheduler/framework/v1alpha1/metrics_recorder.go rename to pkg/scheduler/framework/runtime/metrics_recorder.go index 7751b0def37..8454afa28d2 100644 --- a/pkg/scheduler/framework/v1alpha1/metrics_recorder.go +++ b/pkg/scheduler/framework/runtime/metrics_recorder.go @@ -14,12 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v1alpha1 +package runtime import ( "time" k8smetrics "k8s.io/component-base/metrics" + "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" "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. // 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{ metric: metrics.PluginExecutionDuration, labelValues: []string{pluginName, extensionPoint, status.Code().String()}, diff --git a/pkg/scheduler/framework/v1alpha1/registry.go b/pkg/scheduler/framework/runtime/registry.go similarity index 93% rename from pkg/scheduler/framework/v1alpha1/registry.go rename to pkg/scheduler/framework/runtime/registry.go index 353c97ed867..a1a1df45a6c 100644 --- a/pkg/scheduler/framework/v1alpha1/registry.go +++ b/pkg/scheduler/framework/runtime/registry.go @@ -14,18 +14,19 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v1alpha1 +package runtime import ( "fmt" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/json" + "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" "sigs.k8s.io/yaml" ) // 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. func DecodeInto(obj runtime.Object, into interface{}) error { diff --git a/pkg/scheduler/framework/v1alpha1/registry_test.go b/pkg/scheduler/framework/runtime/registry_test.go similarity index 97% rename from pkg/scheduler/framework/v1alpha1/registry_test.go rename to pkg/scheduler/framework/runtime/registry_test.go index 1ab0a2d513d..c1e0616844a 100644 --- a/pkg/scheduler/framework/v1alpha1/registry_test.go +++ b/pkg/scheduler/framework/runtime/registry_test.go @@ -14,13 +14,14 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v1alpha1 +package runtime import ( "reflect" "testing" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" ) func TestDecodeInto(t *testing.T) { @@ -102,7 +103,7 @@ func (p *mockNoopPlugin) Name() string { } func NewMockNoopPluginFactory() PluginFactory { - return func(_ runtime.Object, _ FrameworkHandle) (Plugin, error) { + return func(_ runtime.Object, _ v1alpha1.FrameworkHandle) (v1alpha1.Plugin, error) { return &mockNoopPlugin{}, nil } } diff --git a/pkg/scheduler/framework/v1alpha1/waiting_pods_map.go b/pkg/scheduler/framework/runtime/waiting_pods_map.go similarity index 91% rename from pkg/scheduler/framework/v1alpha1/waiting_pods_map.go rename to pkg/scheduler/framework/runtime/waiting_pods_map.go index 28c58c40635..25cde8f06dd 100644 --- a/pkg/scheduler/framework/v1alpha1/waiting_pods_map.go +++ b/pkg/scheduler/framework/runtime/waiting_pods_map.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v1alpha1 +package runtime import ( "fmt" @@ -23,6 +23,7 @@ import ( "k8s.io/api/core/v1" "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. @@ -60,7 +61,7 @@ func (m *waitingPodsMap) get(uid types.UID) *waitingPod { } // 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() defer m.mu.RUnlock() for _, v := range m.pods { @@ -72,11 +73,11 @@ func (m *waitingPodsMap) iterate(callback func(WaitingPod)) { type waitingPod struct { pod *v1.Pod pendingPlugins map[string]*time.Timer - s chan *Status + s chan *v1alpha1.Status mu sync.RWMutex } -var _ WaitingPod = &waitingPod{} +var _ v1alpha1.WaitingPod = &waitingPod{} // newWaitingPod returns a new waitingPod instance. 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 // to ensure that non-blocking send will not be ignored - possible situation when // 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)) @@ -142,7 +143,7 @@ func (w *waitingPod) Allow(pluginName string) { // The select clause works as a non-blocking send. // If there is no receiver, it's a no-op (default case). select { - case w.s <- NewStatus(Success, ""): + case w.s <- v1alpha1.NewStatus(v1alpha1.Success, ""): default: } } @@ -158,7 +159,7 @@ func (w *waitingPod) Reject(msg string) { // The select clause works as a non-blocking send. // If there is no receiver, it's a no-op (default case). select { - case w.s <- NewStatus(Unschedulable, msg): + case w.s <- v1alpha1.NewStatus(v1alpha1.Unschedulable, msg): default: } } diff --git a/pkg/scheduler/framework/v1alpha1/BUILD b/pkg/scheduler/framework/v1alpha1/BUILD index cd12d2d800c..bb970d6311d 100644 --- a/pkg/scheduler/framework/v1alpha1/BUILD +++ b/pkg/scheduler/framework/v1alpha1/BUILD @@ -5,13 +5,9 @@ go_library( srcs = [ "cycle_state.go", "extender.go", - "framework.go", "interface.go", "listers.go", - "metrics_recorder.go", - "registry.go", "types.go", - "waiting_pods_map.go", ], importpath = "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1", visibility = ["//visibility:public"], @@ -19,27 +15,19 @@ go_library( "//pkg/apis/core/v1/helper:go_default_library", "//pkg/features: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", "//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/apis/meta/v1: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/util/json: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/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", "//staging/src/k8s.io/kube-scheduler/extender/v1: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", srcs = [ "cycle_state_test.go", - "framework_test.go", "interface_test.go", - "registry_test.go", "types_test.go", ], embed = [":go_default_library"], 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/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/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", ], ) diff --git a/pkg/scheduler/profile/BUILD b/pkg/scheduler/profile/BUILD index fce95fc5ae6..d8851950051 100644 --- a/pkg/scheduler/profile/BUILD +++ b/pkg/scheduler/profile/BUILD @@ -7,6 +7,7 @@ go_library( visibility = ["//visibility:public"], deps = [ "//pkg/scheduler/apis/config:go_default_library", + "//pkg/scheduler/framework/runtime:go_default_library", "//pkg/scheduler/framework/v1alpha1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", "//staging/src/k8s.io/client-go/kubernetes/scheme:go_default_library", @@ -35,6 +36,7 @@ go_test( embed = [":go_default_library"], deps = [ "//pkg/scheduler/apis/config:go_default_library", + "//pkg/scheduler/framework/runtime: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/events/v1beta1:go_default_library", diff --git a/pkg/scheduler/profile/profile.go b/pkg/scheduler/profile/profile.go index eb9ec8b7290..8e1397247d2 100644 --- a/pkg/scheduler/profile/profile.go +++ b/pkg/scheduler/profile/profile.go @@ -26,6 +26,7 @@ import ( "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/tools/events" "k8s.io/kubernetes/pkg/scheduler/apis/config" + frameworkruntime "k8s.io/kubernetes/pkg/scheduler/framework/runtime" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" ) @@ -33,7 +34,7 @@ import ( type RecorderFactory func(string) events.EventRecorder // 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. type Profile struct { @@ -43,9 +44,9 @@ type Profile struct { // NewProfile builds a Profile for the given configuration. func NewProfile(cfg config.KubeSchedulerProfile, frameworkFact FrameworkFactory, recorderFact RecorderFactory, - opts ...framework.Option) (*Profile, error) { + opts ...frameworkruntime.Option) (*Profile, error) { 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 { return nil, err } @@ -60,7 +61,7 @@ type Map map[string]*Profile // NewMap builds the profiles given by the configuration, indexed by name. func NewMap(cfgs []config.KubeSchedulerProfile, frameworkFact FrameworkFactory, recorderFact RecorderFactory, - opts ...framework.Option) (Map, error) { + opts ...frameworkruntime.Option) (Map, error) { m := make(Map) v := cfgValidator{m: m} diff --git a/pkg/scheduler/profile/profile_test.go b/pkg/scheduler/profile/profile_test.go index 5c205df74db..e3a7fca2055 100644 --- a/pkg/scheduler/profile/profile_test.go +++ b/pkg/scheduler/profile/profile_test.go @@ -28,10 +28,11 @@ import ( "k8s.io/client-go/kubernetes/fake" "k8s.io/client-go/tools/events" "k8s.io/kubernetes/pkg/scheduler/apis/config" + frameworkruntime "k8s.io/kubernetes/pkg/scheduler/framework/runtime" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" ) -var fakeRegistry = framework.Registry{ +var fakeRegistry = frameworkruntime.Registry{ "QueueSort": newFakePlugin, "Bind1": newFakePlugin, "Bind2": newFakePlugin, @@ -351,8 +352,8 @@ func newFakePlugin(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plu return &fakePlugin{}, nil } -func fakeFrameworkFactory(cfg config.KubeSchedulerProfile, opts ...framework.Option) (framework.Framework, error) { - return framework.NewFramework(fakeRegistry, cfg.Plugins, cfg.PluginConfig, opts...) +func fakeFrameworkFactory(cfg config.KubeSchedulerProfile, opts ...frameworkruntime.Option) (framework.Framework, error) { + return frameworkruntime.NewFramework(fakeRegistry, cfg.Plugins, cfg.PluginConfig, opts...) } func nilRecorderFactory(_ string) events.EventRecorder { diff --git a/pkg/scheduler/scheduler.go b/pkg/scheduler/scheduler.go index bf8845a2407..2cf3872329e 100644 --- a/pkg/scheduler/scheduler.go +++ b/pkg/scheduler/scheduler.go @@ -38,6 +38,7 @@ import ( "k8s.io/kubernetes/pkg/scheduler/apis/config/scheme" "k8s.io/kubernetes/pkg/scheduler/core" frameworkplugins "k8s.io/kubernetes/pkg/scheduler/framework/plugins" + frameworkruntime "k8s.io/kubernetes/pkg/scheduler/framework/runtime" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" internalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache" internalqueue "k8s.io/kubernetes/pkg/scheduler/internal/queue" @@ -101,7 +102,7 @@ type schedulerOptions struct { podInitialBackoffSeconds int64 podMaxBackoffSeconds int64 // Contains out-of-tree plugins to be merged with the in-tree registry. - frameworkOutOfTreeRegistry framework.Registry + frameworkOutOfTreeRegistry frameworkruntime.Registry profiles []schedulerapi.KubeSchedulerProfile extenders []schedulerapi.Extender frameworkCapturer FrameworkCapturer @@ -141,7 +142,7 @@ func WithPercentageOfNodesToScore(percentageOfNodesToScore int32) Option { // WithFrameworkOutOfTreeRegistry sets the registry for out-of-tree plugins. Those plugins // will be appended to the default registry. -func WithFrameworkOutOfTreeRegistry(registry framework.Registry) Option { +func WithFrameworkOutOfTreeRegistry(registry frameworkruntime.Registry) Option { return func(o *schedulerOptions) { o.frameworkOutOfTreeRegistry = registry } diff --git a/pkg/scheduler/scheduler_test.go b/pkg/scheduler/scheduler_test.go index 048f14de26c..00d531a7422 100644 --- a/pkg/scheduler/scheduler_test.go +++ b/pkg/scheduler/scheduler_test.go @@ -55,6 +55,7 @@ import ( "k8s.io/kubernetes/pkg/scheduler/framework/plugins/noderesources" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/queuesort" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumebinding" + frameworkruntime "k8s.io/kubernetes/pkg/scheduler/framework/runtime" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" internalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache" fakecache "k8s.io/kubernetes/pkg/scheduler/internal/cache/fake" @@ -121,10 +122,10 @@ func (es mockScheduler) Extenders() []framework.Extender { } func TestSchedulerCreation(t *testing.T) { - invalidRegistry := map[string]framework.PluginFactory{ + invalidRegistry := map[string]frameworkruntime.PluginFactory{ defaultbinder.Name: defaultbinder.New, } - validRegistry := map[string]framework.PluginFactory{ + validRegistry := map[string]frameworkruntime.PluginFactory{ "Foo": defaultbinder.New, } cases := []struct { @@ -298,7 +299,7 @@ func TestSchedulerScheduleOne(t *testing.T) { fwk, err := st.NewFramework([]st.RegisterPluginFunc{ st.RegisterQueueSortPlugin(queuesort.Name, queuesort.New), st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), - }, framework.WithClientSet(client)) + }, frameworkruntime.WithClientSet(client)) if err != nil { t.Fatal(err) } @@ -361,7 +362,7 @@ type fakeNodeSelector struct { func newFakeNodeSelector(args runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) { pl := &fakeNodeSelector{} - if err := framework.DecodeInto(args, &pl.fakeNodeSelectorArgs); err != nil { + if err := frameworkruntime.DecodeInto(args, &pl.fakeNodeSelectorArgs); err != nil { return nil, err } return pl, nil @@ -444,7 +445,7 @@ func TestSchedulerMultipleProfilesScheduling(t *testing.T) { }, }, ), - WithFrameworkOutOfTreeRegistry(framework.Registry{ + WithFrameworkOutOfTreeRegistry(frameworkruntime.Registry{ "FakeNodeSelector": newFakeNodeSelector, }), ) @@ -765,7 +766,7 @@ func setupTestScheduler(queuedPodStore *clientcache.FIFO, scache internalcache.C return true, b, nil }) - fwk, _ := st.NewFramework(fns, framework.WithClientSet(client)) + fwk, _ := st.NewFramework(fns, frameworkruntime.WithClientSet(client)) prof := &profile.Profile{ Framework: fwk, Recorder: &events.FakeRecorder{}, @@ -1118,7 +1119,7 @@ func TestSchedulerBinding(t *testing.T) { fwk, err := st.NewFramework([]st.RegisterPluginFunc{ st.RegisterQueueSortPlugin(queuesort.Name, queuesort.New), st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), - }, framework.WithClientSet(client)) + }, frameworkruntime.WithClientSet(client)) if err != nil { t.Fatal(err) } diff --git a/pkg/scheduler/testing/BUILD b/pkg/scheduler/testing/BUILD index 87fd5868e69..721f61eb17d 100644 --- a/pkg/scheduler/testing/BUILD +++ b/pkg/scheduler/testing/BUILD @@ -15,6 +15,7 @@ go_library( deps = [ "//pkg/api/v1/pod: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/util:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library", diff --git a/pkg/scheduler/testing/fake_extender.go b/pkg/scheduler/testing/fake_extender.go index b4fc16a6c1c..e1e89745e0c 100644 --- a/pkg/scheduler/testing/fake_extender.go +++ b/pkg/scheduler/testing/fake_extender.go @@ -25,6 +25,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" extenderv1 "k8s.io/kube-scheduler/extender/v1" podutil "k8s.io/kubernetes/pkg/api/v1/pod" + frameworkruntime "k8s.io/kubernetes/pkg/scheduler/framework/runtime" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" "k8s.io/kubernetes/pkg/scheduler/util" ) @@ -110,7 +111,7 @@ func Machine2PrioritizerExtender(pod *v1.Pod, nodes []*v1.Node) (*framework.Node type machine2PrioritizerPlugin struct{} // 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 &machine2PrioritizerPlugin{}, nil } diff --git a/pkg/scheduler/testing/fake_plugins.go b/pkg/scheduler/testing/fake_plugins.go index bd7ac3f52dd..cf0a26e5505 100644 --- a/pkg/scheduler/testing/fake_plugins.go +++ b/pkg/scheduler/testing/fake_plugins.go @@ -23,6 +23,7 @@ import ( v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" + frameworkruntime "k8s.io/kubernetes/pkg/scheduler/framework/runtime" 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. -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 &FakeFilterPlugin{ FailedNodeReturnCodeMap: failedNodeReturnCodeMap, diff --git a/pkg/scheduler/testing/framework_helpers.go b/pkg/scheduler/testing/framework_helpers.go index 42ee5d39f46..19b45578b0b 100644 --- a/pkg/scheduler/testing/framework_helpers.go +++ b/pkg/scheduler/testing/framework_helpers.go @@ -18,57 +18,58 @@ package testing import ( schedulerapi "k8s.io/kubernetes/pkg/scheduler/apis/config" + "k8s.io/kubernetes/pkg/scheduler/framework/runtime" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" ) // NewFramework creates a Framework from the register functions and options. -func NewFramework(fns []RegisterPluginFunc, opts ...framework.Option) (framework.Framework, error) { - registry := framework.Registry{} +func NewFramework(fns []RegisterPluginFunc, opts ...runtime.Option) (framework.Framework, error) { + registry := runtime.Registry{} plugins := &schedulerapi.Plugins{} var pluginConfigs []schedulerapi.PluginConfig for _, f := range fns { f(®istry, 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() // 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. -func RegisterQueueSortPlugin(pluginName string, pluginNewFunc framework.PluginFactory) RegisterPluginFunc { +func RegisterQueueSortPlugin(pluginName string, pluginNewFunc runtime.PluginFactory) RegisterPluginFunc { return RegisterPluginAsExtensions(pluginName, pluginNewFunc, "QueueSort") } // 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") } // 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") } // 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") } // 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") } // 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...) } // 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 { - return func(reg *framework.Registry, plugins *schedulerapi.Plugins, pluginConfigs []schedulerapi.PluginConfig) { +func RegisterPluginAsExtensionsWithWeight(pluginName string, weight int32, pluginNewFunc runtime.PluginFactory, extensions ...string) RegisterPluginFunc { + return func(reg *runtime.Registry, plugins *schedulerapi.Plugins, pluginConfigs []schedulerapi.PluginConfig) { reg.Register(pluginName, pluginNewFunc) for _, extension := range extensions { ps := getPluginSetByExtension(plugins, extension) diff --git a/test/e2e/framework/.import-restrictions b/test/e2e/framework/.import-restrictions index c2d001d816d..9b0fc023db9 100644 --- a/test/e2e/framework/.import-restrictions +++ b/test/e2e/framework/.import-restrictions @@ -187,6 +187,7 @@ rules: - k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodeports - k8s.io/kubernetes/pkg/scheduler/framework/plugins/noderesources - 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/listers - k8s.io/kubernetes/pkg/scheduler/metrics diff --git a/test/integration/scheduler/BUILD b/test/integration/scheduler/BUILD index a018465b84e..ae90a30f8c2 100644 --- a/test/integration/scheduler/BUILD +++ b/test/integration/scheduler/BUILD @@ -29,6 +29,7 @@ go_test( "//pkg/scheduler:go_default_library", "//pkg/scheduler/apis/config: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/profile:go_default_library", "//pkg/scheduler/testing:go_default_library", diff --git a/test/integration/scheduler/framework_test.go b/test/integration/scheduler/framework_test.go index 50b747f35c8..2f9719c720c 100644 --- a/test/integration/scheduler/framework_test.go +++ b/test/integration/scheduler/framework_test.go @@ -31,6 +31,7 @@ import ( "k8s.io/kubernetes/pkg/scheduler" schedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/defaultbinder" + frameworkruntime "k8s.io/kubernetes/pkg/scheduler/framework/runtime" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" testutils "k8s.io/kubernetes/test/integration/util" ) @@ -145,14 +146,14 @@ var _ framework.UnreservePlugin = &UnreservePlugin{} var _ framework.PermitPlugin = &PermitPlugin{} // 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 plugin, nil } } // 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) { plugin.fh = fh return plugin, nil @@ -498,7 +499,7 @@ func (pp *PermitPlugin) reset() { } // 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) { permitPlugin.fh = fh return permitPlugin, nil @@ -509,7 +510,7 @@ func newPermitPlugin(permitPlugin *PermitPlugin) framework.PluginFactory { func TestPreFilterPlugin(t *testing.T) { // Create a plugin registry for testing. Register only a pre-filter plugin. preFilterPlugin := &PreFilterPlugin{} - registry := framework.Registry{prefilterPluginName: newPlugin(preFilterPlugin)} + registry := frameworkruntime.Registry{prefilterPluginName: newPlugin(preFilterPlugin)} // Setup initial prefilter plugin for testing. prof := schedulerconfig.KubeSchedulerProfile{ @@ -626,7 +627,7 @@ func TestPostFilterPlugin(t *testing.T) { ) filterPlugin.rejectFilter = tt.rejectFilter postFilterPlugin.rejectPostFilter = tt.rejectPostFilter - registry := framework.Registry{ + registry := frameworkruntime.Registry{ filterPluginName: newPlugin(filterPlugin), postfilterPluginName: newPostFilterPlugin(postFilterPlugin), } @@ -688,7 +689,7 @@ func TestPostFilterPlugin(t *testing.T) { func TestScorePlugin(t *testing.T) { // Create a plugin registry for testing. Register only a score plugin. scorePlugin := &ScorePlugin{} - registry := framework.Registry{ + registry := frameworkruntime.Registry{ scorePluginName: newPlugin(scorePlugin), } @@ -763,7 +764,7 @@ func TestScorePlugin(t *testing.T) { func TestNormalizeScorePlugin(t *testing.T) { // Create a plugin registry for testing. Register only a normalize score plugin. scoreWithNormalizePlugin := &ScoreWithNormalizePlugin{} - registry := framework.Registry{ + registry := frameworkruntime.Registry{ scoreWithNormalizePluginName: newPlugin(scoreWithNormalizePlugin), } @@ -809,7 +810,7 @@ func TestNormalizeScorePlugin(t *testing.T) { func TestReservePlugin(t *testing.T) { // Create a plugin registry for testing. Register only a reserve plugin. reservePlugin := &ReservePlugin{} - registry := framework.Registry{reservePluginName: newPlugin(reservePlugin)} + registry := frameworkruntime.Registry{reservePluginName: newPlugin(reservePlugin)} // Setup initial reserve plugin for testing. prof := schedulerconfig.KubeSchedulerProfile{ @@ -880,7 +881,7 @@ func TestReservePlugin(t *testing.T) { func TestPrebindPlugin(t *testing.T) { // Create a plugin registry for testing. Register only a prebind plugin. preBindPlugin := &PreBindPlugin{} - registry := framework.Registry{preBindPluginName: newPlugin(preBindPlugin)} + registry := frameworkruntime.Registry{preBindPluginName: newPlugin(preBindPlugin)} // Setup initial prebind plugin for testing. prof := schedulerconfig.KubeSchedulerProfile{ @@ -963,7 +964,7 @@ func TestUnreservePlugin(t *testing.T) { // TODO: register more plugin which would trigger un-reserve plugin preBindPlugin := &PreBindPlugin{} unreservePlugin := &UnreservePlugin{name: unreservePluginName} - registry := framework.Registry{ + registry := frameworkruntime.Registry{ unreservePluginName: newPlugin(unreservePlugin), preBindPluginName: newPlugin(preBindPlugin), } @@ -1055,7 +1056,7 @@ func TestBindPlugin(t *testing.T) { unreservePlugin := &UnreservePlugin{name: "mock-unreserve-plugin"} postBindPlugin := &PostBindPlugin{name: "mock-post-bind-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) { 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. preBindPlugin := &PreBindPlugin{} postBindPlugin := &PostBindPlugin{name: postBindPluginName} - registry := framework.Registry{ + registry := frameworkruntime.Registry{ preBindPluginName: newPlugin(preBindPlugin), postBindPluginName: newPlugin(postBindPlugin), } @@ -1594,7 +1595,7 @@ func TestCoSchedulingWithPermitPlugin(t *testing.T) { func TestFilterPlugin(t *testing.T) { // Create a plugin registry for testing. Register only a filter plugin. filterPlugin := &FilterPlugin{} - registry := framework.Registry{filterPluginName: newPlugin(filterPlugin)} + registry := frameworkruntime.Registry{filterPluginName: newPlugin(filterPlugin)} // Setup initial filter plugin for testing. prof := schedulerconfig.KubeSchedulerProfile{ @@ -1664,7 +1665,7 @@ func TestFilterPlugin(t *testing.T) { func TestPreScorePlugin(t *testing.T) { // Create a plugin registry for testing. Register only a pre-score plugin. preScorePlugin := &PreScorePlugin{} - registry := framework.Registry{preScorePluginName: newPlugin(preScorePlugin)} + registry := frameworkruntime.Registry{preScorePluginName: newPlugin(preScorePlugin)} // Setup initial pre-score plugin for testing. 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. // 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 { return } - registry = framework.Registry{} + registry = frameworkruntime.Registry{} var plugins []schedulerconfig.Plugin for _, p := range pp { registry.Register(p.Name(), newPermitPlugin(p)) diff --git a/test/integration/scheduler/preemption_test.go b/test/integration/scheduler/preemption_test.go index eb7da02c96d..2ec631207de 100644 --- a/test/integration/scheduler/preemption_test.go +++ b/test/integration/scheduler/preemption_test.go @@ -45,6 +45,7 @@ import ( "k8s.io/kubernetes/pkg/features" "k8s.io/kubernetes/pkg/scheduler" schedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config" + frameworkruntime "k8s.io/kubernetes/pkg/scheduler/framework/runtime" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" "k8s.io/kubernetes/plugin/pkg/admission/priority" testutils "k8s.io/kubernetes/test/integration/util" @@ -124,7 +125,7 @@ var _ framework.FilterPlugin = &tokenFilter{} func TestPreemption(t *testing.T) { // Initialize scheduler with a filter plugin. var filter tokenFilter - registry := make(framework.Registry) + registry := make(frameworkruntime.Registry) err := registry.Register(filterPluginName, func(_ runtime.Object, fh framework.FrameworkHandle) (framework.Plugin, error) { return &filter, nil })