From ce05382b582aa8a92216df487476a5110e40fe25 Mon Sep 17 00:00:00 2001 From: Aldo Culquicondor Date: Wed, 8 Apr 2020 13:47:52 -0400 Subject: [PATCH] Use RawExtension and Object for external and internal scheduling plugin args, respectively Signed-off-by: Aldo Culquicondor --- .../app/options/options_test.go | 12 ++-- .../apis/config/testing/compatibility_test.go | 12 ++-- pkg/scheduler/apis/config/types.go | 2 +- .../v1alpha2/zz_generated.conversion.go | 32 +++++++++-- .../apis/config/zz_generated.deepcopy.go | 4 +- pkg/scheduler/core/extender_test.go | 2 +- pkg/scheduler/core/generic_scheduler_test.go | 22 ++++---- pkg/scheduler/factory.go | 2 +- pkg/scheduler/factory_test.go | 2 +- .../plugins/defaultbinder/default_binder.go | 2 +- .../default_pod_topology_spread.go | 2 +- .../plugins/imagelocality/image_locality.go | 2 +- .../plugins/interpodaffinity/plugin.go | 2 +- .../framework/plugins/legacy_registry.go | 2 +- .../plugins/nodeaffinity/node_affinity.go | 2 +- .../framework/plugins/nodelabel/node_label.go | 2 +- .../framework/plugins/nodename/node_name.go | 2 +- .../framework/plugins/nodeports/node_ports.go | 2 +- .../node_prefer_avoid_pods.go | 2 +- .../noderesources/balanced_allocation.go | 2 +- .../framework/plugins/noderesources/fit.go | 2 +- .../plugins/noderesources/least_allocated.go | 2 +- .../plugins/noderesources/most_allocated.go | 2 +- .../requested_to_capacity_ratio.go | 2 +- .../plugins/noderesources/resource_limits.go | 2 +- .../nodeunschedulable/node_unschedulable.go | 2 +- .../framework/plugins/nodevolumelimits/csi.go | 2 +- .../plugins/nodevolumelimits/non_csi.go | 8 +-- .../plugins/podtopologyspread/plugin.go | 2 +- .../plugins/queuesort/priority_sort.go | 2 +- .../serviceaffinity/service_affinity.go | 2 +- .../tainttoleration/taint_toleration.go | 2 +- .../plugins/volumebinding/volume_binding.go | 2 +- .../volumerestrictions/volume_restrictions.go | 2 +- .../plugins/volumezone/volume_zone.go | 2 +- pkg/scheduler/framework/v1alpha1/framework.go | 4 +- .../framework/v1alpha1/framework_test.go | 56 +++++++++---------- pkg/scheduler/framework/v1alpha1/registry.go | 13 ++++- .../framework/v1alpha1/registry_test.go | 2 +- pkg/scheduler/profile/profile.go | 6 +- pkg/scheduler/profile/profile_test.go | 8 +-- pkg/scheduler/scheduler_test.go | 6 +- .../kube-scheduler/config/v1alpha2/types.go | 2 +- test/integration/scheduler/framework_test.go | 12 ++-- test/integration/scheduler/preemption_test.go | 2 +- 45 files changed, 148 insertions(+), 111 deletions(-) diff --git a/cmd/kube-scheduler/app/options/options_test.go b/cmd/kube-scheduler/app/options/options_test.go index 304d4c0c946..2a88c0c875b 100644 --- a/cmd/kube-scheduler/app/options/options_test.go +++ b/cmd/kube-scheduler/app/options/options_test.go @@ -204,6 +204,8 @@ profiles: - name: baz pluginConfig: - name: foo + args: + bar: baz `, configKubeconfig)), os.FileMode(0600)); err != nil { t.Fatal(err) } @@ -543,7 +545,10 @@ profiles: PluginConfig: []kubeschedulerconfig.PluginConfig{ { Name: "foo", - Args: runtime.Unknown{}, + Args: &runtime.Unknown{ + Raw: []byte(`{"bar":"baz"}`), + ContentType: "application/json", + }, }, }, }, @@ -608,7 +613,6 @@ profiles: PluginConfig: []kubeschedulerconfig.PluginConfig{ { Name: "foo", - Args: runtime.Unknown{}, }, }, }, @@ -666,7 +670,7 @@ profiles: PluginConfig: []kubeschedulerconfig.PluginConfig{ { Name: "InterPodAffinity", - Args: runtime.Unknown{ + Args: &runtime.Unknown{ Raw: []byte(`{"hardPodAffinityWeight":5}`), }, }, @@ -760,7 +764,7 @@ profiles: } if diff := cmp.Diff(tc.expectedConfig, config.ComponentConfig); diff != "" { - t.Errorf("incorrect config (-want, +got):\n%s", diff) + t.Errorf("incorrect config (-want,+got):\n%s", diff) } // ensure we have a client diff --git a/pkg/scheduler/apis/config/testing/compatibility_test.go b/pkg/scheduler/apis/config/testing/compatibility_test.go index 7ac8019c50d..44066b6f471 100644 --- a/pkg/scheduler/apis/config/testing/compatibility_test.go +++ b/pkg/scheduler/apis/config/testing/compatibility_test.go @@ -1598,7 +1598,7 @@ func TestPluginsConfigurationCompatibility(t *testing.T) { pluginConfig: []config.PluginConfig{ { Name: "NodeResourcesFit", - Args: runtime.Unknown{ + Args: &runtime.Unknown{ Raw: []byte(`{ "ignoredResources": [ "foo", @@ -1609,7 +1609,7 @@ func TestPluginsConfigurationCompatibility(t *testing.T) { }, { Name: "PodTopologySpread", - Args: runtime.Unknown{ + Args: &runtime.Unknown{ Raw: []byte(`{ "defaultConstraints": [ { @@ -1628,7 +1628,7 @@ func TestPluginsConfigurationCompatibility(t *testing.T) { }, { Name: "RequestedToCapacityRatio", - Args: runtime.Unknown{ + Args: &runtime.Unknown{ Raw: []byte(`{ "shape":[ "Utilization": 5, @@ -1643,7 +1643,7 @@ func TestPluginsConfigurationCompatibility(t *testing.T) { }, { Name: "InterPodAffinity", - Args: runtime.Unknown{ + Args: &runtime.Unknown{ Raw: []byte(`{ "HardPodAffinityWeight": 100 }`), @@ -1651,7 +1651,7 @@ func TestPluginsConfigurationCompatibility(t *testing.T) { }, { Name: "NodeLabel", - Args: runtime.Unknown{ + Args: &runtime.Unknown{ Raw: []byte(`{ "presentLabels": [ "foo", @@ -1671,7 +1671,7 @@ func TestPluginsConfigurationCompatibility(t *testing.T) { }, { Name: "ServiceAffinity", - Args: runtime.Unknown{ + Args: &runtime.Unknown{ Raw: []byte(`{ affinityLabels: [ "foo", diff --git a/pkg/scheduler/apis/config/types.go b/pkg/scheduler/apis/config/types.go index a21d16fd2ff..aea06a599ca 100644 --- a/pkg/scheduler/apis/config/types.go +++ b/pkg/scheduler/apis/config/types.go @@ -237,7 +237,7 @@ type PluginConfig struct { // Name defines the name of plugin being configured Name string // Args defines the arguments passed to the plugins at the time of initialization. Args can have arbitrary structure. - Args runtime.Unknown + Args runtime.Object } /* diff --git a/pkg/scheduler/apis/config/v1alpha2/zz_generated.conversion.go b/pkg/scheduler/apis/config/v1alpha2/zz_generated.conversion.go index f21a6607caa..0bf56f8b98a 100644 --- a/pkg/scheduler/apis/config/v1alpha2/zz_generated.conversion.go +++ b/pkg/scheduler/apis/config/v1alpha2/zz_generated.conversion.go @@ -336,7 +336,17 @@ func autoConvert_v1alpha2_KubeSchedulerProfile_To_config_KubeSchedulerProfile(in } else { out.Plugins = nil } - out.PluginConfig = *(*[]config.PluginConfig)(unsafe.Pointer(&in.PluginConfig)) + if in.PluginConfig != nil { + in, out := &in.PluginConfig, &out.PluginConfig + *out = make([]config.PluginConfig, len(*in)) + for i := range *in { + if err := Convert_v1alpha2_PluginConfig_To_config_PluginConfig(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.PluginConfig = nil + } return nil } @@ -358,7 +368,17 @@ func autoConvert_config_KubeSchedulerProfile_To_v1alpha2_KubeSchedulerProfile(in } else { out.Plugins = nil } - out.PluginConfig = *(*[]v1alpha2.PluginConfig)(unsafe.Pointer(&in.PluginConfig)) + if in.PluginConfig != nil { + in, out := &in.PluginConfig, &out.PluginConfig + *out = make([]v1alpha2.PluginConfig, len(*in)) + for i := range *in { + if err := Convert_config_PluginConfig_To_v1alpha2_PluginConfig(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.PluginConfig = nil + } return nil } @@ -441,7 +461,9 @@ func Convert_config_Plugin_To_v1alpha2_Plugin(in *config.Plugin, out *v1alpha2.P func autoConvert_v1alpha2_PluginConfig_To_config_PluginConfig(in *v1alpha2.PluginConfig, out *config.PluginConfig, s conversion.Scope) error { out.Name = in.Name - out.Args = in.Args + if err := runtime.Convert_runtime_RawExtension_To_runtime_Object(&in.Args, &out.Args, s); err != nil { + return err + } return nil } @@ -452,7 +474,9 @@ func Convert_v1alpha2_PluginConfig_To_config_PluginConfig(in *v1alpha2.PluginCon func autoConvert_config_PluginConfig_To_v1alpha2_PluginConfig(in *config.PluginConfig, out *v1alpha2.PluginConfig, s conversion.Scope) error { out.Name = in.Name - out.Args = in.Args + if err := runtime.Convert_runtime_Object_To_runtime_RawExtension(&in.Args, &out.Args, s); err != nil { + return err + } return nil } diff --git a/pkg/scheduler/apis/config/zz_generated.deepcopy.go b/pkg/scheduler/apis/config/zz_generated.deepcopy.go index 918847eb93d..b5e159394a7 100644 --- a/pkg/scheduler/apis/config/zz_generated.deepcopy.go +++ b/pkg/scheduler/apis/config/zz_generated.deepcopy.go @@ -341,7 +341,9 @@ func (in *Plugin) DeepCopy() *Plugin { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PluginConfig) DeepCopyInto(out *PluginConfig) { *out = *in - in.Args.DeepCopyInto(&out.Args) + if in.Args != nil { + out.Args = in.Args.DeepCopyObject() + } return } diff --git a/pkg/scheduler/core/extender_test.go b/pkg/scheduler/core/extender_test.go index a7b20bb912b..965b5b93a93 100644 --- a/pkg/scheduler/core/extender_test.go +++ b/pkg/scheduler/core/extender_test.go @@ -110,7 +110,7 @@ func machine2PrioritizerExtender(pod *v1.Pod, nodes []*v1.Node) (*framework.Node type machine2PrioritizerPlugin struct{} func newMachine2PrioritizerPlugin() framework.PluginFactory { - return func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) { + return func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) { return &machine2PrioritizerPlugin{}, nil } } diff --git a/pkg/scheduler/core/generic_scheduler_test.go b/pkg/scheduler/core/generic_scheduler_test.go index 12cff0672b8..29af9c1a1ee 100644 --- a/pkg/scheduler/core/generic_scheduler_test.go +++ b/pkg/scheduler/core/generic_scheduler_test.go @@ -81,7 +81,7 @@ func (pl *trueFilterPlugin) Filter(_ context.Context, _ *framework.CycleState, p } // NewTrueFilterPlugin initializes a trueFilterPlugin and returns it. -func NewTrueFilterPlugin(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) { +func NewTrueFilterPlugin(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) { return &trueFilterPlugin{}, nil } @@ -98,7 +98,7 @@ func (pl *falseFilterPlugin) Filter(_ context.Context, _ *framework.CycleState, } // NewFalseFilterPlugin initializes a falseFilterPlugin and returns it. -func NewFalseFilterPlugin(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) { +func NewFalseFilterPlugin(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) { return &falseFilterPlugin{}, nil } @@ -122,7 +122,7 @@ func (pl *matchFilterPlugin) Filter(_ context.Context, _ *framework.CycleState, } // NewMatchFilterPlugin initializes a matchFilterPlugin and returns it. -func NewMatchFilterPlugin(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) { +func NewMatchFilterPlugin(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) { return &matchFilterPlugin{}, nil } @@ -142,7 +142,7 @@ func (pl *noPodsFilterPlugin) Filter(_ context.Context, _ *framework.CycleState, } // NewNoPodsFilterPlugin initializes a noPodsFilterPlugin and returns it. -func NewNoPodsFilterPlugin(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) { +func NewNoPodsFilterPlugin(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) { return &noPodsFilterPlugin{}, nil } @@ -171,7 +171,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 { - return func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) { + return func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) { return &fakeFilterPlugin{ failedNodeReturnCodeMap: failedNodeReturnCodeMap, }, nil @@ -181,7 +181,7 @@ func NewFakeFilterPlugin(failedNodeReturnCodeMap map[string]framework.Code) fram type numericMapPlugin struct{} func newNumericMapPlugin() framework.PluginFactory { - return func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) { + return func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) { return &numericMapPlugin{}, nil } } @@ -205,7 +205,7 @@ func (pl *numericMapPlugin) ScoreExtensions() framework.ScoreExtensions { type reverseNumericMapPlugin struct{} func newReverseNumericMapPlugin() framework.PluginFactory { - return func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) { + return func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) { return &reverseNumericMapPlugin{}, nil } } @@ -246,7 +246,7 @@ func (pl *reverseNumericMapPlugin) NormalizeScore(_ context.Context, _ *framewor type trueMapPlugin struct{} func newTrueMapPlugin() framework.PluginFactory { - return func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) { + return func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) { return &trueMapPlugin{}, nil } } @@ -275,7 +275,7 @@ func (pl *trueMapPlugin) NormalizeScore(_ context.Context, _ *framework.CycleSta type falseMapPlugin struct{} func newFalseMapPlugin() framework.PluginFactory { - return func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) { + return func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) { return &falseMapPlugin{}, nil } } @@ -962,7 +962,7 @@ func TestFindFitPredicateCallCounts(t *testing.T) { plugin := fakeFilterPlugin{} registerFakeFilterFunc := st.RegisterFilterPlugin( "FakeFilter", - func(_ *runtime.Unknown, fh framework.FrameworkHandle) (framework.Plugin, error) { + func(_ runtime.Object, fh framework.FrameworkHandle) (framework.Plugin, error) { return &plugin, nil }, ) @@ -1598,7 +1598,7 @@ func TestSelectNodesForPreemption(t *testing.T) { fakePlugin.failedNodeReturnCodeMap = filterFailedNodeReturnCodeMap registerFakeFilterFunc := st.RegisterFilterPlugin( "FakeFilter", - func(_ *runtime.Unknown, fh framework.FrameworkHandle) (framework.Plugin, error) { + func(_ runtime.Object, fh framework.FrameworkHandle) (framework.Plugin, error) { return &fakePlugin, nil }, ) diff --git a/pkg/scheduler/factory.go b/pkg/scheduler/factory.go index d5631a1e9a4..fc581005ff0 100644 --- a/pkg/scheduler/factory.go +++ b/pkg/scheduler/factory.go @@ -342,7 +342,7 @@ func (c *Configurator) createFromConfig(policy schedulerapi.Policy) (*Scheduler, // mergePluginConfigsFromPolicy merges the giving plugin configs ensuring that, // if a plugin name is repeated, the arguments are the same. func mergePluginConfigsFromPolicy(pc1, pc2 []schedulerapi.PluginConfig) ([]schedulerapi.PluginConfig, error) { - args := make(map[string]runtime.Unknown) + args := make(map[string]runtime.Object) for _, c := range pc1 { args[c.Name] = c.Args } diff --git a/pkg/scheduler/factory_test.go b/pkg/scheduler/factory_test.go index cd1eb70c0f0..76ee825566a 100644 --- a/pkg/scheduler/factory_test.go +++ b/pkg/scheduler/factory_test.go @@ -251,7 +251,7 @@ func TestCreateFromConfigWithHardPodAffinitySymmetricWeight(t *testing.T) { for _, cfg := range factory.profiles[0].PluginConfig { if cfg.Name == interpodaffinity.Name { foundAffinityCfg = true - wantArgs := runtime.Unknown{Raw: []byte(`{"hardPodAffinityWeight":10}`)} + wantArgs := &runtime.Unknown{Raw: []byte(`{"hardPodAffinityWeight":10}`)} if diff := cmp.Diff(wantArgs, cfg.Args); diff != "" { t.Errorf("wrong InterPodAffinity args (-want, +got): %s", diff) diff --git a/pkg/scheduler/framework/plugins/defaultbinder/default_binder.go b/pkg/scheduler/framework/plugins/defaultbinder/default_binder.go index 73525b17052..127d5bbca8a 100644 --- a/pkg/scheduler/framework/plugins/defaultbinder/default_binder.go +++ b/pkg/scheduler/framework/plugins/defaultbinder/default_binder.go @@ -37,7 +37,7 @@ type DefaultBinder struct { var _ framework.BindPlugin = &DefaultBinder{} // New creates a DefaultBinder. -func New(_ *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plugin, error) { +func New(_ runtime.Object, handle framework.FrameworkHandle) (framework.Plugin, error) { return &DefaultBinder{handle: handle}, nil } diff --git a/pkg/scheduler/framework/plugins/defaultpodtopologyspread/default_pod_topology_spread.go b/pkg/scheduler/framework/plugins/defaultpodtopologyspread/default_pod_topology_spread.go index 30a571bd294..da3835ad134 100644 --- a/pkg/scheduler/framework/plugins/defaultpodtopologyspread/default_pod_topology_spread.go +++ b/pkg/scheduler/framework/plugins/defaultpodtopologyspread/default_pod_topology_spread.go @@ -188,7 +188,7 @@ func (pl *DefaultPodTopologySpread) PreScore(ctx context.Context, cycleState *fr } // New initializes a new plugin and returns it. -func New(_ *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plugin, error) { +func New(_ runtime.Object, handle framework.FrameworkHandle) (framework.Plugin, error) { return &DefaultPodTopologySpread{ handle: handle, }, nil diff --git a/pkg/scheduler/framework/plugins/imagelocality/image_locality.go b/pkg/scheduler/framework/plugins/imagelocality/image_locality.go index 2da5119bab9..80ab8ba85d8 100644 --- a/pkg/scheduler/framework/plugins/imagelocality/image_locality.go +++ b/pkg/scheduler/framework/plugins/imagelocality/image_locality.go @@ -74,7 +74,7 @@ func (pl *ImageLocality) ScoreExtensions() framework.ScoreExtensions { } // New initializes a new plugin and returns it. -func New(_ *runtime.Unknown, h framework.FrameworkHandle) (framework.Plugin, error) { +func New(_ runtime.Object, h framework.FrameworkHandle) (framework.Plugin, error) { return &ImageLocality{handle: h}, nil } diff --git a/pkg/scheduler/framework/plugins/interpodaffinity/plugin.go b/pkg/scheduler/framework/plugins/interpodaffinity/plugin.go index b97a56bfe5e..5baaf09311d 100644 --- a/pkg/scheduler/framework/plugins/interpodaffinity/plugin.go +++ b/pkg/scheduler/framework/plugins/interpodaffinity/plugin.go @@ -62,7 +62,7 @@ func (pl *InterPodAffinity) BuildArgs() interface{} { } // New initializes a new plugin and returns it. -func New(plArgs *runtime.Unknown, h framework.FrameworkHandle) (framework.Plugin, error) { +func New(plArgs runtime.Object, h framework.FrameworkHandle) (framework.Plugin, error) { if h.SnapshotSharedLister() == nil { return nil, fmt.Errorf("SnapshotSharedlister is nil") } diff --git a/pkg/scheduler/framework/plugins/legacy_registry.go b/pkg/scheduler/framework/plugins/legacy_registry.go index 3dee1d523c2..ffafc030828 100644 --- a/pkg/scheduler/framework/plugins/legacy_registry.go +++ b/pkg/scheduler/framework/plugins/legacy_registry.go @@ -496,7 +496,7 @@ func NewPluginConfig(pluginName string, args interface{}) config.PluginConfig { } return config.PluginConfig{ Name: pluginName, - Args: runtime.Unknown{Raw: encoding}, + Args: &runtime.Unknown{Raw: encoding}, } } diff --git a/pkg/scheduler/framework/plugins/nodeaffinity/node_affinity.go b/pkg/scheduler/framework/plugins/nodeaffinity/node_affinity.go index 7c575c48985..4309c00be83 100644 --- a/pkg/scheduler/framework/plugins/nodeaffinity/node_affinity.go +++ b/pkg/scheduler/framework/plugins/nodeaffinity/node_affinity.go @@ -113,6 +113,6 @@ func (pl *NodeAffinity) ScoreExtensions() framework.ScoreExtensions { } // New initializes a new plugin and returns it. -func New(_ *runtime.Unknown, h framework.FrameworkHandle) (framework.Plugin, error) { +func New(_ runtime.Object, h framework.FrameworkHandle) (framework.Plugin, error) { return &NodeAffinity{handle: h}, nil } diff --git a/pkg/scheduler/framework/plugins/nodelabel/node_label.go b/pkg/scheduler/framework/plugins/nodelabel/node_label.go index 86c286be91e..b84965acb63 100644 --- a/pkg/scheduler/framework/plugins/nodelabel/node_label.go +++ b/pkg/scheduler/framework/plugins/nodelabel/node_label.go @@ -50,7 +50,7 @@ func validateNoConflict(presentLabels []string, absentLabels []string) error { } // New initializes a new plugin and returns it. -func New(plArgs *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plugin, error) { +func New(plArgs runtime.Object, handle framework.FrameworkHandle) (framework.Plugin, error) { args := schedulerv1alpha2.NodeLabelArgs{} if err := framework.DecodeInto(plArgs, &args); err != nil { return nil, err diff --git a/pkg/scheduler/framework/plugins/nodename/node_name.go b/pkg/scheduler/framework/plugins/nodename/node_name.go index 2d01280c7ca..8d1a50666c9 100644 --- a/pkg/scheduler/framework/plugins/nodename/node_name.go +++ b/pkg/scheduler/framework/plugins/nodename/node_name.go @@ -59,6 +59,6 @@ func Fits(pod *v1.Pod, nodeInfo *framework.NodeInfo) bool { } // New initializes a new plugin and returns it. -func New(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) { +func New(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) { return &NodeName{}, nil } diff --git a/pkg/scheduler/framework/plugins/nodeports/node_ports.go b/pkg/scheduler/framework/plugins/nodeports/node_ports.go index 44ab9806a93..6750fa76579 100644 --- a/pkg/scheduler/framework/plugins/nodeports/node_ports.go +++ b/pkg/scheduler/framework/plugins/nodeports/node_ports.go @@ -128,6 +128,6 @@ func fitsPorts(wantPorts []*v1.ContainerPort, nodeInfo *framework.NodeInfo) bool } // New initializes a new plugin and returns it. -func New(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) { +func New(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) { return &NodePorts{}, nil } diff --git a/pkg/scheduler/framework/plugins/nodepreferavoidpods/node_prefer_avoid_pods.go b/pkg/scheduler/framework/plugins/nodepreferavoidpods/node_prefer_avoid_pods.go index 8450f6b707f..8daff1a0907 100644 --- a/pkg/scheduler/framework/plugins/nodepreferavoidpods/node_prefer_avoid_pods.go +++ b/pkg/scheduler/framework/plugins/nodepreferavoidpods/node_prefer_avoid_pods.go @@ -87,6 +87,6 @@ func (pl *NodePreferAvoidPods) ScoreExtensions() framework.ScoreExtensions { } // New initializes a new plugin and returns it. -func New(_ *runtime.Unknown, h framework.FrameworkHandle) (framework.Plugin, error) { +func New(_ runtime.Object, h framework.FrameworkHandle) (framework.Plugin, error) { return &NodePreferAvoidPods{handle: h}, nil } diff --git a/pkg/scheduler/framework/plugins/noderesources/balanced_allocation.go b/pkg/scheduler/framework/plugins/noderesources/balanced_allocation.go index a3afffe86d2..a5d17f737b2 100644 --- a/pkg/scheduler/framework/plugins/noderesources/balanced_allocation.go +++ b/pkg/scheduler/framework/plugins/noderesources/balanced_allocation.go @@ -68,7 +68,7 @@ func (ba *BalancedAllocation) ScoreExtensions() framework.ScoreExtensions { } // NewBalancedAllocation initializes a new plugin and returns it. -func NewBalancedAllocation(_ *runtime.Unknown, h framework.FrameworkHandle) (framework.Plugin, error) { +func NewBalancedAllocation(_ runtime.Object, h framework.FrameworkHandle) (framework.Plugin, error) { return &BalancedAllocation{ handle: h, resourceAllocationScorer: resourceAllocationScorer{ diff --git a/pkg/scheduler/framework/plugins/noderesources/fit.go b/pkg/scheduler/framework/plugins/noderesources/fit.go index 6227ea73705..380d2376185 100644 --- a/pkg/scheduler/framework/plugins/noderesources/fit.go +++ b/pkg/scheduler/framework/plugins/noderesources/fit.go @@ -63,7 +63,7 @@ func (f *Fit) Name() string { } // NewFit initializes a new plugin and returns it. -func NewFit(plArgs *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) { +func NewFit(plArgs runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) { args := &schedulerv1alpha2.NodeResourcesFitArgs{} if err := framework.DecodeInto(plArgs, args); err != nil { return nil, err diff --git a/pkg/scheduler/framework/plugins/noderesources/least_allocated.go b/pkg/scheduler/framework/plugins/noderesources/least_allocated.go index 887925ecab1..7601446ec64 100644 --- a/pkg/scheduler/framework/plugins/noderesources/least_allocated.go +++ b/pkg/scheduler/framework/plugins/noderesources/least_allocated.go @@ -63,7 +63,7 @@ func (la *LeastAllocated) ScoreExtensions() framework.ScoreExtensions { } // NewLeastAllocated initializes a new plugin and returns it. -func NewLeastAllocated(_ *runtime.Unknown, h framework.FrameworkHandle) (framework.Plugin, error) { +func NewLeastAllocated(_ runtime.Object, h framework.FrameworkHandle) (framework.Plugin, error) { return &LeastAllocated{ handle: h, resourceAllocationScorer: resourceAllocationScorer{ diff --git a/pkg/scheduler/framework/plugins/noderesources/most_allocated.go b/pkg/scheduler/framework/plugins/noderesources/most_allocated.go index 380f74d40cf..9f30c29fe1c 100644 --- a/pkg/scheduler/framework/plugins/noderesources/most_allocated.go +++ b/pkg/scheduler/framework/plugins/noderesources/most_allocated.go @@ -61,7 +61,7 @@ func (ma *MostAllocated) ScoreExtensions() framework.ScoreExtensions { } // NewMostAllocated initializes a new plugin and returns it. -func NewMostAllocated(_ *runtime.Unknown, h framework.FrameworkHandle) (framework.Plugin, error) { +func NewMostAllocated(_ runtime.Object, h framework.FrameworkHandle) (framework.Plugin, error) { return &MostAllocated{ handle: h, resourceAllocationScorer: resourceAllocationScorer{ diff --git a/pkg/scheduler/framework/plugins/noderesources/requested_to_capacity_ratio.go b/pkg/scheduler/framework/plugins/noderesources/requested_to_capacity_ratio.go index 9dc5d293505..57d198b1e4a 100644 --- a/pkg/scheduler/framework/plugins/noderesources/requested_to_capacity_ratio.go +++ b/pkg/scheduler/framework/plugins/noderesources/requested_to_capacity_ratio.go @@ -48,7 +48,7 @@ type functionShapePoint struct { } // NewRequestedToCapacityRatio initializes a new plugin and returns it. -func NewRequestedToCapacityRatio(plArgs *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plugin, error) { +func NewRequestedToCapacityRatio(plArgs runtime.Object, handle framework.FrameworkHandle) (framework.Plugin, error) { args := &schedulerv1alpha2.RequestedToCapacityRatioArgs{} if err := framework.DecodeInto(plArgs, args); err != nil { return nil, err diff --git a/pkg/scheduler/framework/plugins/noderesources/resource_limits.go b/pkg/scheduler/framework/plugins/noderesources/resource_limits.go index 73387c25679..5d5a22f85cd 100644 --- a/pkg/scheduler/framework/plugins/noderesources/resource_limits.go +++ b/pkg/scheduler/framework/plugins/noderesources/resource_limits.go @@ -128,7 +128,7 @@ func (rl *ResourceLimits) ScoreExtensions() framework.ScoreExtensions { } // NewResourceLimits initializes a new plugin and returns it. -func NewResourceLimits(_ *runtime.Unknown, h framework.FrameworkHandle) (framework.Plugin, error) { +func NewResourceLimits(_ runtime.Object, h framework.FrameworkHandle) (framework.Plugin, error) { return &ResourceLimits{handle: h}, nil } diff --git a/pkg/scheduler/framework/plugins/nodeunschedulable/node_unschedulable.go b/pkg/scheduler/framework/plugins/nodeunschedulable/node_unschedulable.go index 7a0689347ff..ffc85e32c21 100644 --- a/pkg/scheduler/framework/plugins/nodeunschedulable/node_unschedulable.go +++ b/pkg/scheduler/framework/plugins/nodeunschedulable/node_unschedulable.go @@ -65,6 +65,6 @@ func (pl *NodeUnschedulable) Filter(ctx context.Context, _ *framework.CycleState } // New initializes a new plugin and returns it. -func New(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) { +func New(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) { return &NodeUnschedulable{}, nil } diff --git a/pkg/scheduler/framework/plugins/nodevolumelimits/csi.go b/pkg/scheduler/framework/plugins/nodevolumelimits/csi.go index 44eeeb0173a..448992ae15c 100644 --- a/pkg/scheduler/framework/plugins/nodevolumelimits/csi.go +++ b/pkg/scheduler/framework/plugins/nodevolumelimits/csi.go @@ -268,7 +268,7 @@ func (pl *CSILimits) getCSIDriverInfoFromSC(csiNode *storagev1.CSINode, pvc *v1. } // NewCSI initializes a new plugin and returns it. -func NewCSI(_ *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plugin, error) { +func NewCSI(_ runtime.Object, handle framework.FrameworkHandle) (framework.Plugin, error) { informerFactory := handle.SharedInformerFactory() pvLister := informerFactory.Core().V1().PersistentVolumes().Lister() pvcLister := informerFactory.Core().V1().PersistentVolumeClaims().Lister() diff --git a/pkg/scheduler/framework/plugins/nodevolumelimits/non_csi.go b/pkg/scheduler/framework/plugins/nodevolumelimits/non_csi.go index 3728b7eb051..bc63b0e6272 100644 --- a/pkg/scheduler/framework/plugins/nodevolumelimits/non_csi.go +++ b/pkg/scheduler/framework/plugins/nodevolumelimits/non_csi.go @@ -68,7 +68,7 @@ const ( const AzureDiskName = "AzureDiskLimits" // NewAzureDisk returns function that initializes a new plugin and returns it. -func NewAzureDisk(_ *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plugin, error) { +func NewAzureDisk(_ runtime.Object, handle framework.FrameworkHandle) (framework.Plugin, error) { informerFactory := handle.SharedInformerFactory() return newNonCSILimitsWithInformerFactory(azureDiskVolumeFilterType, informerFactory), nil } @@ -77,7 +77,7 @@ func NewAzureDisk(_ *runtime.Unknown, handle framework.FrameworkHandle) (framewo const CinderName = "CinderLimits" // NewCinder returns function that initializes a new plugin and returns it. -func NewCinder(_ *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plugin, error) { +func NewCinder(_ runtime.Object, handle framework.FrameworkHandle) (framework.Plugin, error) { informerFactory := handle.SharedInformerFactory() return newNonCSILimitsWithInformerFactory(cinderVolumeFilterType, informerFactory), nil } @@ -86,7 +86,7 @@ func NewCinder(_ *runtime.Unknown, handle framework.FrameworkHandle) (framework. const EBSName = "EBSLimits" // NewEBS returns function that initializes a new plugin and returns it. -func NewEBS(_ *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plugin, error) { +func NewEBS(_ runtime.Object, handle framework.FrameworkHandle) (framework.Plugin, error) { informerFactory := handle.SharedInformerFactory() return newNonCSILimitsWithInformerFactory(ebsVolumeFilterType, informerFactory), nil } @@ -95,7 +95,7 @@ func NewEBS(_ *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plu const GCEPDName = "GCEPDLimits" // NewGCEPD returns function that initializes a new plugin and returns it. -func NewGCEPD(_ *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plugin, error) { +func NewGCEPD(_ runtime.Object, handle framework.FrameworkHandle) (framework.Plugin, error) { informerFactory := handle.SharedInformerFactory() return newNonCSILimitsWithInformerFactory(gcePDVolumeFilterType, informerFactory), nil } diff --git a/pkg/scheduler/framework/plugins/podtopologyspread/plugin.go b/pkg/scheduler/framework/plugins/podtopologyspread/plugin.go index 6c2f6609164..5c5fa703f42 100644 --- a/pkg/scheduler/framework/plugins/podtopologyspread/plugin.go +++ b/pkg/scheduler/framework/plugins/podtopologyspread/plugin.go @@ -83,7 +83,7 @@ func (pl *PodTopologySpread) BuildArgs() interface{} { } // New initializes a new plugin and returns it. -func New(args *runtime.Unknown, h framework.FrameworkHandle) (framework.Plugin, error) { +func New(args runtime.Object, h framework.FrameworkHandle) (framework.Plugin, error) { if h.SnapshotSharedLister() == nil { return nil, fmt.Errorf("SnapshotSharedlister is nil") } diff --git a/pkg/scheduler/framework/plugins/queuesort/priority_sort.go b/pkg/scheduler/framework/plugins/queuesort/priority_sort.go index b0099209a74..193911de6d8 100644 --- a/pkg/scheduler/framework/plugins/queuesort/priority_sort.go +++ b/pkg/scheduler/framework/plugins/queuesort/priority_sort.go @@ -45,6 +45,6 @@ func (pl *PrioritySort) Less(pInfo1, pInfo2 *framework.PodInfo) bool { } // New initializes a new plugin and returns it. -func New(_ *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plugin, error) { +func New(_ runtime.Object, handle framework.FrameworkHandle) (framework.Plugin, error) { return &PrioritySort{}, nil } diff --git a/pkg/scheduler/framework/plugins/serviceaffinity/service_affinity.go b/pkg/scheduler/framework/plugins/serviceaffinity/service_affinity.go index 299bfdb7f4e..f600e4a422a 100644 --- a/pkg/scheduler/framework/plugins/serviceaffinity/service_affinity.go +++ b/pkg/scheduler/framework/plugins/serviceaffinity/service_affinity.go @@ -63,7 +63,7 @@ func (s *preFilterState) Clone() framework.StateData { } // New initializes a new plugin and returns it. -func New(plArgs *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plugin, error) { +func New(plArgs runtime.Object, handle framework.FrameworkHandle) (framework.Plugin, error) { args := schedulerv1alpha2.ServiceAffinityArgs{} if err := framework.DecodeInto(plArgs, &args); err != nil { return nil, err diff --git a/pkg/scheduler/framework/plugins/tainttoleration/taint_toleration.go b/pkg/scheduler/framework/plugins/tainttoleration/taint_toleration.go index 73bfea7e5a9..866f560470b 100644 --- a/pkg/scheduler/framework/plugins/tainttoleration/taint_toleration.go +++ b/pkg/scheduler/framework/plugins/tainttoleration/taint_toleration.go @@ -167,6 +167,6 @@ func (pl *TaintToleration) ScoreExtensions() framework.ScoreExtensions { } // New initializes a new plugin and returns it. -func New(_ *runtime.Unknown, h framework.FrameworkHandle) (framework.Plugin, error) { +func New(_ runtime.Object, h framework.FrameworkHandle) (framework.Plugin, error) { return &TaintToleration{handle: h}, nil } diff --git a/pkg/scheduler/framework/plugins/volumebinding/volume_binding.go b/pkg/scheduler/framework/plugins/volumebinding/volume_binding.go index bde2b62b1cb..f1f1b105f4a 100644 --- a/pkg/scheduler/framework/plugins/volumebinding/volume_binding.go +++ b/pkg/scheduler/framework/plugins/volumebinding/volume_binding.go @@ -88,7 +88,7 @@ func (pl *VolumeBinding) Filter(ctx context.Context, cs *framework.CycleState, p } // New initializes a new plugin with volume binder and returns it. -func New(_ *runtime.Unknown, fh framework.FrameworkHandle) (framework.Plugin, error) { +func New(_ runtime.Object, fh framework.FrameworkHandle) (framework.Plugin, error) { return &VolumeBinding{ binder: fh.VolumeBinder(), }, nil diff --git a/pkg/scheduler/framework/plugins/volumerestrictions/volume_restrictions.go b/pkg/scheduler/framework/plugins/volumerestrictions/volume_restrictions.go index 33f57e6e89e..599311c7f95 100644 --- a/pkg/scheduler/framework/plugins/volumerestrictions/volume_restrictions.go +++ b/pkg/scheduler/framework/plugins/volumerestrictions/volume_restrictions.go @@ -129,6 +129,6 @@ func (pl *VolumeRestrictions) Filter(ctx context.Context, _ *framework.CycleStat } // New initializes a new plugin and returns it. -func New(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) { +func New(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) { return &VolumeRestrictions{}, nil } diff --git a/pkg/scheduler/framework/plugins/volumezone/volume_zone.go b/pkg/scheduler/framework/plugins/volumezone/volume_zone.go index d7f866ce5b9..972ae34c131 100644 --- a/pkg/scheduler/framework/plugins/volumezone/volume_zone.go +++ b/pkg/scheduler/framework/plugins/volumezone/volume_zone.go @@ -172,7 +172,7 @@ func (pl *VolumeZone) Filter(ctx context.Context, _ *framework.CycleState, pod * } // New initializes a new plugin and returns it. -func New(_ *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plugin, error) { +func New(_ runtime.Object, handle framework.FrameworkHandle) (framework.Plugin, error) { informerFactory := handle.SharedInformerFactory() pvLister := informerFactory.Core().V1().PersistentVolumes().Lister() pvcLister := informerFactory.Core().V1().PersistentVolumeClaims().Lister() diff --git a/pkg/scheduler/framework/v1alpha1/framework.go b/pkg/scheduler/framework/v1alpha1/framework.go index 320860709f5..1160e0711da 100644 --- a/pkg/scheduler/framework/v1alpha1/framework.go +++ b/pkg/scheduler/framework/v1alpha1/framework.go @@ -197,13 +197,13 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi // get needed plugins from config pg := f.pluginsNeeded(plugins) - pluginConfig := make(map[string]*runtime.Unknown, 0) + pluginConfig := make(map[string]runtime.Object, 0) for i := range args { name := args[i].Name if _, ok := pluginConfig[name]; ok { return nil, fmt.Errorf("repeated config for plugin %s", name) } - pluginConfig[name] = &args[i].Args + pluginConfig[name] = args[i].Args } pluginsMap := make(map[string]Plugin) diff --git a/pkg/scheduler/framework/v1alpha1/framework_test.go b/pkg/scheduler/framework/v1alpha1/framework_test.go index 2eb4496d402..2f2002c14f7 100644 --- a/pkg/scheduler/framework/v1alpha1/framework_test.go +++ b/pkg/scheduler/framework/v1alpha1/framework_test.go @@ -53,7 +53,7 @@ const ( var _ ScorePlugin = &TestScoreWithNormalizePlugin{} var _ ScorePlugin = &TestScorePlugin{} -func newScoreWithNormalizePlugin1(injArgs *runtime.Unknown, f FrameworkHandle) (Plugin, error) { +func newScoreWithNormalizePlugin1(injArgs runtime.Object, f FrameworkHandle) (Plugin, error) { var inj injectedResult if err := DecodeInto(injArgs, &inj); err != nil { return nil, err @@ -61,7 +61,7 @@ func newScoreWithNormalizePlugin1(injArgs *runtime.Unknown, f FrameworkHandle) ( return &TestScoreWithNormalizePlugin{scoreWithNormalizePlugin1, inj}, nil } -func newScoreWithNormalizePlugin2(injArgs *runtime.Unknown, f FrameworkHandle) (Plugin, error) { +func newScoreWithNormalizePlugin2(injArgs runtime.Object, f FrameworkHandle) (Plugin, error) { var inj injectedResult if err := DecodeInto(injArgs, &inj); err != nil { return nil, err @@ -69,7 +69,7 @@ func newScoreWithNormalizePlugin2(injArgs *runtime.Unknown, f FrameworkHandle) ( return &TestScoreWithNormalizePlugin{scoreWithNormalizePlugin2, inj}, nil } -func newScorePlugin1(injArgs *runtime.Unknown, f FrameworkHandle) (Plugin, error) { +func newScorePlugin1(injArgs runtime.Object, f FrameworkHandle) (Plugin, error) { var inj injectedResult if err := DecodeInto(injArgs, &inj); err != nil { return nil, err @@ -77,7 +77,7 @@ func newScorePlugin1(injArgs *runtime.Unknown, f FrameworkHandle) (Plugin, error return &TestScorePlugin{scorePlugin1, inj}, nil } -func newPluginNotImplementingScore(_ *runtime.Unknown, _ FrameworkHandle) (Plugin, error) { +func newPluginNotImplementingScore(_ runtime.Object, _ FrameworkHandle) (Plugin, error) { return &PluginNotImplementingScore{}, nil } @@ -259,7 +259,7 @@ func (dp *TestDuplicatePlugin) PreFilterExtensions() PreFilterExtensions { var _ PreFilterPlugin = &TestDuplicatePlugin{} -func newDuplicatePlugin(_ *runtime.Unknown, _ FrameworkHandle) (Plugin, error) { +func newDuplicatePlugin(_ runtime.Object, _ FrameworkHandle) (Plugin, error) { return &TestDuplicatePlugin{}, nil } @@ -277,7 +277,7 @@ func (pp *TestPermitPlugin) Permit(ctx context.Context, state *CycleState, p *v1 var _ QueueSortPlugin = &TestQueueSortPlugin{} -func newQueueSortPlugin(_ *runtime.Unknown, _ FrameworkHandle) (Plugin, error) { +func newQueueSortPlugin(_ runtime.Object, _ FrameworkHandle) (Plugin, error) { return &TestQueueSortPlugin{}, nil } @@ -294,7 +294,7 @@ func (pl *TestQueueSortPlugin) Less(_, _ *PodInfo) bool { var _ BindPlugin = &TestBindPlugin{} -func newBindPlugin(_ *runtime.Unknown, _ FrameworkHandle) (Plugin, error) { +func newBindPlugin(_ runtime.Object, _ FrameworkHandle) (Plugin, error) { return &TestBindPlugin{}, nil } @@ -479,7 +479,7 @@ func TestRunScorePlugins(t *testing.T) { pluginConfigs: []config.PluginConfig{ { Name: scorePlugin1, - Args: runtime.Unknown{ + Args: &runtime.Unknown{ Raw: []byte(`{ "scoreRes": 1 }`), }, }, @@ -496,7 +496,7 @@ func TestRunScorePlugins(t *testing.T) { pluginConfigs: []config.PluginConfig{ { Name: scoreWithNormalizePlugin1, - Args: runtime.Unknown{ + Args: &runtime.Unknown{ Raw: []byte(`{ "scoreRes": 10, "normalizeRes": 5 }`), }, }, @@ -512,19 +512,19 @@ func TestRunScorePlugins(t *testing.T) { pluginConfigs: []config.PluginConfig{ { Name: scorePlugin1, - Args: runtime.Unknown{ + Args: &runtime.Unknown{ Raw: []byte(`{ "scoreRes": 1 }`), }, }, { Name: scoreWithNormalizePlugin1, - Args: runtime.Unknown{ + Args: &runtime.Unknown{ Raw: []byte(`{ "scoreRes": 3, "normalizeRes": 4}`), }, }, { Name: scoreWithNormalizePlugin2, - Args: runtime.Unknown{ + Args: &runtime.Unknown{ Raw: []byte(`{ "scoreRes": 4, "normalizeRes": 5}`), }, }, @@ -543,7 +543,7 @@ func TestRunScorePlugins(t *testing.T) { pluginConfigs: []config.PluginConfig{ { Name: scoreWithNormalizePlugin1, - Args: runtime.Unknown{ + Args: &runtime.Unknown{ Raw: []byte(`{ "scoreStatus": 1 }`), }, }, @@ -556,7 +556,7 @@ func TestRunScorePlugins(t *testing.T) { pluginConfigs: []config.PluginConfig{ { Name: scoreWithNormalizePlugin1, - Args: runtime.Unknown{ + Args: &runtime.Unknown{ Raw: []byte(`{ "normalizeStatus": 1 }`), }, }, @@ -570,7 +570,7 @@ func TestRunScorePlugins(t *testing.T) { pluginConfigs: []config.PluginConfig{ { Name: scorePlugin1, - Args: runtime.Unknown{ + Args: &runtime.Unknown{ Raw: []byte(fmt.Sprintf(`{ "scoreRes": %d }`, MaxNodeScore+1)), }, }, @@ -583,7 +583,7 @@ func TestRunScorePlugins(t *testing.T) { pluginConfigs: []config.PluginConfig{ { Name: scorePlugin1, - Args: runtime.Unknown{ + Args: &runtime.Unknown{ Raw: []byte(fmt.Sprintf(`{ "scoreRes": %d }`, MinNodeScore-1)), }, }, @@ -596,7 +596,7 @@ func TestRunScorePlugins(t *testing.T) { pluginConfigs: []config.PluginConfig{ { Name: scoreWithNormalizePlugin1, - Args: runtime.Unknown{ + Args: &runtime.Unknown{ Raw: []byte(fmt.Sprintf(`{ "normalizeRes": %d }`, MaxNodeScore+1)), }, }, @@ -609,7 +609,7 @@ func TestRunScorePlugins(t *testing.T) { pluginConfigs: []config.PluginConfig{ { Name: scoreWithNormalizePlugin1, - Args: runtime.Unknown{ + Args: &runtime.Unknown{ Raw: []byte(fmt.Sprintf(`{ "normalizeRes": %d }`, MinNodeScore-1)), }, }, @@ -650,11 +650,11 @@ func TestPreFilterPlugins(t *testing.T) { preFilter2 := &TestPreFilterWithExtensionsPlugin{} r := make(Registry) r.Register(preFilterPluginName, - func(_ *runtime.Unknown, fh FrameworkHandle) (Plugin, error) { + func(_ runtime.Object, fh FrameworkHandle) (Plugin, error) { return preFilter1, nil }) r.Register(preFilterWithExtensionsPluginName, - func(_ *runtime.Unknown, fh FrameworkHandle) (Plugin, error) { + func(_ runtime.Object, fh FrameworkHandle) (Plugin, error) { return preFilter2, nil }) plugins := &config.Plugins{PreFilter: &config.PluginSet{Enabled: []config.Plugin{{Name: preFilterWithExtensionsPluginName}, {Name: preFilterPluginName}}}} @@ -874,7 +874,7 @@ func TestFilterPlugins(t *testing.T) { // register all plugins tmpPl := pl if err := registry.Register(pl.name, - func(_ *runtime.Unknown, _ FrameworkHandle) (Plugin, error) { + func(_ runtime.Object, _ FrameworkHandle) (Plugin, error) { return tmpPl, nil }); err != nil { t.Fatalf("fail to register filter plugin (%s)", pl.name) @@ -1032,7 +1032,7 @@ func TestPreBindPlugins(t *testing.T) { for _, pl := range tt.plugins { tmpPl := pl - if err := registry.Register(pl.name, func(_ *runtime.Unknown, _ FrameworkHandle) (Plugin, error) { + if err := registry.Register(pl.name, func(_ runtime.Object, _ FrameworkHandle) (Plugin, error) { return tmpPl, nil }); err != nil { t.Fatalf("Unable to register pre bind plugins: %s", pl.name) @@ -1188,7 +1188,7 @@ func TestReservePlugins(t *testing.T) { for _, pl := range tt.plugins { tmpPl := pl - if err := registry.Register(pl.name, func(_ *runtime.Unknown, _ FrameworkHandle) (Plugin, error) { + if err := registry.Register(pl.name, func(_ runtime.Object, _ FrameworkHandle) (Plugin, error) { return tmpPl, nil }); err != nil { t.Fatalf("Unable to register pre bind plugins: %s", pl.name) @@ -1311,7 +1311,7 @@ func TestPermitPlugins(t *testing.T) { for _, pl := range tt.plugins { tmpPl := pl - if err := registry.Register(pl.name, func(_ *runtime.Unknown, _ FrameworkHandle) (Plugin, error) { + if err := registry.Register(pl.name, func(_ runtime.Object, _ FrameworkHandle) (Plugin, error) { return tmpPl, nil }); err != nil { t.Fatalf("Unable to register Permit plugin: %s", pl.name) @@ -1469,7 +1469,7 @@ func TestRecordingMetrics(t *testing.T) { plugin := &TestPlugin{name: testPlugin, inj: tt.inject} r := make(Registry) r.Register(testPlugin, - func(_ *runtime.Unknown, fh FrameworkHandle) (Plugin, error) { + func(_ runtime.Object, fh FrameworkHandle) (Plugin, error) { return plugin, nil }) pluginSet := &config.PluginSet{Enabled: []config.Plugin{{Name: testPlugin, Weight: 1}}} @@ -1584,7 +1584,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.Unknown, fh FrameworkHandle) (Plugin, error) { + func(_ runtime.Object, fh FrameworkHandle) (Plugin, error) { return plugin, nil }) pluginSet.Enabled = append(pluginSet.Enabled, config.Plugin{Name: name}) @@ -1635,7 +1635,7 @@ func TestPermitWaitDurationMetric(t *testing.T) { plugin := &TestPlugin{name: testPlugin, inj: tt.inject} r := make(Registry) err := r.Register(testPlugin, - func(_ *runtime.Unknown, fh FrameworkHandle) (Plugin, error) { + func(_ runtime.Object, fh FrameworkHandle) (Plugin, error) { return plugin, nil }) if err != nil { @@ -1694,7 +1694,7 @@ func TestWaitOnPermit(t *testing.T) { testPermitPlugin := &TestPermitPlugin{} r := make(Registry) r.Register(permitPlugin, - func(_ *runtime.Unknown, fh FrameworkHandle) (Plugin, error) { + func(_ runtime.Object, fh FrameworkHandle) (Plugin, error) { return testPermitPlugin, nil }) plugins := &config.Plugins{ diff --git a/pkg/scheduler/framework/v1alpha1/registry.go b/pkg/scheduler/framework/v1alpha1/registry.go index 39432f1e6fe..353c97ed867 100644 --- a/pkg/scheduler/framework/v1alpha1/registry.go +++ b/pkg/scheduler/framework/v1alpha1/registry.go @@ -25,11 +25,18 @@ import ( ) // PluginFactory is a function that builds a plugin. -type PluginFactory = func(configuration *runtime.Unknown, f FrameworkHandle) (Plugin, error) +type PluginFactory = func(configuration runtime.Object, f FrameworkHandle) (Plugin, error) // DecodeInto decodes configuration whose type is *runtime.Unknown to the interface into. -func DecodeInto(configuration *runtime.Unknown, into interface{}) error { - if configuration == nil || configuration.Raw == nil { +func DecodeInto(obj runtime.Object, into interface{}) error { + if obj == nil { + return nil + } + configuration, ok := obj.(*runtime.Unknown) + if !ok { + return fmt.Errorf("want args of type runtime.Unknown, got %T", obj) + } + if configuration.Raw == nil { return nil } diff --git a/pkg/scheduler/framework/v1alpha1/registry_test.go b/pkg/scheduler/framework/v1alpha1/registry_test.go index 4bda03221d8..1ab0a2d513d 100644 --- a/pkg/scheduler/framework/v1alpha1/registry_test.go +++ b/pkg/scheduler/framework/v1alpha1/registry_test.go @@ -102,7 +102,7 @@ func (p *mockNoopPlugin) Name() string { } func NewMockNoopPluginFactory() PluginFactory { - return func(_ *runtime.Unknown, _ FrameworkHandle) (Plugin, error) { + return func(_ runtime.Object, _ FrameworkHandle) (Plugin, error) { return &mockNoopPlugin{}, nil } } diff --git a/pkg/scheduler/profile/profile.go b/pkg/scheduler/profile/profile.go index 39f94b9ba19..9555b287302 100644 --- a/pkg/scheduler/profile/profile.go +++ b/pkg/scheduler/profile/profile.go @@ -91,7 +91,7 @@ func NewRecorderFactory(b events.EventBroadcaster) RecorderFactory { type cfgValidator struct { m Map queueSort string - queueSortArgs runtime.Unknown + queueSortArgs runtime.Object } func (v *cfgValidator) validate(cfg config.KubeSchedulerProfile) error { @@ -108,7 +108,7 @@ func (v *cfgValidator) validate(cfg config.KubeSchedulerProfile) error { return fmt.Errorf("one queue sort plugin required for profile with scheduler name %q", cfg.SchedulerName) } queueSort := cfg.Plugins.QueueSort.Enabled[0].Name - var queueSortArgs runtime.Unknown + var queueSortArgs runtime.Object for _, plCfg := range cfg.PluginConfig { if plCfg.Name == queueSort { queueSortArgs = plCfg.Args @@ -123,7 +123,7 @@ func (v *cfgValidator) validate(cfg config.KubeSchedulerProfile) error { return fmt.Errorf("different queue sort plugins for profile %q: %q, first: %q", cfg.SchedulerName, queueSort, v.queueSort) } if !cmp.Equal(v.queueSortArgs, queueSortArgs) { - return fmt.Errorf("different queue sort plugin args for profile %q: %s", cfg.SchedulerName, queueSortArgs.Raw) + return fmt.Errorf("different queue sort plugin args for profile %q", cfg.SchedulerName) } return nil } diff --git a/pkg/scheduler/profile/profile_test.go b/pkg/scheduler/profile/profile_test.go index 2f96a652166..7733e045d4d 100644 --- a/pkg/scheduler/profile/profile_test.go +++ b/pkg/scheduler/profile/profile_test.go @@ -63,7 +63,7 @@ func TestNewProfile(t *testing.T) { PluginConfig: []config.PluginConfig{ { Name: "QueueSort", - Args: runtime.Unknown{Raw: []byte("{}")}, + Args: &runtime.Unknown{Raw: []byte("{}")}, }, }, }, @@ -153,7 +153,7 @@ func TestNewMap(t *testing.T) { PluginConfig: []config.PluginConfig{ { Name: "Bind2", - Args: runtime.Unknown{Raw: []byte("{}")}, + Args: &runtime.Unknown{Raw: []byte("{}")}, }, }, }, @@ -215,7 +215,7 @@ func TestNewMap(t *testing.T) { PluginConfig: []config.PluginConfig{ { Name: "QueueSort", - Args: runtime.Unknown{Raw: []byte("{}")}, + Args: &runtime.Unknown{Raw: []byte("{}")}, }, }, }, @@ -304,7 +304,7 @@ func (p *fakePlugin) Bind(context.Context, *framework.CycleState, *v1.Pod, strin return nil } -func newFakePlugin(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) { +func newFakePlugin(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) { return &fakePlugin{}, nil } diff --git a/pkg/scheduler/scheduler_test.go b/pkg/scheduler/scheduler_test.go index c7aeb56518a..72da25861f6 100644 --- a/pkg/scheduler/scheduler_test.go +++ b/pkg/scheduler/scheduler_test.go @@ -388,7 +388,7 @@ type fakeNodeSelector struct { fakeNodeSelectorArgs } -func newFakeNodeSelector(args *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) { +func newFakeNodeSelector(args runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) { pl := &fakeNodeSelector{} if err := framework.DecodeInto(args, &pl.fakeNodeSelectorArgs); err != nil { return nil, err @@ -455,7 +455,7 @@ func TestSchedulerMultipleProfilesScheduling(t *testing.T) { }}, PluginConfig: []schedulerapi.PluginConfig{ {Name: "FakeNodeSelector", - Args: runtime.Unknown{Raw: []byte(`{"nodeName":"machine2"}`)}, + Args: &runtime.Unknown{Raw: []byte(`{"nodeName":"machine2"}`)}, }, }, }, @@ -468,7 +468,7 @@ func TestSchedulerMultipleProfilesScheduling(t *testing.T) { }}, PluginConfig: []schedulerapi.PluginConfig{ {Name: "FakeNodeSelector", - Args: runtime.Unknown{Raw: []byte(`{"nodeName":"machine3"}`)}, + Args: &runtime.Unknown{Raw: []byte(`{"nodeName":"machine3"}`)}, }, }, }, diff --git a/staging/src/k8s.io/kube-scheduler/config/v1alpha2/types.go b/staging/src/k8s.io/kube-scheduler/config/v1alpha2/types.go index 2474b716ad1..08fa1e01ae4 100644 --- a/staging/src/k8s.io/kube-scheduler/config/v1alpha2/types.go +++ b/staging/src/k8s.io/kube-scheduler/config/v1alpha2/types.go @@ -200,5 +200,5 @@ type PluginConfig struct { // Name defines the name of plugin being configured Name string `json:"name"` // Args defines the arguments passed to the plugins at the time of initialization. Args can have arbitrary structure. - Args runtime.Unknown `json:"args,omitempty"` + Args runtime.RawExtension `json:"args,omitempty"` } diff --git a/test/integration/scheduler/framework_test.go b/test/integration/scheduler/framework_test.go index 63f327a2c9b..cf54a938e87 100644 --- a/test/integration/scheduler/framework_test.go +++ b/test/integration/scheduler/framework_test.go @@ -136,7 +136,7 @@ var _ framework.PermitPlugin = &PermitPlugin{} // newPlugin returns a plugin factory with specified Plugin. func newPlugin(plugin framework.Plugin) framework.PluginFactory { - return func(_ *runtime.Unknown, fh framework.FrameworkHandle) (framework.Plugin, error) { + return func(_ runtime.Object, fh framework.FrameworkHandle) (framework.Plugin, error) { return plugin, nil } } @@ -454,7 +454,7 @@ func (pp *PermitPlugin) reset() { // newPermitPlugin returns a factory for permit plugin with specified PermitPlugin. func newPermitPlugin(permitPlugin *PermitPlugin) framework.PluginFactory { - return func(_ *runtime.Unknown, fh framework.FrameworkHandle) (framework.Plugin, error) { + return func(_ runtime.Object, fh framework.FrameworkHandle) (framework.Plugin, error) { permitPlugin.fh = fh return permitPlugin, nil } @@ -860,16 +860,16 @@ func TestBindPlugin(t *testing.T) { 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{ - unreservePlugin.Name(): func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) { + unreservePlugin.Name(): func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) { return unreservePlugin, nil }, - bindPlugin1.Name(): func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) { + bindPlugin1.Name(): func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) { return bindPlugin1, nil }, - bindPlugin2.Name(): func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) { + bindPlugin2.Name(): func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) { return bindPlugin2, nil }, - postBindPlugin.Name(): func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) { + postBindPlugin.Name(): func(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) { return postBindPlugin, nil }, } diff --git a/test/integration/scheduler/preemption_test.go b/test/integration/scheduler/preemption_test.go index ec544e5cc48..0f3d4ed9406 100644 --- a/test/integration/scheduler/preemption_test.go +++ b/test/integration/scheduler/preemption_test.go @@ -122,7 +122,7 @@ func TestPreemption(t *testing.T) { // Initialize scheduler with a filter plugin. var filter tokenFilter registry := make(framework.Registry) - err := registry.Register(filterPluginName, func(_ *runtime.Unknown, fh framework.FrameworkHandle) (framework.Plugin, error) { + err := registry.Register(filterPluginName, func(_ runtime.Object, fh framework.FrameworkHandle) (framework.Plugin, error) { return &filter, nil }) if err != nil {