Change the scheduler plugins PluginFactory function to use context parameter to pass logger

- Migrated pkg/scheduler/framework/plugins/nodevolumelimits to use contextual logging
- Fix golangci-lint validation failed
- Check for plugins creation err
This commit is contained in:
Mengjiao Liu
2023-09-06 11:55:33 +08:00
parent f9f00da6bc
commit a7466f44e0
53 changed files with 287 additions and 218 deletions

View File

@@ -67,6 +67,6 @@ func Fits(pod *v1.Pod, nodeInfo *framework.NodeInfo) bool {
}
// New initializes a new plugin and returns it.
func New(_ runtime.Object, _ framework.Handle) (framework.Plugin, error) {
func New(_ context.Context, _ runtime.Object, _ framework.Handle) (framework.Plugin, error) {
return &NodeName{}, nil
}

View File

@@ -17,13 +17,13 @@ limitations under the License.
package nodename
import (
"context"
"reflect"
"testing"
v1 "k8s.io/api/core/v1"
"k8s.io/kubernetes/pkg/scheduler/framework"
st "k8s.io/kubernetes/pkg/scheduler/testing"
"k8s.io/kubernetes/test/utils/ktesting"
)
func TestNodeName(t *testing.T) {
@@ -55,9 +55,12 @@ func TestNodeName(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
nodeInfo := framework.NewNodeInfo()
nodeInfo.SetNode(test.node)
p, _ := New(nil, nil)
gotStatus := p.(framework.FilterPlugin).Filter(context.Background(), nil, test.pod, nodeInfo)
_, ctx := ktesting.NewTestContext(t)
p, err := New(ctx, nil, nil)
if err != nil {
t.Fatalf("creating plugin: %v", err)
}
gotStatus := p.(framework.FilterPlugin).Filter(ctx, nil, test.pod, nodeInfo)
if !reflect.DeepEqual(gotStatus, test.wantStatus) {
t.Errorf("status does not match: %v, want: %v", gotStatus, test.wantStatus)
}