mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-07-18 04:54:54 +00:00
Update factory to use generics, keep single New function
This commit is contained in:
@@ -82,13 +82,8 @@ func (pl *DefaultPreemption) Name() string {
|
||||
return Name
|
||||
}
|
||||
|
||||
// New initializes a new plugin and returns it.
|
||||
func New(_ context.Context, dpArgs runtime.Object, fh framework.Handle, fts feature.Features) (framework.Plugin, error) {
|
||||
return NewDefaultPreemption(dpArgs, fh, fts)
|
||||
}
|
||||
|
||||
// NewDefaultPreemption initializes a new plugin and returns it. The plugin type is retained to allow modification.
|
||||
func NewDefaultPreemption(dpArgs runtime.Object, fh framework.Handle, fts feature.Features) (*DefaultPreemption, error) {
|
||||
// New initializes a new plugin and returns it. The plugin type is retained to allow modification.
|
||||
func New(_ context.Context, dpArgs runtime.Object, fh framework.Handle, fts feature.Features) (*DefaultPreemption, error) {
|
||||
args, ok := dpArgs.(*config.DefaultPreemptionArgs)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("got args of type %T, want *DefaultPreemptionArgs", dpArgs)
|
||||
|
||||
@@ -436,7 +436,7 @@ func TestPostFilter(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p, err := NewDefaultPreemption(getDefaultDefaultPreemptionArgs(), f, feature.Features{})
|
||||
p, err := New(ctx, getDefaultDefaultPreemptionArgs(), f, feature.Features{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -1186,7 +1186,7 @@ func TestDryRunPreemption(t *testing.T) {
|
||||
if tt.args == nil {
|
||||
tt.args = getDefaultDefaultPreemptionArgs()
|
||||
}
|
||||
pl, err := NewDefaultPreemption(tt.args, fwk, feature.Features{})
|
||||
pl, err := New(ctx, tt.args, fwk, feature.Features{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -1430,7 +1430,7 @@ func TestSelectBestCandidate(t *testing.T) {
|
||||
t.Errorf("Unexpected PreFilter Status: %v", status)
|
||||
}
|
||||
|
||||
pl, err := NewDefaultPreemption(getDefaultDefaultPreemptionArgs(), fwk, feature.Features{})
|
||||
pl, err := New(ctx, getDefaultDefaultPreemptionArgs(), fwk, feature.Features{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -1693,7 +1693,7 @@ func TestCustomSelection(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
pl, err := NewDefaultPreemption(getDefaultDefaultPreemptionArgs(), fwk, feature.Features{})
|
||||
pl, err := New(ctx, getDefaultDefaultPreemptionArgs(), fwk, feature.Features{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -1809,7 +1809,7 @@ func TestPodEligibleToPreemptOthers(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
pl, err := NewDefaultPreemption(getDefaultDefaultPreemptionArgs(), f, feature.Features{})
|
||||
pl, err := New(ctx, getDefaultDefaultPreemptionArgs(), f, feature.Features{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -2115,7 +2115,7 @@ func TestPreempt(t *testing.T) {
|
||||
features := feature.Features{
|
||||
EnableAsyncPreemption: asyncPreemptionEnabled,
|
||||
}
|
||||
pl, err := NewDefaultPreemption(getDefaultDefaultPreemptionArgs(), fwk, features)
|
||||
pl, err := New(ctx, getDefaultDefaultPreemptionArgs(), fwk, features)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -31,11 +31,11 @@ import (
|
||||
type PluginFactory = func(ctx context.Context, configuration runtime.Object, f framework.Handle) (framework.Plugin, error)
|
||||
|
||||
// PluginFactoryWithFts is a function that builds a plugin with certain feature gates.
|
||||
type PluginFactoryWithFts func(context.Context, runtime.Object, framework.Handle, plfeature.Features) (framework.Plugin, error)
|
||||
type PluginFactoryWithFts[T framework.Plugin] func(context.Context, runtime.Object, framework.Handle, plfeature.Features) (T, 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 {
|
||||
func FactoryAdapter[T framework.Plugin](fts plfeature.Features, withFts PluginFactoryWithFts[T]) PluginFactory {
|
||||
return func(ctx context.Context, plArgs runtime.Object, fh framework.Handle) (framework.Plugin, error) {
|
||||
return withFts(ctx, plArgs, fh, fts)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user