Skip to content

[release-1.15] fix(nodeorder): reuse session NodeMap and unify Score plugins through BatchNodeOrderFn - #5562

Merged
volcano-sh-bot merged 3 commits into
volcano-sh:release-1.15from
volcano-sh-bot:cherry-pick-5497-to-release-1.15
Jul 3, 2026
Merged

[release-1.15] fix(nodeorder): reuse session NodeMap and unify Score plugins through BatchNodeOrderFn#5562
volcano-sh-bot merged 3 commits into
volcano-sh:release-1.15from
volcano-sh-bot:cherry-pick-5497-to-release-1.15

Conversation

@volcano-sh-bot

Copy link
Copy Markdown
Contributor

This is an automated cherry-pick of #5497

NONE

The batch path used to build an fwk.NodeInfo per scored node via
SetNode(node.Node), which leaves Allocatable/Requested unset. Any
Score plugin that reads those fields would nil-panic if added to
the batch path.

This commit changes:
1. Pass ssn.NodeMap into BatchNodeOrderFn and look up the populated
   NodeInfo from it instead of constructing a new one.
2. Pass GetSnapshot().GetFwkNodeInfoMap() the same way in the agent
   scheduler nodeorder plugin.

Signed-off-by: JesseStutler <chenzicong4@huawei.com>
pprof shows noderesources.Fit and BalancedAllocation recomputing the
pod resource request on every per-node Score call, because the
NodeOrderFn path skips PreScore. Plugins registered via the batch
path go through nodescore.CalculatePluginScore, which runs PreScore
once per batch and caches the parsed state.

This commit changes:
1. Move Fit (Least/Most), BalancedAllocation and NodeAffinity from
   NodeOrderScorePlugins to ScorePlugins so they take the batch path.
   ImageLocality has no PreScore upstream and stays where it is.
2. Introduce scorePluginEntry to bundle plugin + normalizer + weight,
   and replace the per-plugin interPodAffinityScore /
   taintTolerationScore / podTopologySpreadScore wrappers with a
   single iteration over ScorePlugins.
3. Update TestInitPlugin to match the new plugin layout.

Signed-off-by: JesseStutler <chenzicong4@huawei.com>
Signed-off-by: JesseStutler <chenzicong4@huawei.com>
@volcano-sh-bot
volcano-sh-bot requested review from Thor-wl and k82cn July 2, 2026 01:29
@volcano-sh-bot volcano-sh-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 2, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the node scoring mechanism in the Volcano scheduler by introducing a scorePluginEntry struct to encapsulate score plugins, their normalizers, and weights, and refactoring BatchNodeOrderFn to dynamically calculate scores. It also adds a helper function NodeInfosForCandidateNodes to reuse candidate node information, optimizing snapshot usage. The review feedback suggests defensive programming improvements to prevent potential nil pointer dereferences, specifically checking for nil nodeInfo in the helper function and falling back to an empty normalizer if a plugin's normalizer is nil.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +50 to +52
if nodeInfo, ok := nodeMap[node.Name]; ok {
nodeInfos = append(nodeInfos, nodeInfo)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To prevent potential nil pointer or nil interface dereference panics in downstream score plugins, we should defensively check if the retrieved nodeInfo interface is non-nil before appending it to the nodeInfos slice.

Suggested change
if nodeInfo, ok := nodeMap[node.Name]; ok {
nodeInfos = append(nodeInfos, nodeInfo)
}
if nodeInfo, ok := nodeMap[node.Name]; ok && nodeInfo != nil {
nodeInfos = append(nodeInfos, nodeInfo)
}

Comment on lines +373 to 377
for name, entry := range pp.ScorePlugins {
scores, err := nodescore.CalculatePluginScore(name, entry.plugin, entry.normalizer, state, task.Pod, nodeInfos, entry.weight)
if err != nil {
return nil, err
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If a score plugin is registered in pp.ScorePlugins but its normalizer field is left uninitialized (i.e., nil), calling CalculatePluginScore will result in a nil pointer dereference panic when NormalizeScore is invoked. We should defensively fall back to &nodescore.EmptyNormalizer{} if entry.normalizer is nil.

	for name, entry := range pp.ScorePlugins {
		normalizer := entry.normalizer
		if normalizer == nil {
			normalizer = &nodescore.EmptyNormalizer{}
		}
		scores, err := nodescore.CalculatePluginScore(name, entry.plugin, normalizer, state, task.Pod, nodeInfos, entry.weight)
		if err != nil {
			return nil, err
		}

@JesseStutler

Copy link
Copy Markdown
Member

/approve
/lgtm

@volcano-sh-bot volcano-sh-bot added the lgtm Indicates that a PR is ready to be merged. label Jul 3, 2026
@volcano-sh-bot

Copy link
Copy Markdown
Contributor Author

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JesseStutler

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@volcano-sh-bot volcano-sh-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 3, 2026
@volcano-sh-bot
volcano-sh-bot merged commit 69368d1 into volcano-sh:release-1.15 Jul 3, 2026
27 of 28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants