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

Extend plugin's New with a context.Context

The new context.Context can be later used for passing a contextualized
logger. Or, other initialization steps that require the context.
This commit is contained in:
Jan Chaloupka
2025-05-19 11:58:22 +02:00
parent d34848086c
commit 1974c12e0f
30 changed files with 47 additions and 34 deletions

View File

@@ -66,7 +66,7 @@ func HaveEvictAnnotation(pod *v1.Pod) bool {
// New builds plugin from its arguments while passing a handle
// nolint: gocyclo
func New(args runtime.Object, handle frameworktypes.Handle) (frameworktypes.Plugin, error) {
func New(ctx context.Context, args runtime.Object, handle frameworktypes.Handle) (frameworktypes.Plugin, error) {
defaultEvictorArgs, ok := args.(*DefaultEvictorArgs)
if !ok {
return nil, fmt.Errorf("want args to be of type defaultEvictorFilterArgs, got %T", args)

View File

@@ -858,7 +858,7 @@ func TestReinitialization(t *testing.T) {
if !ok {
t.Fatalf("Unable to initialize as a DefaultEvictor plugin")
}
_, err = New(defaultEvictor.args, defaultEvictor.handle)
_, err = New(ctx, defaultEvictor.args, defaultEvictor.handle)
if err != nil {
t.Fatalf("Unable to reinitialize the plugin: %v", err)
}
@@ -907,6 +907,7 @@ func initializePlugin(ctx context.Context, test testCase) (frameworktypes.Plugin
}
evictorPlugin, err := New(
ctx,
defaultEvictorArgs,
&frameworkfake.HandleImpl{
ClientsetImpl: fakeClient,