mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
scheduler: avoid repeated boilerplate code when registering plugins
Some plugins expect the new feature gate struct. We can inject that additional parameter via a helper function instead of having to repeat the same anonymous function for each plugin.
This commit is contained in:
parent
047a6b9f86
commit
1d656d46a2
@ -17,10 +17,8 @@ limitations under the License.
|
|||||||
package plugins
|
package plugins
|
||||||
|
|
||||||
import (
|
import (
|
||||||
apiruntime "k8s.io/apimachinery/pkg/runtime"
|
|
||||||
"k8s.io/apiserver/pkg/util/feature"
|
"k8s.io/apiserver/pkg/util/feature"
|
||||||
"k8s.io/kubernetes/pkg/features"
|
"k8s.io/kubernetes/pkg/features"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/framework"
|
|
||||||
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/defaultbinder"
|
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/defaultbinder"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/defaultpreemption"
|
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/defaultpreemption"
|
||||||
plfeature "k8s.io/kubernetes/pkg/scheduler/framework/plugins/feature"
|
plfeature "k8s.io/kubernetes/pkg/scheduler/framework/plugins/feature"
|
||||||
@ -69,42 +67,24 @@ func NewInTreeRegistry() runtime.Registry {
|
|||||||
nodeaffinity.Name: nodeaffinity.New,
|
nodeaffinity.Name: nodeaffinity.New,
|
||||||
podtopologyspread.Name: podtopologyspread.New,
|
podtopologyspread.Name: podtopologyspread.New,
|
||||||
nodeunschedulable.Name: nodeunschedulable.New,
|
nodeunschedulable.Name: nodeunschedulable.New,
|
||||||
noderesources.FitName: func(plArgs apiruntime.Object, fh framework.Handle) (framework.Plugin, error) {
|
noderesources.FitName: runtime.FactoryAdapter(fts, noderesources.NewFit),
|
||||||
return noderesources.NewFit(plArgs, fh, fts)
|
noderesources.BalancedAllocationName: runtime.FactoryAdapter(fts, noderesources.NewBalancedAllocation),
|
||||||
},
|
noderesources.MostAllocatedName: runtime.FactoryAdapter(fts, noderesources.NewMostAllocated),
|
||||||
noderesources.BalancedAllocationName: func(plArgs apiruntime.Object, fh framework.Handle) (framework.Plugin, error) {
|
noderesources.LeastAllocatedName: runtime.FactoryAdapter(fts, noderesources.NewLeastAllocated),
|
||||||
return noderesources.NewBalancedAllocation(plArgs, fh, fts)
|
noderesources.RequestedToCapacityRatioName: runtime.FactoryAdapter(fts, noderesources.NewRequestedToCapacityRatio),
|
||||||
},
|
volumebinding.Name: runtime.FactoryAdapter(fts, volumebinding.New),
|
||||||
noderesources.MostAllocatedName: func(plArgs apiruntime.Object, fh framework.Handle) (framework.Plugin, error) {
|
volumerestrictions.Name: runtime.FactoryAdapter(fts, volumerestrictions.New),
|
||||||
return noderesources.NewMostAllocated(plArgs, fh, fts)
|
|
||||||
},
|
|
||||||
noderesources.LeastAllocatedName: func(plArgs apiruntime.Object, fh framework.Handle) (framework.Plugin, error) {
|
|
||||||
return noderesources.NewLeastAllocated(plArgs, fh, fts)
|
|
||||||
},
|
|
||||||
noderesources.RequestedToCapacityRatioName: func(plArgs apiruntime.Object, fh framework.Handle) (framework.Plugin, error) {
|
|
||||||
return noderesources.NewRequestedToCapacityRatio(plArgs, fh, fts)
|
|
||||||
},
|
|
||||||
volumebinding.Name: func(plArgs apiruntime.Object, fh framework.Handle) (framework.Plugin, error) {
|
|
||||||
return volumebinding.New(plArgs, fh, fts)
|
|
||||||
},
|
|
||||||
volumerestrictions.Name: func(plArgs apiruntime.Object, fh framework.Handle) (framework.Plugin, error) {
|
|
||||||
return volumerestrictions.New(plArgs, fh, fts)
|
|
||||||
},
|
|
||||||
volumezone.Name: volumezone.New,
|
volumezone.Name: volumezone.New,
|
||||||
nodevolumelimits.CSIName: nodevolumelimits.NewCSI,
|
nodevolumelimits.CSIName: nodevolumelimits.NewCSI,
|
||||||
nodevolumelimits.EBSName: nodevolumelimits.NewEBS,
|
nodevolumelimits.EBSName: nodevolumelimits.NewEBS,
|
||||||
nodevolumelimits.GCEPDName: nodevolumelimits.NewGCEPD,
|
nodevolumelimits.GCEPDName: nodevolumelimits.NewGCEPD,
|
||||||
nodevolumelimits.AzureDiskName: nodevolumelimits.NewAzureDisk,
|
nodevolumelimits.AzureDiskName: nodevolumelimits.NewAzureDisk,
|
||||||
nodevolumelimits.CinderName: nodevolumelimits.NewCinder,
|
nodevolumelimits.CinderName: nodevolumelimits.NewCinder,
|
||||||
interpodaffinity.Name: func(plArgs apiruntime.Object, fh framework.Handle) (framework.Plugin, error) {
|
interpodaffinity.Name: runtime.FactoryAdapter(fts, interpodaffinity.New),
|
||||||
return interpodaffinity.New(plArgs, fh, fts)
|
|
||||||
},
|
|
||||||
nodelabel.Name: nodelabel.New,
|
nodelabel.Name: nodelabel.New,
|
||||||
serviceaffinity.Name: serviceaffinity.New,
|
serviceaffinity.Name: serviceaffinity.New,
|
||||||
queuesort.Name: queuesort.New,
|
queuesort.Name: queuesort.New,
|
||||||
defaultbinder.Name: defaultbinder.New,
|
defaultbinder.Name: defaultbinder.New,
|
||||||
defaultpreemption.Name: func(plArgs apiruntime.Object, fh framework.Handle) (framework.Plugin, error) {
|
defaultpreemption.Name: runtime.FactoryAdapter(fts, defaultpreemption.New),
|
||||||
return defaultpreemption.New(plArgs, fh, fts)
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,12 +22,24 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/util/json"
|
"k8s.io/apimachinery/pkg/util/json"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/framework"
|
"k8s.io/kubernetes/pkg/scheduler/framework"
|
||||||
|
plfeature "k8s.io/kubernetes/pkg/scheduler/framework/plugins/feature"
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
// PluginFactory is a function that builds a plugin.
|
// PluginFactory is a function that builds a plugin.
|
||||||
type PluginFactory = func(configuration runtime.Object, f framework.Handle) (framework.Plugin, error)
|
type PluginFactory = func(configuration runtime.Object, f framework.Handle) (framework.Plugin, error)
|
||||||
|
|
||||||
|
// PluginFactoryWithFts is a function that builds a plugin with certain feature gates.
|
||||||
|
type PluginFactoryWithFts func(runtime.Object, framework.Handle, plfeature.Features) (framework.Plugin, error)
|
||||||
|
|
||||||
|
// FactoryAdapter can be used to inject feature gates for a plugin that needs
|
||||||
|
// them when the caller expects the older PluginFactory method.
|
||||||
|
func FactoryAdapter(fts plfeature.Features, withFts PluginFactoryWithFts) PluginFactory {
|
||||||
|
return func(plArgs runtime.Object, fh framework.Handle) (framework.Plugin, error) {
|
||||||
|
return withFts(plArgs, fh, fts)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// DecodeInto decodes configuration whose type is *runtime.Unknown to the interface into.
|
// DecodeInto decodes configuration whose type is *runtime.Unknown to the interface into.
|
||||||
func DecodeInto(obj runtime.Object, into interface{}) error {
|
func DecodeInto(obj runtime.Object, into interface{}) error {
|
||||||
if obj == nil {
|
if obj == nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user