Merge pull request #88189 from skilxn-go/RemovePreScoreNodeListArguments

[Scheduler Framework]Remove `FilteredNodesStatuses` argument from `PreScore`'s interface
This commit is contained in:
Kubernetes Prow Robot 2020-02-15 13:29:28 -08:00 committed by GitHub
commit 3b22fcc7bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 31 additions and 37 deletions

View File

@ -203,7 +203,7 @@ func (g *genericScheduler) Schedule(ctx context.Context, state *framework.CycleS
} }
// Run "prescore" plugins. // Run "prescore" plugins.
prescoreStatus := g.framework.RunPreScorePlugins(ctx, state, pod, filteredNodes, filteredNodesStatuses) prescoreStatus := g.framework.RunPreScorePlugins(ctx, state, pod, filteredNodes)
if !prescoreStatus.IsSuccess() { if !prescoreStatus.IsSuccess() {
return result, prescoreStatus.AsError() return result, prescoreStatus.AsError()
} }

View File

@ -1144,11 +1144,11 @@ func TestZeroRequest(t *testing.T) {
ctx := context.Background() ctx := context.Background()
state := framework.NewCycleState() state := framework.NewCycleState()
_, filteredNodesStatuses, err := scheduler.findNodesThatFitPod(ctx, state, test.pod) _, _, err = scheduler.findNodesThatFitPod(ctx, state, test.pod)
if err != nil { if err != nil {
t.Fatalf("error filtering nodes: %+v", err) t.Fatalf("error filtering nodes: %+v", err)
} }
scheduler.framework.RunPreScorePlugins(ctx, state, test.pod, test.nodes, filteredNodesStatuses) scheduler.framework.RunPreScorePlugins(ctx, state, test.pod, test.nodes)
list, err := scheduler.prioritizeNodes( list, err := scheduler.prioritizeNodes(
ctx, ctx,
state, state,

View File

@ -19,6 +19,7 @@ package defaultpodtopologyspread
import ( import (
"context" "context"
"fmt" "fmt"
"k8s.io/klog" "k8s.io/klog"
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
@ -178,7 +179,7 @@ func (pl *DefaultPodTopologySpread) ScoreExtensions() framework.ScoreExtensions
} }
// PreScore builds and writes cycle state used by Score and NormalizeScore. // PreScore builds and writes cycle state used by Score and NormalizeScore.
func (pl *DefaultPodTopologySpread) PreScore(ctx context.Context, cycleState *framework.CycleState, pod *v1.Pod, nodes []*v1.Node, _ framework.NodeToStatusMap) *framework.Status { func (pl *DefaultPodTopologySpread) PreScore(ctx context.Context, cycleState *framework.CycleState, pod *v1.Pod, nodes []*v1.Node) *framework.Status {
var selector labels.Selector var selector labels.Selector
informerFactory := pl.handle.SharedInformerFactory() informerFactory := pl.handle.SharedInformerFactory()
selector = getSelector( selector = getSelector(

View File

@ -73,7 +73,7 @@ func BenchmarkTestSelectorSpreadPriority(b *testing.B) {
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
state := framework.NewCycleState() state := framework.NewCycleState()
status := plugin.PreScore(ctx, state, pod, allNodes, nil) status := plugin.PreScore(ctx, state, pod, allNodes)
if !status.IsSuccess() { if !status.IsSuccess() {
b.Fatalf("unexpected error: %v", status) b.Fatalf("unexpected error: %v", status)
} }

View File

@ -386,7 +386,7 @@ func TestDefaultPodTopologySpreadScore(t *testing.T) {
handle: fh, handle: fh,
} }
status := plugin.PreScore(ctx, state, test.pod, nodes, nil) status := plugin.PreScore(ctx, state, test.pod, nodes)
if !status.IsSuccess() { if !status.IsSuccess() {
t.Fatalf("unexpected error: %v", status) t.Fatalf("unexpected error: %v", status)
} }
@ -638,7 +638,7 @@ func TestZoneSelectorSpreadPriority(t *testing.T) {
} }
state := framework.NewCycleState() state := framework.NewCycleState()
status := plugin.PreScore(ctx, state, test.pod, nodes, nil) status := plugin.PreScore(ctx, state, test.pod, nodes)
if !status.IsSuccess() { if !status.IsSuccess() {
t.Fatalf("unexpected error: %v", status) t.Fatalf("unexpected error: %v", status)
} }

View File

@ -20,7 +20,7 @@ import (
"context" "context"
"fmt" "fmt"
"k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/util/workqueue" "k8s.io/client-go/util/workqueue"
"k8s.io/klog" "k8s.io/klog"
@ -172,7 +172,6 @@ func (pl *InterPodAffinity) PreScore(
cycleState *framework.CycleState, cycleState *framework.CycleState,
pod *v1.Pod, pod *v1.Pod,
nodes []*v1.Node, nodes []*v1.Node,
_ framework.NodeToStatusMap,
) *framework.Status { ) *framework.Status {
if len(nodes) == 0 { if len(nodes) == 0 {
// No nodes to score. // No nodes to score.

View File

@ -523,7 +523,7 @@ func TestPreferredAffinity(t *testing.T) {
hardPodAffinityWeight: 1, hardPodAffinityWeight: 1,
} }
status := p.PreScore(context.Background(), state, test.pod, test.nodes, nil) status := p.PreScore(context.Background(), state, test.pod, test.nodes)
if !status.IsSuccess() { if !status.IsSuccess() {
t.Errorf("unexpected error: %v", status) t.Errorf("unexpected error: %v", status)
} }
@ -631,7 +631,7 @@ func TestPreferredAffinityWithHardPodAffinitySymmetricWeight(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
status := p.(framework.PreScorePlugin).PreScore(context.Background(), state, test.pod, test.nodes, nil) status := p.(framework.PreScorePlugin).PreScore(context.Background(), state, test.pod, test.nodes)
if !status.IsSuccess() { if !status.IsSuccess() {
t.Errorf("unexpected error: %v", status) t.Errorf("unexpected error: %v", status)
} }

View File

@ -65,7 +65,6 @@ func (rl *ResourceLimits) PreScore(
cycleState *framework.CycleState, cycleState *framework.CycleState,
pod *v1.Pod, pod *v1.Pod,
nodes []*v1.Node, nodes []*v1.Node,
_ framework.NodeToStatusMap,
) *framework.Status { ) *framework.Status {
if len(nodes) == 0 { if len(nodes) == 0 {
// No nodes to score. // No nodes to score.

View File

@ -152,7 +152,7 @@ func TestResourceLimits(t *testing.T) {
for i := range test.nodes { for i := range test.nodes {
state := framework.NewCycleState() state := framework.NewCycleState()
if !test.skipPreScore { if !test.skipPreScore {
status := p.PreScore(context.Background(), state, test.pod, test.nodes, nil) status := p.PreScore(context.Background(), state, test.pod, test.nodes)
if !status.IsSuccess() { if !status.IsSuccess() {
t.Errorf("unexpected error: %v", status) t.Errorf("unexpected error: %v", status)
} }

View File

@ -84,7 +84,6 @@ func (pl *PodTopologySpread) PreScore(
cycleState *framework.CycleState, cycleState *framework.CycleState,
pod *v1.Pod, pod *v1.Pod,
filteredNodes []*v1.Node, filteredNodes []*v1.Node,
_ framework.NodeToStatusMap,
) *framework.Status { ) *framework.Status {
allNodes, err := pl.sharedLister.NodeInfos().List() allNodes, err := pl.sharedLister.NodeInfos().List()
if err != nil { if err != nil {

View File

@ -476,7 +476,7 @@ func TestPodTopologySpreadScore(t *testing.T) {
snapshot := cache.NewSnapshot(tt.existingPods, allNodes) snapshot := cache.NewSnapshot(tt.existingPods, allNodes)
p := &PodTopologySpread{sharedLister: snapshot} p := &PodTopologySpread{sharedLister: snapshot}
status := p.PreScore(context.Background(), state, tt.pod, tt.nodes, nil) status := p.PreScore(context.Background(), state, tt.pod, tt.nodes)
if !status.IsSuccess() { if !status.IsSuccess() {
t.Errorf("unexpected error: %v", status) t.Errorf("unexpected error: %v", status)
} }
@ -546,7 +546,7 @@ func BenchmarkTestPodTopologySpreadScore(b *testing.B) {
snapshot := cache.NewSnapshot(existingPods, allNodes) snapshot := cache.NewSnapshot(existingPods, allNodes)
p := &PodTopologySpread{sharedLister: snapshot} p := &PodTopologySpread{sharedLister: snapshot}
status := p.PreScore(context.Background(), state, tt.pod, filteredNodes, nil) status := p.PreScore(context.Background(), state, tt.pod, filteredNodes)
if !status.IsSuccess() { if !status.IsSuccess() {
b.Fatalf("unexpected error: %v", status) b.Fatalf("unexpected error: %v", status)
} }
@ -605,7 +605,7 @@ func BenchmarkTestDefaultEvenPodsSpreadPriority(b *testing.B) {
snapshot := cache.NewSnapshot(existingPods, allNodes) snapshot := cache.NewSnapshot(existingPods, allNodes)
p := &PodTopologySpread{sharedLister: snapshot} p := &PodTopologySpread{sharedLister: snapshot}
status := p.PreScore(context.Background(), state, pod, filteredNodes, nil) status := p.PreScore(context.Background(), state, pod, filteredNodes)
if !status.IsSuccess() { if !status.IsSuccess() {
b.Fatalf("unexpected error: %v", status) b.Fatalf("unexpected error: %v", status)
} }

View File

@ -100,7 +100,7 @@ func getAllTolerationPreferNoSchedule(tolerations []v1.Toleration) (tolerationLi
} }
// PreScore builds and writes cycle state used by Score and NormalizeScore. // PreScore builds and writes cycle state used by Score and NormalizeScore.
func (pl *TaintToleration) PreScore(ctx context.Context, cycleState *framework.CycleState, pod *v1.Pod, nodes []*v1.Node, _ framework.NodeToStatusMap) *framework.Status { func (pl *TaintToleration) PreScore(ctx context.Context, cycleState *framework.CycleState, pod *v1.Pod, nodes []*v1.Node) *framework.Status {
if len(nodes) == 0 { if len(nodes) == 0 {
return nil return nil
} }

View File

@ -233,7 +233,7 @@ func TestTaintTolerationScore(t *testing.T) {
fh, _ := framework.NewFramework(nil, nil, nil, framework.WithSnapshotSharedLister(snapshot)) fh, _ := framework.NewFramework(nil, nil, nil, framework.WithSnapshotSharedLister(snapshot))
p, _ := New(nil, fh) p, _ := New(nil, fh)
status := p.(framework.PreScorePlugin).PreScore(context.Background(), state, test.pod, test.nodes, nil) status := p.(framework.PreScorePlugin).PreScore(context.Background(), state, test.pod, test.nodes)
if !status.IsSuccess() { if !status.IsSuccess() {
t.Errorf("unexpected error: %v", status) t.Errorf("unexpected error: %v", status)
} }

View File

@ -22,7 +22,7 @@ import (
"reflect" "reflect"
"time" "time"
"k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
@ -462,21 +462,19 @@ func (f *framework) runFilterPlugin(ctx context.Context, pl FilterPlugin, state
} }
// RunPreScorePlugins runs the set of configured pre-score plugins. If any // RunPreScorePlugins runs the set of configured pre-score plugins. If any
// of these plugins returns any status other than "Success", the given pod is // of these plugins returns any status other than "Success", the given pod is rejected.
// rejected. The filteredNodeStatuses is the set of filtered nodes and their statuses.
func (f *framework) RunPreScorePlugins( func (f *framework) RunPreScorePlugins(
ctx context.Context, ctx context.Context,
state *CycleState, state *CycleState,
pod *v1.Pod, pod *v1.Pod,
nodes []*v1.Node, nodes []*v1.Node,
filteredNodesStatuses NodeToStatusMap,
) (status *Status) { ) (status *Status) {
startTime := time.Now() startTime := time.Now()
defer func() { defer func() {
metrics.FrameworkExtensionPointDuration.WithLabelValues(preScore, status.Code().String()).Observe(metrics.SinceInSeconds(startTime)) metrics.FrameworkExtensionPointDuration.WithLabelValues(preScore, status.Code().String()).Observe(metrics.SinceInSeconds(startTime))
}() }()
for _, pl := range f.preScorePlugins { for _, pl := range f.preScorePlugins {
status = f.runPreScorePlugin(ctx, pl, state, pod, nodes, filteredNodesStatuses) status = f.runPreScorePlugin(ctx, pl, state, pod, nodes)
if !status.IsSuccess() { if !status.IsSuccess() {
msg := fmt.Sprintf("error while running %q prescore plugin for pod %q: %v", pl.Name(), pod.Name, status.Message()) msg := fmt.Sprintf("error while running %q prescore plugin for pod %q: %v", pl.Name(), pod.Name, status.Message())
klog.Error(msg) klog.Error(msg)
@ -487,12 +485,12 @@ func (f *framework) RunPreScorePlugins(
return nil return nil
} }
func (f *framework) runPreScorePlugin(ctx context.Context, pl PreScorePlugin, state *CycleState, pod *v1.Pod, nodes []*v1.Node, filteredNodesStatuses NodeToStatusMap) *Status { func (f *framework) runPreScorePlugin(ctx context.Context, pl PreScorePlugin, state *CycleState, pod *v1.Pod, nodes []*v1.Node) *Status {
if !state.ShouldRecordPluginMetrics() { if !state.ShouldRecordPluginMetrics() {
return pl.PreScore(ctx, state, pod, nodes, filteredNodesStatuses) return pl.PreScore(ctx, state, pod, nodes)
} }
startTime := time.Now() startTime := time.Now()
status := pl.PreScore(ctx, state, pod, nodes, filteredNodesStatuses) status := pl.PreScore(ctx, state, pod, nodes)
f.metricsRecorder.observePluginDurationAsync(preScore, pl.Name(), status, metrics.SinceInSeconds(startTime)) f.metricsRecorder.observePluginDurationAsync(preScore, pl.Name(), status, metrics.SinceInSeconds(startTime))
return status return status
} }

View File

@ -169,7 +169,7 @@ func (pl *TestPlugin) Filter(ctx context.Context, state *CycleState, pod *v1.Pod
return NewStatus(Code(pl.inj.FilterStatus), "injected filter status") return NewStatus(Code(pl.inj.FilterStatus), "injected filter status")
} }
func (pl *TestPlugin) PreScore(ctx context.Context, state *CycleState, pod *v1.Pod, nodes []*v1.Node, filteredNodesStatuses NodeToStatusMap) *Status { func (pl *TestPlugin) PreScore(ctx context.Context, state *CycleState, pod *v1.Pod, nodes []*v1.Node) *Status {
return NewStatus(Code(pl.inj.PreScoreStatus), "injected status") return NewStatus(Code(pl.inj.PreScoreStatus), "injected status")
} }
@ -1329,7 +1329,7 @@ func TestRecordingMetrics(t *testing.T) {
}, },
{ {
name: "PreScore - Success", name: "PreScore - Success",
action: func(f Framework) { f.RunPreScorePlugins(context.Background(), state, pod, nil, nil) }, action: func(f Framework) { f.RunPreScorePlugins(context.Background(), state, pod, nil) },
wantExtensionPoint: "PreScore", wantExtensionPoint: "PreScore",
wantStatus: Success, wantStatus: Success,
}, },
@ -1385,7 +1385,7 @@ func TestRecordingMetrics(t *testing.T) {
}, },
{ {
name: "PreScore - Error", name: "PreScore - Error",
action: func(f Framework) { f.RunPreScorePlugins(context.Background(), state, pod, nil, nil) }, action: func(f Framework) { f.RunPreScorePlugins(context.Background(), state, pod, nil) },
inject: injectedResult{PreScoreStatus: int(Error)}, inject: injectedResult{PreScoreStatus: int(Error)},
wantExtensionPoint: "PreScore", wantExtensionPoint: "PreScore",
wantStatus: Error, wantStatus: Error,

View File

@ -310,9 +310,8 @@ type PreScorePlugin interface {
Plugin Plugin
// PreScore is called by the scheduling framework after a list of nodes // PreScore is called by the scheduling framework after a list of nodes
// passed the filtering phase. All prescore plugins must return success or // passed the filtering phase. All prescore plugins must return success or
// the pod will be rejected. The filteredNodesStatuses is the set of filtered nodes // the pod will be rejected
// and their filter status. PreScore(ctx context.Context, state *CycleState, pod *v1.Pod, nodes []*v1.Node) *Status
PreScore(ctx context.Context, state *CycleState, pod *v1.Pod, nodes []*v1.Node, filteredNodesStatuses NodeToStatusMap) *Status
} }
// ScoreExtensions is an interface for Score extended functionality. // ScoreExtensions is an interface for Score extended functionality.
@ -439,9 +438,8 @@ type Framework interface {
RunPreFilterExtensionRemovePod(ctx context.Context, state *CycleState, podToSchedule *v1.Pod, podToAdd *v1.Pod, nodeInfo *schedulernodeinfo.NodeInfo) *Status RunPreFilterExtensionRemovePod(ctx context.Context, state *CycleState, podToSchedule *v1.Pod, podToAdd *v1.Pod, nodeInfo *schedulernodeinfo.NodeInfo) *Status
// RunPreScorePlugins runs the set of configured pre-score plugins. If any // RunPreScorePlugins runs the set of configured pre-score plugins. If any
// of these plugins returns any status other than "Success", the given pod is // of these plugins returns any status other than "Success", the given pod is rejected.
// rejected. The filteredNodeStatuses is the set of filtered nodes and their statuses. RunPreScorePlugins(ctx context.Context, state *CycleState, pod *v1.Pod, nodes []*v1.Node) *Status
RunPreScorePlugins(ctx context.Context, state *CycleState, pod *v1.Pod, nodes []*v1.Node, filteredNodesStatuses NodeToStatusMap) *Status
// RunScorePlugins runs the set of configured scoring plugins. It returns a map that // RunScorePlugins runs the set of configured scoring plugins. It returns a map that
// stores for each scoring plugin name the corresponding NodeScoreList(s). // stores for each scoring plugin name the corresponding NodeScoreList(s).

View File

@ -247,7 +247,7 @@ func (*PreScorePlugin) Name() string {
} }
// PreScore is a test function. // PreScore is a test function.
func (pfp *PreScorePlugin) PreScore(ctx context.Context, _ *framework.CycleState, pod *v1.Pod, _ []*v1.Node, _ framework.NodeToStatusMap) *framework.Status { func (pfp *PreScorePlugin) PreScore(ctx context.Context, _ *framework.CycleState, pod *v1.Pod, _ []*v1.Node) *framework.Status {
pfp.numPreScoreCalled++ pfp.numPreScoreCalled++
if pfp.failPreScore { if pfp.failPreScore {
return framework.NewStatus(framework.Error, fmt.Sprintf("injecting failure for pod %v", pod.Name)) return framework.NewStatus(framework.Error, fmt.Sprintf("injecting failure for pod %v", pod.Name))