Skip to content

[release-1.15] fix ascend vnpu addResource#5377

Merged
volcano-sh-bot merged 2 commits into
volcano-sh:release-1.15from
volcano-sh-bot:cherry-pick-5363-to-release-1.15
Jun 9, 2026
Merged

[release-1.15] fix ascend vnpu addResource#5377
volcano-sh-bot merged 2 commits into
volcano-sh:release-1.15from
volcano-sh-bot:cherry-pick-5363-to-release-1.15

Conversation

@volcano-sh-bot

Copy link
Copy Markdown
Contributor

This is an automated cherry-pick of #5363


Signed-off-by: james <open4pd@4paradigm.com>
Signed-off-by: james <open4pd@4paradigm.com>
@volcano-sh-bot volcano-sh-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 4, 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 introduces a PodMap to the AscendDevice struct to track resource usage per pod, preventing duplicate additions or subtractions of resources for the same pod. It also updates AddResourceUsage and SubResourceUsage signatures, updates annotation keys from InRequestDevices to SupportDevices, and adds comprehensive unit tests for AddResource. The review feedback suggests adding a safety check to lazily initialize dev.PodMap if it is nil before writing to it, preventing potential runtime panics.

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 +208 to +216
if _, ok := dev.PodMap[string(pod.UID)]; !ok {
dev.PodMap[string(pod.UID)] = &devices.DeviceUsage{
Used: 1,
Usedcores: cono_dev.Usedcores,
Usedmem: cono_dev.Usedmem,
}
ads.AddResourceUsage(dev, cono_dev.Usedcores, cono_dev.Usedmem)
klog.V(5).Infof("add resource usage for pod %s. device %s usedmem %d", pod.Name, dev.DeviceInfo.ID, cono_dev.Usedmem)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

If dev.PodMap is nil, assigning a value to it will cause a runtime panic (panic: assignment to entry in nil map). Although PodMap is initialized in NewAscendDevices and DeepCopy, it is safer to lazily initialize it if it is nil to prevent potential panics if AscendDevice is constructed or modified elsewhere without proper initialization.

		if dev.PodMap == nil {
			dev.PodMap = make(map[string]*devices.DeviceUsage)
		}
		if _, ok := dev.PodMap[string(pod.UID)]; !ok {
			dev.PodMap[string(pod.UID)] = &devices.DeviceUsage{
				Used:      1,
				Usedcores: cono_dev.Usedcores,
				Usedmem:   cono_dev.Usedmem,
			}
			ads.AddResourceUsage(dev, cono_dev.Usedcores, cono_dev.Usedmem)
			klog.V(5).Infof("add resource usage for pod %s. device %s usedmem %d", pod.Name, dev.DeviceInfo.ID, cono_dev.Usedmem)
		}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@DSFans2014 Could you check it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

New instances of AscendDevice are created through NewAscendDevices, DeepCopy, and getDeviceSnapshot. All of these interfaces initialize the PodMap, so there will be no null pointer issues currently.
From the perspective of defensive programming, I can add null pointer checks.

@DSFans2014 DSFans2014 Jun 5, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I submitted a PR on the bot for this change: volcano-sh-bot#1. I'm not sure if this is the correct way to modify the bot's branch. If not, please let me know how to do it. @JesseStutler
I also have added this change to #5378 which will be merged to master

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Got it, If there are other places already init the struct, I think we can safely merge it, because AI may also have illusions and can't get the context of other places of codes

@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 Jun 9, 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 Jun 9, 2026
@volcano-sh-bot volcano-sh-bot merged commit 3553dab into volcano-sh:release-1.15 Jun 9, 2026
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.

3 participants