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

Move framework types under framework/types

This commit is contained in:
Jan Chaloupka
2023-03-23 19:00:55 +01:00
parent bcc6c8eb2a
commit 757661110a
36 changed files with 191 additions and 191 deletions

View File

@@ -22,9 +22,9 @@ import (
"sigs.k8s.io/descheduler/pkg/api"
"sigs.k8s.io/descheduler/pkg/descheduler/evictions"
podutil "sigs.k8s.io/descheduler/pkg/descheduler/pod"
"sigs.k8s.io/descheduler/pkg/framework"
"sigs.k8s.io/descheduler/pkg/framework/pluginregistry"
"sigs.k8s.io/descheduler/pkg/framework/plugins/defaultevictor"
frameworktypes "sigs.k8s.io/descheduler/pkg/framework/types"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/errors"
@@ -38,10 +38,10 @@ import (
// can evict a pod without importing a specific pod evictor
type evictorImpl struct {
podEvictor *evictions.PodEvictor
evictorFilter framework.EvictorPlugin
evictorFilter frameworktypes.EvictorPlugin
}
var _ framework.Evictor = &evictorImpl{}
var _ frameworktypes.Evictor = &evictorImpl{}
// Filter checks if a pod can be evicted
func (ei *evictorImpl) Filter(pod *v1.Pod) bool {
@@ -70,7 +70,7 @@ type handleImpl struct {
evictor *evictorImpl
}
var _ framework.Handle = &handleImpl{}
var _ frameworktypes.Handle = &handleImpl{}
// ClientSet retrieves kube client set
func (hi *handleImpl) ClientSet() clientset.Interface {
@@ -88,7 +88,7 @@ func (hi *handleImpl) SharedInformerFactory() informers.SharedInformerFactory {
}
// Evictor retrieves evictor so plugins can filter and evict pods
func (hi *handleImpl) Evictor() framework.Evictor {
func (hi *handleImpl) Evictor() frameworktypes.Evictor {
return hi.evictor
}
@@ -96,8 +96,8 @@ type profileImpl struct {
profileName string
podEvictor *evictions.PodEvictor
deschedulePlugins []framework.DeschedulePlugin
balancePlugins []framework.BalancePlugin
deschedulePlugins []frameworktypes.DeschedulePlugin
balancePlugins []frameworktypes.BalancePlugin
}
// Option for the handleImpl.
@@ -144,7 +144,7 @@ func getPluginConfig(pluginName string, pluginConfigs []api.PluginConfig) (*api.
return nil, 0
}
func buildPlugin(config api.DeschedulerProfile, pluginName string, handle *handleImpl, reg pluginregistry.Registry) (framework.Plugin, error) {
func buildPlugin(config api.DeschedulerProfile, pluginName string, handle *handleImpl, reg pluginregistry.Registry) (frameworktypes.Plugin, error) {
pc, _ := getPluginConfig(pluginName, config.PluginConfigs)
if pc == nil {
klog.ErrorS(fmt.Errorf("unable to get plugin config"), "skipping plugin", "plugin", pluginName, "profile", config.Name)
@@ -200,12 +200,12 @@ func NewProfile(config api.DeschedulerProfile, reg pluginregistry.Registry, opts
sharedInformerFactory: hOpts.sharedInformerFactory,
evictor: &evictorImpl{
podEvictor: hOpts.podEvictor,
evictorFilter: evictorPlugin.(framework.EvictorPlugin),
evictorFilter: evictorPlugin.(frameworktypes.EvictorPlugin),
},
}
deschedulePlugins := []framework.DeschedulePlugin{}
balancePlugins := []framework.BalancePlugin{}
deschedulePlugins := []frameworktypes.DeschedulePlugin{}
balancePlugins := []frameworktypes.BalancePlugin{}
descheduleEnabled := make(map[string]struct{})
balanceEnabled := make(map[string]struct{})
@@ -228,16 +228,16 @@ func NewProfile(config api.DeschedulerProfile, reg pluginregistry.Registry, opts
// pg can be of any of each type, or both
if _, exists := descheduleEnabled[plugin]; exists {
_, ok := pg.(framework.DeschedulePlugin)
_, ok := pg.(frameworktypes.DeschedulePlugin)
if ok {
deschedulePlugins = append(deschedulePlugins, pg.(framework.DeschedulePlugin))
deschedulePlugins = append(deschedulePlugins, pg.(frameworktypes.DeschedulePlugin))
}
}
if _, exists := balanceEnabled[plugin]; exists {
_, ok := pg.(framework.BalancePlugin)
_, ok := pg.(frameworktypes.BalancePlugin)
if ok {
balancePlugins = append(balancePlugins, pg.(framework.BalancePlugin))
balancePlugins = append(balancePlugins, pg.(frameworktypes.BalancePlugin))
}
}
}
@@ -251,7 +251,7 @@ func NewProfile(config api.DeschedulerProfile, reg pluginregistry.Registry, opts
}, nil
}
func (d profileImpl) RunDeschedulePlugins(ctx context.Context, nodes []*v1.Node) *framework.Status {
func (d profileImpl) RunDeschedulePlugins(ctx context.Context, nodes []*v1.Node) *frameworktypes.Status {
errs := []error{}
for _, pl := range d.deschedulePlugins {
evicted := d.podEvictor.TotalEvicted()
@@ -272,15 +272,15 @@ func (d profileImpl) RunDeschedulePlugins(ctx context.Context, nodes []*v1.Node)
aggrErr := errors.NewAggregate(errs)
if aggrErr == nil {
return &framework.Status{}
return &frameworktypes.Status{}
}
return &framework.Status{
return &frameworktypes.Status{
Err: fmt.Errorf("%v", aggrErr.Error()),
}
}
func (d profileImpl) RunBalancePlugins(ctx context.Context, nodes []*v1.Node) *framework.Status {
func (d profileImpl) RunBalancePlugins(ctx context.Context, nodes []*v1.Node) *frameworktypes.Status {
errs := []error{}
for _, pl := range d.balancePlugins {
evicted := d.podEvictor.TotalEvicted()
@@ -301,10 +301,10 @@ func (d profileImpl) RunBalancePlugins(ctx context.Context, nodes []*v1.Node) *f
aggrErr := errors.NewAggregate(errs)
if aggrErr == nil {
return &framework.Status{}
return &frameworktypes.Status{}
}
return &framework.Status{
return &frameworktypes.Status{
Err: fmt.Errorf("%v", aggrErr.Error()),
}
}

View File

@@ -16,10 +16,10 @@ import (
"sigs.k8s.io/descheduler/pkg/api"
"sigs.k8s.io/descheduler/pkg/descheduler/evictions"
podutil "sigs.k8s.io/descheduler/pkg/descheduler/pod"
"sigs.k8s.io/descheduler/pkg/framework"
fakeplugin "sigs.k8s.io/descheduler/pkg/framework/fake/plugin"
"sigs.k8s.io/descheduler/pkg/framework/pluginregistry"
"sigs.k8s.io/descheduler/pkg/framework/plugins/defaultevictor"
frameworktypes "sigs.k8s.io/descheduler/pkg/framework/types"
"sigs.k8s.io/descheduler/pkg/utils"
testutils "sigs.k8s.io/descheduler/test"
)
@@ -28,7 +28,7 @@ func TestProfileTopExtensionPoints(t *testing.T) {
tests := []struct {
name string
config api.DeschedulerProfile
extensionPoint framework.ExtensionPoint
extensionPoint frameworktypes.ExtensionPoint
expectedEviction bool
}{
{
@@ -58,7 +58,7 @@ func TestProfileTopExtensionPoints(t *testing.T) {
},
},
},
extensionPoint: framework.DescheduleExtensionPoint,
extensionPoint: frameworktypes.DescheduleExtensionPoint,
expectedEviction: true,
},
{
@@ -88,7 +88,7 @@ func TestProfileTopExtensionPoints(t *testing.T) {
},
},
},
extensionPoint: framework.BalanceExtensionPoint,
extensionPoint: frameworktypes.BalanceExtensionPoint,
expectedEviction: true,
},
{
@@ -118,7 +118,7 @@ func TestProfileTopExtensionPoints(t *testing.T) {
},
},
},
extensionPoint: framework.DescheduleExtensionPoint,
extensionPoint: frameworktypes.DescheduleExtensionPoint,
expectedEviction: false,
},
{
@@ -148,7 +148,7 @@ func TestProfileTopExtensionPoints(t *testing.T) {
},
},
},
extensionPoint: framework.BalanceExtensionPoint,
extensionPoint: frameworktypes.BalanceExtensionPoint,
expectedEviction: false,
},
}
@@ -166,8 +166,8 @@ func TestProfileTopExtensionPoints(t *testing.T) {
p1.ObjectMeta.OwnerReferences = []metav1.OwnerReference{{}}
fakePlugin := fakeplugin.FakePlugin{}
if test.extensionPoint == framework.DescheduleExtensionPoint {
fakePlugin.AddReactor(string(framework.DescheduleExtensionPoint), func(action fakeplugin.Action) (handled bool, err error) {
if test.extensionPoint == frameworktypes.DescheduleExtensionPoint {
fakePlugin.AddReactor(string(frameworktypes.DescheduleExtensionPoint), func(action fakeplugin.Action) (handled bool, err error) {
if dAction, ok := action.(fakeplugin.DescheduleAction); ok {
if dAction.Handle().Evictor().Evict(ctx, p1, evictions.EvictOptions{}) {
return true, nil
@@ -177,8 +177,8 @@ func TestProfileTopExtensionPoints(t *testing.T) {
return false, nil
})
}
if test.extensionPoint == framework.BalanceExtensionPoint {
fakePlugin.AddReactor(string(framework.BalanceExtensionPoint), func(action fakeplugin.Action) (handled bool, err error) {
if test.extensionPoint == frameworktypes.BalanceExtensionPoint {
fakePlugin.AddReactor(string(frameworktypes.BalanceExtensionPoint), func(action fakeplugin.Action) (handled bool, err error) {
if dAction, ok := action.(fakeplugin.BalanceAction); ok {
if dAction.Handle().Evictor().Evict(ctx, p1, evictions.EvictOptions{}) {
return true, nil
@@ -240,11 +240,11 @@ func TestProfileTopExtensionPoints(t *testing.T) {
t.Fatalf("unable to create %q profile: %v", test.config.Name, err)
}
var status *framework.Status
var status *frameworktypes.Status
switch test.extensionPoint {
case framework.DescheduleExtensionPoint:
case frameworktypes.DescheduleExtensionPoint:
status = prfl.RunDeschedulePlugins(ctx, nodes)
case framework.BalanceExtensionPoint:
case frameworktypes.BalanceExtensionPoint:
status = prfl.RunBalancePlugins(ctx, nodes)
default:
t.Fatalf("unknown %q extension point", test.extensionPoint)