[release-1.15] fix(scheduler): display maxFloat/maxInt in Resource.String() for infinite values - #5478
Conversation
Signed-off-by: r0hansaxena <rohansxn8772@gmail.com>
Signed-off-by: r0hansaxena <rohansxn8772@gmail.com>
Signed-off-by: r0hansaxena <rohansxn8772@gmail.com>
There was a problem hiding this comment.
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.
| 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 { |
There was a problem hiding this comment.
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.
| 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 { |
There was a problem hiding this comment.
float will default to 0 for both values on initialization, but I get the defensive programming idea.
| 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 { |
There was a problem hiding this comment.
float will default to 0 for both values on initialization, but I get the defensive programming idea.
|
/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 #5276