feat: implement "queue-sort" extension point for scheduling framework
This commit is contained in:
@@ -34,6 +34,7 @@ type framework struct {
|
||||
nodeInfoSnapshot *cache.NodeInfoSnapshot
|
||||
waitingPods *waitingPodsMap
|
||||
plugins map[string]Plugin // a map of initialized plugins. Plugin name:plugin instance.
|
||||
queueSortPlugins []QueueSortPlugin
|
||||
reservePlugins []ReservePlugin
|
||||
prebindPlugins []PrebindPlugin
|
||||
unreservePlugins []UnreservePlugin
|
||||
@@ -69,6 +70,10 @@ func NewFramework(r Registry, _ *runtime.Unknown) (Framework, error) {
|
||||
// TODO: For now, we assume any plugins that implements an extension
|
||||
// point wants to be called at that extension point. We should change this
|
||||
// later and add these plugins based on the configuration.
|
||||
if qsp, ok := p.(QueueSortPlugin); ok {
|
||||
f.queueSortPlugins = append(f.queueSortPlugins, qsp)
|
||||
}
|
||||
|
||||
if rp, ok := p.(ReservePlugin); ok {
|
||||
f.reservePlugins = append(f.reservePlugins, rp)
|
||||
}
|
||||
@@ -85,6 +90,16 @@ func NewFramework(r Registry, _ *runtime.Unknown) (Framework, error) {
|
||||
return f, nil
|
||||
}
|
||||
|
||||
// QueueSortFunc returns the function to sort pods in scheduling queue
|
||||
func (f *framework) QueueSortFunc() LessFunc {
|
||||
if len(f.queueSortPlugins) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Only one QueueSort plugin can be enabled.
|
||||
return f.queueSortPlugins[0].Less
|
||||
}
|
||||
|
||||
// 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.
|
||||
|
@@ -107,6 +107,25 @@ type Plugin interface {
|
||||
Name() string
|
||||
}
|
||||
|
||||
// PodInfo is minimum cell in the scheduling queue.
|
||||
type PodInfo struct {
|
||||
Pod *v1.Pod
|
||||
// The time pod added to the scheduling queue.
|
||||
Timestamp time.Time
|
||||
}
|
||||
|
||||
// LessFunc is the function to sort pod info
|
||||
type LessFunc func(podInfo1, podInfo2 *PodInfo) bool
|
||||
|
||||
// QueueSortPlugin is an interface that must be implemented by "QueueSort" plugins.
|
||||
// These plugins are used to sort pods in the scheduling queue. Only one queue sort
|
||||
// plugin may be enabled at a time.
|
||||
type QueueSortPlugin interface {
|
||||
Plugin
|
||||
// Less are used to sort pods in the scheduling queue.
|
||||
Less(*PodInfo, *PodInfo) bool
|
||||
}
|
||||
|
||||
// ReservePlugin is an interface for Reserve plugins. These plugins are called
|
||||
// at the reservation point. These are meant to update the state of the plugin.
|
||||
// This concept used to be called 'assume' in the original scheduler.
|
||||
@@ -157,6 +176,9 @@ type PermitPlugin interface {
|
||||
// Configured plugins are called at specified points in a scheduling context.
|
||||
type Framework interface {
|
||||
FrameworkHandle
|
||||
// QueueSortFunc returns the function to sort pods in scheduling queue
|
||||
QueueSortFunc() LessFunc
|
||||
|
||||
// RunPrebindPlugins runs the set of configured prebind plugins. It returns
|
||||
// *Status and its code is set to non-success if any of the plugins returns
|
||||
// anything but Success. If the Status code is "Unschedulable", it is
|
||||
|
Reference in New Issue
Block a user