1
0
mirror of https://github.com/kubernetes-sigs/descheduler.git synced 2026-01-26 13:29:11 +01:00

Detect individual extension points from plugin types

- Populate extension points automatically from plugin types
- Make a list of enabled extension points based on a profile
  configuration
- Populate filter and pre-eviction filter handles from their
  corresponding extension points
This commit is contained in:
Jan Chaloupka
2023-03-30 10:56:19 +02:00
parent 3897ff069f
commit 3510aba01d
6 changed files with 901 additions and 72 deletions

View File

@@ -24,6 +24,8 @@ type Action interface {
DeepCopy() Action
}
type ReactionFunc func(action Action) (handled, filter bool, err error)
// Reactor is an interface to allow the composition of reaction functions.
type Reactor interface {
// Handles indicates whether or not this Reactor deals with a given
@@ -31,7 +33,8 @@ type Reactor interface {
Handles(action Action) bool
// React handles the action. It may choose to
// delegate by indicated handled=false.
React(action Action) (handled bool, err error)
// filter is used to store results of filter based actions
React(action Action) (handled, filter bool, err error)
}
// SimpleReactor is a Reactor. Each reaction function is attached to a given extensionPoint. "*" in either field matches everything for that value.
@@ -44,12 +47,10 @@ func (r *SimpleReactor) Handles(action Action) bool {
return r.ExtensionPoint == "*" || r.ExtensionPoint == action.GetExtensionPoint()
}
func (r *SimpleReactor) React(action Action) (bool, error) {
func (r *SimpleReactor) React(action Action) (bool, bool, error) {
return r.Reaction(action)
}
type ReactionFunc func(action Action) (handled bool, err error)
type DescheduleAction interface {
Action
CanDeschedule() bool
@@ -62,6 +63,16 @@ type BalanceAction interface {
Nodes() []*v1.Node
}
type FilterAction interface {
Action
CanFilter() bool
}
type PreEvictionFilterAction interface {
Action
CanPreEvictionFilter() bool
}
type ActionImpl struct {
handle frameworktypes.Handle
extensionPoint string
@@ -130,6 +141,30 @@ func (a BalanceActionImpl) DeepCopy() Action {
}
}
func (c *FakePlugin) AddReactor(extensionPoint string, reaction ReactionFunc) {
c.ReactionChain = append(c.ReactionChain, &SimpleReactor{ExtensionPoint: extensionPoint, Reaction: reaction})
type FilterActionImpl struct {
ActionImpl
}
func (d FilterActionImpl) CanFilter() bool {
return true
}
func (a FilterActionImpl) DeepCopy() Action {
return FilterActionImpl{
ActionImpl: a.ActionImpl.DeepCopy().(ActionImpl),
}
}
type PreEvictionFilterActionImpl struct {
ActionImpl
}
func (d PreEvictionFilterActionImpl) CanPreEvictionFilter() bool {
return true
}
func (a PreEvictionFilterActionImpl) DeepCopy() Action {
return PreEvictionFilterActionImpl{
ActionImpl: a.ActionImpl.DeepCopy().(ActionImpl),
}
}