Merge pull request #130537 from saintube/scheduler-expose-nodeinfo-in-score

Expose NodeInfo to the ScorePlugin
This commit is contained in:
Kubernetes Prow Robot 2025-03-06 06:53:55 -08:00 committed by GitHub
commit 0f7becbc44
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
27 changed files with 138 additions and 105 deletions

View File

@ -609,7 +609,7 @@ type ScorePlugin interface {
// Score is called on each filtered node. It must return success and an integer
// indicating the rank of the node. All scoring plugins must return success or
// the pod will be rejected.
Score(ctx context.Context, state *CycleState, p *v1.Pod, nodeName string) (int64, *Status)
Score(ctx context.Context, state *CycleState, p *v1.Pod, nodeInfo *NodeInfo) (int64, *Status)
// ScoreExtensions returns a ScoreExtensions interface if it implements one, or nil if does not.
ScoreExtensions() ScoreExtensions

View File

@ -18,7 +18,6 @@ package imagelocality
import (
"context"
"fmt"
"strings"
v1 "k8s.io/api/core/v1"
@ -51,12 +50,7 @@ func (pl *ImageLocality) Name() string {
}
// Score invoked at the score extension point.
func (pl *ImageLocality) Score(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeName string) (int64, *framework.Status) {
nodeInfo, err := pl.handle.SnapshotSharedLister().NodeInfos().Get(nodeName)
if err != nil {
return 0, framework.AsStatus(fmt.Errorf("getting node %q from Snapshot: %w", nodeName, err))
}
func (pl *ImageLocality) Score(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) (int64, *framework.Status) {
nodeInfos, err := pl.handle.SnapshotSharedLister().NodeInfos().List()
if err != nil {
return 0, framework.AsStatus(err)

View File

@ -374,7 +374,14 @@ func TestImageLocalityPriority(t *testing.T) {
var gotList framework.NodeScoreList
for _, n := range test.nodes {
nodeName := n.ObjectMeta.Name
score, status := p.(framework.ScorePlugin).Score(ctx, state, test.pod, nodeName)
// Currently, we use the snapshot instead of the tf.BuildNodeInfos to build the nodeInfo since some
// fields like ImageStates is essential for the Score plugin but the latter does not construct that.
// We should enhance the BuildNodeInfos to achieve feature parity with the core logic.
nodeInfo, err := snapshot.NodeInfos().Get(nodeName)
if err != nil {
t.Errorf("failed to get node %q from snapshot: %v", nodeName, err)
}
score, status := p.(framework.ScorePlugin).Score(ctx, state, test.pod, nodeInfo)
if !status.IsSuccess() {
t.Errorf("unexpected error: %v", status)
}

View File

@ -236,11 +236,7 @@ func getPreScoreState(cycleState *framework.CycleState) (*preScoreState, error)
// The "score" returned in this function is the sum of weights got from cycleState which have its topologyKey matching with the node's labels.
// it is normalized later.
// Note: the returned "score" is positive for pod-affinity, and negative for pod-antiaffinity.
func (pl *InterPodAffinity) Score(ctx context.Context, cycleState *framework.CycleState, pod *v1.Pod, nodeName string) (int64, *framework.Status) {
nodeInfo, err := pl.sharedLister.NodeInfos().Get(nodeName)
if err != nil {
return 0, framework.AsStatus(fmt.Errorf("failed to get node %q from Snapshot: %w", nodeName, err))
}
func (pl *InterPodAffinity) Score(ctx context.Context, cycleState *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) (int64, *framework.Status) {
node := nodeInfo.Node()
s, err := getPreScoreState(cycleState)

View File

@ -786,7 +786,8 @@ func TestPreferredAffinity(t *testing.T) {
defer cancel()
state := framework.NewCycleState()
p := plugintesting.SetupPluginWithInformers(ctx, t, schedruntime.FactoryAdapter(feature.Features{}, New), &config.InterPodAffinityArgs{HardPodAffinityWeight: 1, IgnorePreferredTermsOfExistingPods: test.ignorePreferredTermsOfExistingPods}, cache.NewSnapshot(test.pods, test.nodes), namespaces)
status := p.(framework.PreScorePlugin).PreScore(ctx, state, test.pod, tf.BuildNodeInfos(test.nodes))
nodeInfos := tf.BuildNodeInfos(test.nodes)
status := p.(framework.PreScorePlugin).PreScore(ctx, state, test.pod, nodeInfos)
if !status.IsSuccess() {
if status.Code() != test.wantStatus.Code() {
@ -800,9 +801,9 @@ func TestPreferredAffinity(t *testing.T) {
}
var gotList framework.NodeScoreList
for _, n := range test.nodes {
nodeName := n.ObjectMeta.Name
score, status := p.(framework.ScorePlugin).Score(ctx, state, test.pod, nodeName)
for _, nodeInfo := range nodeInfos {
nodeName := nodeInfo.Node().Name
score, status := p.(framework.ScorePlugin).Score(ctx, state, test.pod, nodeInfo)
if !status.IsSuccess() {
t.Errorf("unexpected error from Score: %v", status)
}
@ -954,7 +955,8 @@ func TestPreferredAffinityWithHardPodAffinitySymmetricWeight(t *testing.T) {
defer cancel()
state := framework.NewCycleState()
p := plugintesting.SetupPluginWithInformers(ctx, t, schedruntime.FactoryAdapter(feature.Features{}, New), &config.InterPodAffinityArgs{HardPodAffinityWeight: test.hardPodAffinityWeight}, cache.NewSnapshot(test.pods, test.nodes), namespaces)
status := p.(framework.PreScorePlugin).PreScore(ctx, state, test.pod, tf.BuildNodeInfos(test.nodes))
nodeInfos := tf.BuildNodeInfos(test.nodes)
status := p.(framework.PreScorePlugin).PreScore(ctx, state, test.pod, nodeInfos)
if !test.wantStatus.Equal(status) {
t.Errorf("InterPodAffinity#PreScore() returned unexpected status.Code got: %v, want: %v", status.Code(), test.wantStatus.Code())
}
@ -963,9 +965,13 @@ func TestPreferredAffinityWithHardPodAffinitySymmetricWeight(t *testing.T) {
}
var gotList framework.NodeScoreList
for _, n := range test.nodes {
nodeName := n.ObjectMeta.Name
score, status := p.(framework.ScorePlugin).Score(ctx, state, test.pod, nodeName)
for _, nodeInfo := range nodeInfos {
nodeName := nodeInfo.Node().Name
nodeInfo, err := p.(*InterPodAffinity).sharedLister.NodeInfos().Get(nodeName)
if err != nil {
t.Errorf("failed to get node %q from snapshot: %v", nodeName, err)
}
score, status := p.(framework.ScorePlugin).Score(ctx, state, test.pod, nodeInfo)
if !status.IsSuccess() {
t.Errorf("unexpected error: %v", status)
}

View File

@ -256,12 +256,7 @@ func (pl *NodeAffinity) PreScore(ctx context.Context, cycleState *framework.Cycl
// Score returns the sum of the weights of the terms that match the Node.
// Terms came from the Pod .spec.affinity.nodeAffinity and from the plugin's
// default affinity.
func (pl *NodeAffinity) Score(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeName string) (int64, *framework.Status) {
nodeInfo, err := pl.handle.SnapshotSharedLister().NodeInfos().Get(nodeName)
if err != nil {
return 0, framework.AsStatus(fmt.Errorf("getting node %q from Snapshot: %w", nodeName, err))
}
func (pl *NodeAffinity) Score(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) (int64, *framework.Status) {
node := nodeInfo.Node()
var count int64

View File

@ -1212,9 +1212,10 @@ func TestNodeAffinityPriority(t *testing.T) {
}
}
var gotList framework.NodeScoreList
for _, n := range test.nodes {
nodeName := n.ObjectMeta.Name
score, status := p.(framework.ScorePlugin).Score(ctx, state, test.pod, nodeName)
nodeInfos := tf.BuildNodeInfos(test.nodes)
for _, nodeInfo := range nodeInfos {
nodeName := nodeInfo.Node().Name
score, status := p.(framework.ScorePlugin).Score(ctx, state, test.pod, nodeInfo)
if !status.IsSuccess() {
t.Errorf("unexpected error: %v", status)
}

View File

@ -89,12 +89,7 @@ func (ba *BalancedAllocation) Name() string {
}
// Score invoked at the score extension point.
func (ba *BalancedAllocation) Score(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeName string) (int64, *framework.Status) {
nodeInfo, err := ba.handle.SnapshotSharedLister().NodeInfos().Get(nodeName)
if err != nil {
return 0, framework.AsStatus(fmt.Errorf("getting node %q from Snapshot: %w", nodeName, err))
}
func (ba *BalancedAllocation) Score(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) (int64, *framework.Status) {
s, err := getBalancedAllocationPreScoreState(state)
if err != nil {
s = &balancedAllocationPreScoreState{podRequests: ba.calculatePodResourceRequestList(pod, ba.resources)}

View File

@ -399,7 +399,11 @@ func TestNodeResourcesBalancedAllocation(t *testing.T) {
t.Errorf("PreScore is expected to return success, but didn't. Got status: %v", status)
}
}
hostResult, status := p.(framework.ScorePlugin).Score(ctx, state, test.pod, test.nodes[i].Name)
nodeInfo, err := snapshot.Get(test.nodes[i].Name)
if err != nil {
t.Errorf("failed to get node %q from snapshot: %v", test.nodes[i].Name, err)
}
hostResult, status := p.(framework.ScorePlugin).Score(ctx, state, test.pod, nodeInfo)
if !status.IsSuccess() {
t.Errorf("Score is expected to return success, but didn't. Got status: %v", status)
}

View File

@ -579,12 +579,7 @@ func fitsRequest(podRequest *preFilterState, nodeInfo *framework.NodeInfo, ignor
}
// Score invoked at the Score extension point.
func (f *Fit) Score(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeName string) (int64, *framework.Status) {
nodeInfo, err := f.handle.SnapshotSharedLister().NodeInfos().Get(nodeName)
if err != nil {
return 0, framework.AsStatus(fmt.Errorf("getting node %q from Snapshot: %w", nodeName, err))
}
func (f *Fit) Score(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) (int64, *framework.Status) {
s, err := getPreScoreState(state)
if err != nil {
s = &preScoreState{

View File

@ -1106,7 +1106,11 @@ func TestFitScore(t *testing.T) {
t.Errorf("PreScore is expected to return success, but didn't. Got status: %v", status)
}
}
score, status := p.(framework.ScorePlugin).Score(ctx, state, test.requestedPod, n.Name)
nodeInfo, err := snapshot.Get(n.Name)
if err != nil {
t.Errorf("failed to get node %q from snapshot: %v", n.Name, err)
}
score, status := p.(framework.ScorePlugin).Score(ctx, state, test.requestedPod, nodeInfo)
if !status.IsSuccess() {
t.Errorf("Score is expected to return success, but didn't. Got status: %v", status)
}
@ -1221,12 +1225,16 @@ func BenchmarkTestFitScore(b *testing.B) {
var nodeResourcesFunc = runtime.FactoryAdapter(plfeature.Features{}, NewFit)
pl := plugintesting.SetupPlugin(ctx, b, nodeResourcesFunc, &test.nodeResourcesFitArgs, cache.NewSnapshot(existingPods, nodes))
p := pl.(*Fit)
nodeInfo, err := p.handle.SnapshotSharedLister().NodeInfos().Get(nodes[0].Name)
if err != nil {
b.Errorf("failed to get node %q from snapshot: %v", nodes[0].Name, err)
}
b.ResetTimer()
requestedPod := st.MakePod().Req(map[v1.ResourceName]string{"cpu": "1000", "memory": "2000"}).Obj()
for i := 0; i < b.N; i++ {
_, status := p.Score(ctx, state, requestedPod, nodes[0].Name)
_, status := p.Score(ctx, state, requestedPod, nodeInfo)
if !status.IsSuccess() {
b.Errorf("unexpected status: %v", status)
}

View File

@ -419,7 +419,11 @@ func TestLeastAllocatedScoringStrategy(t *testing.T) {
var gotScores framework.NodeScoreList
for _, n := range test.nodes {
score, status := p.(framework.ScorePlugin).Score(ctx, state, test.requestedPod, n.Name)
nodeInfo, err := snapshot.Get(n.Name)
if err != nil {
t.Errorf("failed to get node %q from snapshot: %v", n.Name, err)
}
score, status := p.(framework.ScorePlugin).Score(ctx, state, test.requestedPod, nodeInfo)
if status.Code() != test.wantStatusCode {
t.Errorf("unexpected status code, want: %v, got: %v", test.wantStatusCode, status.Code())
}

View File

@ -375,7 +375,11 @@ func TestMostAllocatedScoringStrategy(t *testing.T) {
var gotScores framework.NodeScoreList
for _, n := range test.nodes {
score, status := p.(framework.ScorePlugin).Score(ctx, state, test.requestedPod, n.Name)
nodeInfo, err := snapshot.Get(n.Name)
if err != nil {
t.Errorf("failed to get node %q from snapshot: %v", n.Name, err)
}
score, status := p.(framework.ScorePlugin).Score(ctx, state, test.requestedPod, nodeInfo)
if status.Code() != test.wantStatusCode {
t.Errorf("unexpected status code, want: %v, got: %v", test.wantStatusCode, status.Code())
}

View File

@ -136,7 +136,11 @@ func TestRequestedToCapacityRatioScoringStrategy(t *testing.T) {
if !status.IsSuccess() {
t.Errorf("PreScore is expected to return success, but didn't. Got status: %v", status)
}
score, status := p.(framework.ScorePlugin).Score(ctx, state, test.requestedPod, n.Name)
nodeInfo, err := snapshot.Get(n.Name)
if err != nil {
t.Errorf("failed to get node %q from snapshot: %v", n.Name, err)
}
score, status := p.(framework.ScorePlugin).Score(ctx, state, test.requestedPod, nodeInfo)
if !status.IsSuccess() {
t.Errorf("Score is expected to return success, but didn't. Got status: %v", status)
}
@ -333,7 +337,11 @@ func TestResourceBinPackingSingleExtended(t *testing.T) {
if !status.IsSuccess() {
t.Errorf("PreScore is expected to return success, but didn't. Got status: %v", status)
}
score, status := p.(framework.ScorePlugin).Score(ctx, state, test.pod, n.Name)
nodeInfo, err := snapshot.Get(n.Name)
if err != nil {
t.Errorf("failed to get node %q from snapshot: %v", n.Name, err)
}
score, status := p.(framework.ScorePlugin).Score(ctx, state, test.pod, nodeInfo)
if !status.IsSuccess() {
t.Errorf("Score is expected to return success, but didn't. Got status: %v", status)
}
@ -562,7 +570,11 @@ func TestResourceBinPackingMultipleExtended(t *testing.T) {
var gotScores framework.NodeScoreList
for _, n := range test.nodes {
score, status := p.(framework.ScorePlugin).Score(ctx, state, test.pod, n.Name)
nodeInfo, err := snapshot.Get(n.Name)
if err != nil {
t.Errorf("failed to get node %q from snapshot: %v", n.Name, err)
}
score, status := p.(framework.ScorePlugin).Score(ctx, state, test.pod, nodeInfo)
if !status.IsSuccess() {
t.Errorf("Score is expected to return success, but didn't. Got status: %v", status)
}

View File

@ -192,12 +192,7 @@ func (pl *PodTopologySpread) PreScore(
// Score invoked at the Score extension point.
// The "score" returned in this function is the matching number of pods on the `nodeName`,
// it is normalized later.
func (pl *PodTopologySpread) Score(ctx context.Context, cycleState *framework.CycleState, pod *v1.Pod, nodeName string) (int64, *framework.Status) {
nodeInfo, err := pl.sharedLister.NodeInfos().Get(nodeName)
if err != nil {
return 0, framework.AsStatus(fmt.Errorf("getting node %q from Snapshot: %w", nodeName, err))
}
func (pl *PodTopologySpread) Score(ctx context.Context, cycleState *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) (int64, *framework.Status) {
node := nodeInfo.Node()
s, err := getPreScoreState(cycleState)
if err != nil {

View File

@ -1396,7 +1396,11 @@ func TestPodTopologySpreadScore(t *testing.T) {
var gotList framework.NodeScoreList
for _, n := range tt.nodes {
nodeName := n.Name
score, status := p.Score(ctx, state, tt.pod, nodeName)
nodeInfo, err := p.sharedLister.NodeInfos().Get(n.Name)
if err != nil {
t.Errorf("failed to get node %q from snapshot: %v", n.Name, err)
}
score, status := p.Score(ctx, state, tt.pod, nodeInfo)
if !status.IsSuccess() {
t.Errorf("unexpected error: %v", status)
}
@ -1463,13 +1467,21 @@ func BenchmarkTestPodTopologySpreadScore(b *testing.B) {
if !status.IsSuccess() {
b.Fatalf("unexpected error: %v", status)
}
nodeInfos := make([]*framework.NodeInfo, len(filteredNodes))
for i, n := range filteredNodes {
nodeInfo, err := p.sharedLister.NodeInfos().Get(n.Name)
if err != nil {
b.Fatalf("failed to get node %q from snapshot: %v", n.Name, err)
}
nodeInfos[i] = nodeInfo
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
var gotList framework.NodeScoreList
for _, n := range filteredNodes {
nodeName := n.Name
score, status := p.Score(ctx, state, tt.pod, nodeName)
for _, nodeInfo := range nodeInfos {
nodeName := nodeInfo.Node().Name
score, status := p.Score(ctx, state, tt.pod, nodeInfo)
if !status.IsSuccess() {
b.Fatalf("unexpected error: %v", status)
}

View File

@ -180,11 +180,7 @@ func countIntolerableTaintsPreferNoSchedule(taints []v1.Taint, tolerations []v1.
}
// Score invoked at the Score extension point.
func (pl *TaintToleration) Score(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeName string) (int64, *framework.Status) {
nodeInfo, err := pl.handle.SnapshotSharedLister().NodeInfos().Get(nodeName)
if err != nil {
return 0, framework.AsStatus(fmt.Errorf("getting node %q from Snapshot: %w", nodeName, err))
}
func (pl *TaintToleration) Score(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) (int64, *framework.Status) {
node := nodeInfo.Node()
s, err := getPreScoreState(state)

View File

@ -243,14 +243,15 @@ func TestTaintTolerationScore(t *testing.T) {
if err != nil {
t.Fatalf("creating plugin: %v", err)
}
status := p.(framework.PreScorePlugin).PreScore(ctx, state, test.pod, tf.BuildNodeInfos(test.nodes))
nodeInfos := tf.BuildNodeInfos(test.nodes)
status := p.(framework.PreScorePlugin).PreScore(ctx, state, test.pod, nodeInfos)
if !status.IsSuccess() {
t.Errorf("unexpected error: %v", status)
}
var gotList framework.NodeScoreList
for _, n := range test.nodes {
nodeName := n.ObjectMeta.Name
score, status := p.(framework.ScorePlugin).Score(ctx, state, test.pod, nodeName)
for _, nodeInfo := range nodeInfos {
nodeName := nodeInfo.Node().Name
score, status := p.(framework.ScorePlugin).Score(ctx, state, test.pod, nodeInfo)
if !status.IsSuccess() {
t.Errorf("unexpected error: %v", status)
}

View File

@ -458,7 +458,7 @@ func (pl *VolumeBinding) PreScore(ctx context.Context, cs *framework.CycleState,
}
// Score invoked at the score extension point.
func (pl *VolumeBinding) Score(ctx context.Context, cs *framework.CycleState, pod *v1.Pod, nodeName string) (int64, *framework.Status) {
func (pl *VolumeBinding) Score(ctx context.Context, cs *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) (int64, *framework.Status) {
if pl.scorer == nil {
return 0, nil
}
@ -466,6 +466,7 @@ func (pl *VolumeBinding) Score(ctx context.Context, cs *framework.CycleState, po
if err != nil {
return 0, framework.AsStatus(err)
}
nodeName := nodeInfo.Node().Name
podVolumes, ok := state.podVolumesByNode[nodeName]
if !ok {
return 0, nil

View File

@ -773,12 +773,7 @@ func TestVolumeBinding(t *testing.T) {
t.Log("Verify")
p := pl.(*VolumeBinding)
nodeInfos := make([]*framework.NodeInfo, 0)
for _, node := range item.nodes {
nodeInfo := framework.NewNodeInfo()
nodeInfo.SetNode(node)
nodeInfos = append(nodeInfos, nodeInfo)
}
nodeInfos := tf.BuildNodeInfos(item.nodes)
state := framework.NewCycleState()
t.Logf("Verify: call PreFilter and check status")
@ -818,7 +813,7 @@ func TestVolumeBinding(t *testing.T) {
}
t.Logf("Verify: call PreScore and check status")
gotPreScoreStatus := p.PreScore(ctx, state, item.pod, tf.BuildNodeInfos(item.nodes))
gotPreScoreStatus := p.PreScore(ctx, state, item.pod, nodeInfos)
if diff := cmp.Diff(item.wantPreScoreStatus, gotPreScoreStatus); diff != "" {
t.Errorf("state got after prescore does not match (-want,+got):\n%s", diff)
}
@ -827,13 +822,14 @@ func TestVolumeBinding(t *testing.T) {
}
t.Logf("Verify: Score")
for i, node := range item.nodes {
score, status := p.Score(ctx, state, item.pod, node.Name)
for i, nodeInfo := range nodeInfos {
nodeName := nodeInfo.Node().Name
score, status := p.Score(ctx, state, item.pod, nodeInfo)
if !status.IsSuccess() {
t.Errorf("Score expects success status, got: %v", status)
}
if score != item.wantScores[i] {
t.Errorf("Score expects score %d for node %q, got: %d", item.wantScores[i], node.Name, score)
t.Errorf("Score expects score %d for node %q, got: %d", item.wantScores[i], nodeName, score)
}
}
})

View File

@ -1137,7 +1137,8 @@ func (f *frameworkImpl) RunScorePlugins(ctx context.Context, state *framework.Cy
}
// Run Score method for each node in parallel.
f.Parallelizer().Until(ctx, len(nodes), func(index int) {
nodeName := nodes[index].Node().Name
nodeInfo := nodes[index]
nodeName := nodeInfo.Node().Name
logger := logger
if verboseLogs {
logger = klog.LoggerWithValues(logger, "node", klog.ObjectRef{Name: nodeName})
@ -1148,7 +1149,7 @@ func (f *frameworkImpl) RunScorePlugins(ctx context.Context, state *framework.Cy
logger := klog.LoggerWithName(logger, pl.Name())
ctx = klog.NewContext(ctx, logger)
}
s, status := f.runScorePlugin(ctx, pl, state, pod, nodeName)
s, status := f.runScorePlugin(ctx, pl, state, pod, nodeInfo)
if !status.IsSuccess() {
err := fmt.Errorf("plugin %q failed with: %w", pl.Name(), status.AsError())
errCh.SendErrorWithCancel(err, cancel)
@ -1217,12 +1218,12 @@ func (f *frameworkImpl) RunScorePlugins(ctx context.Context, state *framework.Cy
return allNodePluginScores, nil
}
func (f *frameworkImpl) runScorePlugin(ctx context.Context, pl framework.ScorePlugin, state *framework.CycleState, pod *v1.Pod, nodeName string) (int64, *framework.Status) {
func (f *frameworkImpl) runScorePlugin(ctx context.Context, pl framework.ScorePlugin, state *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) (int64, *framework.Status) {
if !state.ShouldRecordPluginMetrics() {
return pl.Score(ctx, state, pod, nodeName)
return pl.Score(ctx, state, pod, nodeInfo)
}
startTime := time.Now()
s, status := pl.Score(ctx, state, pod, nodeName)
s, status := pl.Score(ctx, state, pod, nodeInfo)
f.metricsRecorder.ObservePluginDurationAsync(metrics.Score, pl.Name(), status.Code().String(), metrics.SinceInSeconds(startTime))
return s, status
}

View File

@ -132,7 +132,7 @@ func (pl *TestScoreWithNormalizePlugin) NormalizeScore(ctx context.Context, stat
return injectNormalizeRes(pl.inj, scores)
}
func (pl *TestScoreWithNormalizePlugin) Score(ctx context.Context, state *framework.CycleState, p *v1.Pod, nodeName string) (int64, *framework.Status) {
func (pl *TestScoreWithNormalizePlugin) Score(ctx context.Context, state *framework.CycleState, p *v1.Pod, nodeInfo *framework.NodeInfo) (int64, *framework.Status) {
return setScoreRes(pl.inj)
}
@ -154,7 +154,7 @@ func (pl *TestScorePlugin) PreScore(ctx context.Context, state *framework.CycleS
return framework.NewStatus(framework.Code(pl.inj.PreScoreStatus), injectReason)
}
func (pl *TestScorePlugin) Score(ctx context.Context, state *framework.CycleState, p *v1.Pod, nodeName string) (int64, *framework.Status) {
func (pl *TestScorePlugin) Score(ctx context.Context, state *framework.CycleState, p *v1.Pod, nodeInfo *framework.NodeInfo) (int64, *framework.Status) {
return setScoreRes(pl.inj)
}
@ -194,7 +194,7 @@ func (pl *TestPlugin) Less(*framework.QueuedPodInfo, *framework.QueuedPodInfo) b
return false
}
func (pl *TestPlugin) Score(ctx context.Context, state *framework.CycleState, p *v1.Pod, nodeName string) (int64, *framework.Status) {
func (pl *TestPlugin) Score(ctx context.Context, state *framework.CycleState, p *v1.Pod, nodeInfo *framework.NodeInfo) (int64, *framework.Status) {
return 0, framework.NewStatus(framework.Code(pl.inj.ScoreStatus), injectReason)
}

View File

@ -77,7 +77,7 @@ type instrumentedScorePlugin struct {
var _ framework.ScorePlugin = &instrumentedScorePlugin{}
func (p *instrumentedScorePlugin) Score(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeName string) (int64, *framework.Status) {
func (p *instrumentedScorePlugin) Score(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) (int64, *framework.Status) {
p.metric.Inc()
return p.ScorePlugin.Score(ctx, state, pod, nodeName)
return p.ScorePlugin.Score(ctx, state, pod, nodeInfo)
}

View File

@ -174,7 +174,7 @@ func (pl *falseMapPlugin) Name() string {
return "FalseMap"
}
func (pl *falseMapPlugin) Score(_ context.Context, _ *framework.CycleState, _ *v1.Pod, _ string) (int64, *framework.Status) {
func (pl *falseMapPlugin) Score(_ context.Context, _ *framework.CycleState, _ *v1.Pod, _ *framework.NodeInfo) (int64, *framework.Status) {
return 0, framework.AsStatus(errPrioritize)
}
@ -194,7 +194,8 @@ func (pl *numericMapPlugin) Name() string {
return "NumericMap"
}
func (pl *numericMapPlugin) Score(_ context.Context, _ *framework.CycleState, _ *v1.Pod, nodeName string) (int64, *framework.Status) {
func (pl *numericMapPlugin) Score(_ context.Context, _ *framework.CycleState, _ *v1.Pod, nodeInfo *framework.NodeInfo) (int64, *framework.Status) {
nodeName := nodeInfo.Node().Name
score, err := strconv.Atoi(nodeName)
if err != nil {
return 0, framework.NewStatus(framework.Error, fmt.Sprintf("Error converting nodename to int: %+v", nodeName))
@ -217,7 +218,8 @@ func (pl *reverseNumericMapPlugin) Name() string {
return "ReverseNumericMap"
}
func (pl *reverseNumericMapPlugin) Score(_ context.Context, _ *framework.CycleState, _ *v1.Pod, nodeName string) (int64, *framework.Status) {
func (pl *reverseNumericMapPlugin) Score(_ context.Context, _ *framework.CycleState, _ *v1.Pod, nodeInfo *framework.NodeInfo) (int64, *framework.Status) {
nodeName := nodeInfo.Node().Name
score, err := strconv.Atoi(nodeName)
if err != nil {
return 0, framework.NewStatus(framework.Error, fmt.Sprintf("Error converting nodename to int: %+v", nodeName))
@ -258,7 +260,7 @@ func (pl *trueMapPlugin) Name() string {
return "TrueMap"
}
func (pl *trueMapPlugin) Score(_ context.Context, _ *framework.CycleState, _ *v1.Pod, _ string) (int64, *framework.Status) {
func (pl *trueMapPlugin) Score(_ context.Context, _ *framework.CycleState, _ *v1.Pod, _ *framework.NodeInfo) (int64, *framework.Status) {
return 1, nil
}
@ -372,7 +374,7 @@ func (t *TestPlugin) Name() string {
return t.name
}
func (t *TestPlugin) Score(ctx context.Context, state *framework.CycleState, p *v1.Pod, nodeName string) (int64, *framework.Status) {
func (t *TestPlugin) Score(ctx context.Context, state *framework.CycleState, p *v1.Pod, nodeInfo *framework.NodeInfo) (int64, *framework.Status) {
return 1, nil
}
@ -3001,8 +3003,12 @@ func TestZeroRequest(t *testing.T) {
if err != nil {
t.Fatalf("error filtering nodes: %+v", err)
}
fwk.RunPreScorePlugins(ctx, state, test.pod, tf.BuildNodeInfos(test.nodes))
list, err := prioritizeNodes(ctx, nil, fwk, state, test.pod, tf.BuildNodeInfos(test.nodes))
nodeInfos, err := snapshot.NodeInfos().List()
if err != nil {
t.Fatalf("failed to list node from snapshot: %v", err)
}
fwk.RunPreScorePlugins(ctx, state, test.pod, nodeInfos)
list, err := prioritizeNodes(ctx, nil, fwk, state, test.pod, nodeInfos)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
@ -3399,7 +3405,11 @@ func Test_prioritizeNodes(t *testing.T) {
for ii := range test.extenders {
extenders = append(extenders, &test.extenders[ii])
}
nodesscores, err := prioritizeNodes(ctx, extenders, fwk, state, test.pod, tf.BuildNodeInfos(test.nodes))
nodeInfos, err := snapshot.NodeInfos().List()
if err != nil {
t.Fatalf("failed to list node from snapshot: %v", err)
}
nodesscores, err := prioritizeNodes(ctx, extenders, fwk, state, test.pod, nodeInfos)
if err != nil {
t.Errorf("unexpected error: %v", err)
}

View File

@ -124,9 +124,9 @@ func (pl *node2PrioritizerPlugin) Name() string {
}
// Score return score 100 if the given nodeName is "node2"; otherwise return score 10.
func (pl *node2PrioritizerPlugin) Score(_ context.Context, _ *framework.CycleState, _ *v1.Pod, nodeName string) (int64, *framework.Status) {
func (pl *node2PrioritizerPlugin) Score(_ context.Context, _ *framework.CycleState, _ *v1.Pod, nodeInfo *framework.NodeInfo) (int64, *framework.Status) {
score := 10
if nodeName == "node2" {
if nodeInfo.Node().Name == "node2" {
score = 100
}
return int64(score), nil

View File

@ -258,7 +258,7 @@ func (pl *FakePreScoreAndScorePlugin) Name() string {
return pl.name
}
func (pl *FakePreScoreAndScorePlugin) Score(ctx context.Context, state *framework.CycleState, p *v1.Pod, nodeName string) (int64, *framework.Status) {
func (pl *FakePreScoreAndScorePlugin) Score(ctx context.Context, state *framework.CycleState, p *v1.Pod, nodeInfo *framework.NodeInfo) (int64, *framework.Status) {
return pl.score, pl.scoreStatus
}

View File

@ -355,7 +355,7 @@ func (sp *ScorePlugin) Name() string {
}
// Score returns the score of scheduling a pod on a specific node.
func (sp *ScorePlugin) Score(ctx context.Context, state *framework.CycleState, p *v1.Pod, nodeName string) (int64, *framework.Status) {
func (sp *ScorePlugin) Score(ctx context.Context, state *framework.CycleState, p *v1.Pod, nodeInfo *framework.NodeInfo) (int64, *framework.Status) {
sp.mutex.Lock()
defer sp.mutex.Unlock()
@ -367,7 +367,7 @@ func (sp *ScorePlugin) Score(ctx context.Context, state *framework.CycleState, p
score := int64(1)
if sp.numScoreCalled == 1 {
// The first node is scored the highest, the rest is scored lower.
sp.highScoreNode = nodeName
sp.highScoreNode = nodeInfo.Node().Name
score = framework.MaxNodeScore
}
return score, nil
@ -383,7 +383,7 @@ func (sp *ScoreWithNormalizePlugin) Name() string {
}
// Score returns the score of scheduling a pod on a specific node.
func (sp *ScoreWithNormalizePlugin) Score(ctx context.Context, state *framework.CycleState, p *v1.Pod, nodeName string) (int64, *framework.Status) {
func (sp *ScoreWithNormalizePlugin) Score(ctx context.Context, state *framework.CycleState, p *v1.Pod, nodeInfo *framework.NodeInfo) (int64, *framework.Status) {
sp.mutex.Lock()
defer sp.mutex.Unlock()