[release-1.15] fix: use milli-units for scalar in-queue resources - #5499
Conversation
Signed-off-by: WHOIM1205 <rathourprateek8@gmail.com>
…lar units Signed-off-by: WHOIM1205 <rathourprateek8@gmail.com>
Signed-off-by: WHOIM1205 <rathourprateek8@gmail.com>
Signed-off-by: WHOIM1205 <rathourprateek8@gmail.com>
There was a problem hiding this comment.
Code Review
This pull request refactors GetInqueueResource to use the canonical unit model when calculating reserved (in-queue) resources, ensuring scalar resources like GPUs (milli-units) and pods (whole units) are computed correctly. It also introduces a comprehensive suite of unit tests. The review feedback highlights a critical issue where job, job.PodGroup, job.PodGroup.Spec.MinResources, or allocated could be nil, potentially causing a nil pointer dereference panic, and provides a code suggestion to safely handle these cases.
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.
| func GetInqueueResource(job *api.JobInfo, allocated *api.Resource) *api.Resource { | ||
| minResources := api.NewResource(*job.PodGroup.Spec.MinResources) |
There was a problem hiding this comment.
The function GetInqueueResource dereferences job.PodGroup.Spec.MinResources without checking if job, job.PodGroup, or job.PodGroup.Spec.MinResources is nil. Since job.PodGroup can be nil (for example, after calling UnsetPodGroup), this can lead to a nil pointer dereference panic. Additionally, allocated should be checked for nil to prevent panics when accessing its fields.
func GetInqueueResource(job *api.JobInfo, allocated *api.Resource) *api.Resource {
if job == nil || job.PodGroup == nil || job.PodGroup.Spec.MinResources == nil {
return api.EmptyResource()
}
if allocated == nil {
allocated = api.EmptyResource()
}
minResources := api.NewResource(*job.PodGroup.Spec.MinResources)There was a problem hiding this comment.
This is valid but I don't think this needs to block this cherry-pick.
The production call sites already dereference job.PodGroup and check job.PodGroup.Spec.MinResources != nil before calling GetInqueueResource, and scheduler snapshots skip jobs without PodGroups. allocated is passed as job.Allocated, which is initialized on JobInfo.
So the nil check would only make this helper more defensive for artificial/direct calls; it would not fix a currently reachable panic path introduced by this PR. Since this is a release-branch cherry-pick, I prefer keeping it focused on the scalar-resource accounting fix.
hajnalmt
left a comment
There was a problem hiding this comment.
/lgtm
/approve
/label tide/merge-method-squash
| func GetInqueueResource(job *api.JobInfo, allocated *api.Resource) *api.Resource { | ||
| minResources := api.NewResource(*job.PodGroup.Spec.MinResources) |
There was a problem hiding this comment.
This is valid but I don't think this needs to block this cherry-pick.
The production call sites already dereference job.PodGroup and check job.PodGroup.Spec.MinResources != nil before calling GetInqueueResource, and scheduler snapshots skip jobs without PodGroups. allocated is passed as job.Allocated, which is initialized on JobInfo.
So the nil check would only make this helper more defensive for artificial/direct calls; it would not fix a currently reachable panic path introduced by this PR. Since this is a release-branch cherry-pick, I prefer keeping it focused on the scalar-resource accounting fix.
|
/approve |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: hajnalmt, JesseStutler The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
This is an automated cherry-pick of #5391