mirror of
https://github.com/kubernetes-sigs/descheduler.git
synced 2026-01-25 20:59:28 +01:00
refactor(pkg/framework/profile): build a profile through a shared function to reduce code duplication
This commit is contained in:
@@ -27,6 +27,46 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestProfileDescheduleBalanceExtensionPointsEviction(t *testing.T) {
|
func TestProfileDescheduleBalanceExtensionPointsEviction(t *testing.T) {
|
||||||
|
// Helper to build profile config with default Filter and PreEvictionFilter
|
||||||
|
buildProfileConfig := func(name string, descheduleEnabled, balanceEnabled bool) api.DeschedulerProfile {
|
||||||
|
config := api.DeschedulerProfile{
|
||||||
|
Name: name,
|
||||||
|
PluginConfigs: []api.PluginConfig{
|
||||||
|
{
|
||||||
|
Name: defaultevictor.PluginName,
|
||||||
|
Args: &defaultevictor.DefaultEvictorArgs{
|
||||||
|
PriorityThreshold: &api.PriorityThreshold{
|
||||||
|
Value: nil,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "FakePlugin",
|
||||||
|
Args: &fakeplugin.FakePluginArgs{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Plugins: api.Plugins{
|
||||||
|
Filter: api.PluginSet{
|
||||||
|
Enabled: []string{defaultevictor.PluginName},
|
||||||
|
},
|
||||||
|
PreEvictionFilter: api.PluginSet{
|
||||||
|
Enabled: []string{defaultevictor.PluginName},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if descheduleEnabled {
|
||||||
|
config.Plugins.Deschedule = api.PluginSet{
|
||||||
|
Enabled: []string{"FakePlugin"},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if balanceEnabled {
|
||||||
|
config.Plugins.Balance = api.PluginSet{
|
||||||
|
Enabled: []string{"FakePlugin"},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return config
|
||||||
|
}
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
config api.DeschedulerProfile
|
config api.DeschedulerProfile
|
||||||
@@ -34,134 +74,26 @@ func TestProfileDescheduleBalanceExtensionPointsEviction(t *testing.T) {
|
|||||||
expectedEviction bool
|
expectedEviction bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "profile with deschedule extension point enabled single eviction",
|
name: "profile with deschedule extension point enabled single eviction",
|
||||||
config: api.DeschedulerProfile{
|
config: buildProfileConfig("strategy-test-profile-with-deschedule", true, false),
|
||||||
Name: "strategy-test-profile-with-deschedule",
|
|
||||||
PluginConfigs: []api.PluginConfig{
|
|
||||||
{
|
|
||||||
Name: defaultevictor.PluginName,
|
|
||||||
Args: &defaultevictor.DefaultEvictorArgs{
|
|
||||||
PriorityThreshold: &api.PriorityThreshold{
|
|
||||||
Value: nil,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "FakePlugin",
|
|
||||||
Args: &fakeplugin.FakePluginArgs{},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Plugins: api.Plugins{
|
|
||||||
Deschedule: api.PluginSet{
|
|
||||||
Enabled: []string{"FakePlugin"},
|
|
||||||
},
|
|
||||||
Filter: api.PluginSet{
|
|
||||||
Enabled: []string{defaultevictor.PluginName},
|
|
||||||
},
|
|
||||||
PreEvictionFilter: api.PluginSet{
|
|
||||||
Enabled: []string{defaultevictor.PluginName},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
extensionPoint: frameworktypes.DescheduleExtensionPoint,
|
extensionPoint: frameworktypes.DescheduleExtensionPoint,
|
||||||
expectedEviction: true,
|
expectedEviction: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "profile with balance extension point enabled single eviction",
|
name: "profile with balance extension point enabled single eviction",
|
||||||
config: api.DeschedulerProfile{
|
config: buildProfileConfig("strategy-test-profile-with-balance", false, true),
|
||||||
Name: "strategy-test-profile-with-balance",
|
|
||||||
PluginConfigs: []api.PluginConfig{
|
|
||||||
{
|
|
||||||
Name: defaultevictor.PluginName,
|
|
||||||
Args: &defaultevictor.DefaultEvictorArgs{
|
|
||||||
PriorityThreshold: &api.PriorityThreshold{
|
|
||||||
Value: nil,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "FakePlugin",
|
|
||||||
Args: &fakeplugin.FakePluginArgs{},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Plugins: api.Plugins{
|
|
||||||
Balance: api.PluginSet{
|
|
||||||
Enabled: []string{"FakePlugin"},
|
|
||||||
},
|
|
||||||
Filter: api.PluginSet{
|
|
||||||
Enabled: []string{defaultevictor.PluginName},
|
|
||||||
},
|
|
||||||
PreEvictionFilter: api.PluginSet{
|
|
||||||
Enabled: []string{defaultevictor.PluginName},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
extensionPoint: frameworktypes.BalanceExtensionPoint,
|
extensionPoint: frameworktypes.BalanceExtensionPoint,
|
||||||
expectedEviction: true,
|
expectedEviction: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "profile with deschedule extension point balance enabled no eviction",
|
name: "profile with deschedule extension point balance enabled no eviction",
|
||||||
config: api.DeschedulerProfile{
|
config: buildProfileConfig("strategy-test-profile-with-balance", false, true),
|
||||||
Name: "strategy-test-profile-with-deschedule",
|
|
||||||
PluginConfigs: []api.PluginConfig{
|
|
||||||
{
|
|
||||||
Name: defaultevictor.PluginName,
|
|
||||||
Args: &defaultevictor.DefaultEvictorArgs{
|
|
||||||
PriorityThreshold: &api.PriorityThreshold{
|
|
||||||
Value: nil,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "FakePlugin",
|
|
||||||
Args: &fakeplugin.FakePluginArgs{},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Plugins: api.Plugins{
|
|
||||||
Balance: api.PluginSet{
|
|
||||||
Enabled: []string{"FakePlugin"},
|
|
||||||
},
|
|
||||||
Filter: api.PluginSet{
|
|
||||||
Enabled: []string{defaultevictor.PluginName},
|
|
||||||
},
|
|
||||||
PreEvictionFilter: api.PluginSet{
|
|
||||||
Enabled: []string{defaultevictor.PluginName},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
extensionPoint: frameworktypes.DescheduleExtensionPoint,
|
extensionPoint: frameworktypes.DescheduleExtensionPoint,
|
||||||
expectedEviction: false,
|
expectedEviction: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "profile with balance extension point deschedule enabled no eviction",
|
name: "profile with balance extension point deschedule enabled no eviction",
|
||||||
config: api.DeschedulerProfile{
|
config: buildProfileConfig("strategy-test-profile-with-deschedule", true, false),
|
||||||
Name: "strategy-test-profile-with-deschedule",
|
|
||||||
PluginConfigs: []api.PluginConfig{
|
|
||||||
{
|
|
||||||
Name: defaultevictor.PluginName,
|
|
||||||
Args: &defaultevictor.DefaultEvictorArgs{
|
|
||||||
PriorityThreshold: &api.PriorityThreshold{
|
|
||||||
Value: nil,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "FakePlugin",
|
|
||||||
Args: &fakeplugin.FakePluginArgs{},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Plugins: api.Plugins{
|
|
||||||
Deschedule: api.PluginSet{
|
|
||||||
Enabled: []string{"FakePlugin"},
|
|
||||||
},
|
|
||||||
Filter: api.PluginSet{
|
|
||||||
Enabled: []string{defaultevictor.PluginName},
|
|
||||||
},
|
|
||||||
PreEvictionFilter: api.PluginSet{
|
|
||||||
Enabled: []string{defaultevictor.PluginName},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
extensionPoint: frameworktypes.BalanceExtensionPoint,
|
extensionPoint: frameworktypes.BalanceExtensionPoint,
|
||||||
expectedEviction: false,
|
expectedEviction: false,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user