Skip to content

[release-1.15] fix(scheduler): display maxFloat/maxInt in Resource.String() for infinite values - #5478

Merged
volcano-sh-bot merged 3 commits into
volcano-sh:release-1.15from
volcano-sh-bot:cherry-pick-5276-to-release-1.15
Jun 22, 2026
Merged

[release-1.15] fix(scheduler): display maxFloat/maxInt in Resource.String() for infinite values#5478
volcano-sh-bot merged 3 commits into
volcano-sh:release-1.15from
volcano-sh-bot:cherry-pick-5276-to-release-1.15

Conversation

@volcano-sh-bot

Copy link
Copy Markdown
Contributor

This is an automated cherry-pick of #5276

Signed-off-by: r0hansaxena <rohansxn8772@gmail.com>
Signed-off-by: r0hansaxena <rohansxn8772@gmail.com>
Signed-off-by: r0hansaxena <rohansxn8772@gmail.com>
@volcano-sh-bot volcano-sh-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jun 20, 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 Resource.String() method to use strings.Builder for improved performance and adds formatting logic to handle maximum float and integer values. It also introduces comprehensive unit tests to verify these changes. The review feedback suggests adding a defensive nil check at the beginning of the String() method to prevent potential nil pointer dereference 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 170 to +171
func (r *Resource) String() string {
str := fmt.Sprintf("cpu %0.2f, memory %0.2f", r.MilliCPU, r.Memory)
// Sort scalar resource names to ensure consistent string output
format := func(val float64) string {

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 r is nil, calling r.String() will result in a nil pointer dereference panic when accessing r.MilliCPU or r.Memory. Since String() is commonly called implicitly during logging (e.g., via fmt or klog), it is safer to add a defensive nil check at the beginning of the method to prevent potential scheduler crashes.

Suggested change
func (r *Resource) String() string {
str := fmt.Sprintf("cpu %0.2f, memory %0.2f", r.MilliCPU, r.Memory)
// Sort scalar resource names to ensure consistent string output
format := func(val float64) string {
func (r *Resource) String() string {
if r == nil {
return ""
}
format := func(val float64) string {

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.

float will default to 0 for both values on initialization, but I get the defensive programming idea.

@hajnalmt hajnalmt left a comment

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.

/lgtm
/approve

Comment on lines 170 to +171
func (r *Resource) String() string {
str := fmt.Sprintf("cpu %0.2f, memory %0.2f", r.MilliCPU, r.Memory)
// Sort scalar resource names to ensure consistent string output
format := func(val float64) string {

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.

float will default to 0 for both values on initialization, but I get the defensive programming idea.

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

Copy link
Copy Markdown
Member

/approve

@volcano-sh-bot

Copy link
Copy Markdown
Contributor Author

[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

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 22, 2026
@volcano-sh-bot
volcano-sh-bot merged commit 69d5557 into volcano-sh:release-1.15 Jun 22, 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/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants