feat(scheduler): correct resource accounting for init containers - #1773
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces support for Kubernetes InitContainers within the scheduler and admission webhook. It updates the resource calculation logic in the Filter and fitResourceQuota functions to use the maximum of the largest init container's request and the sum of regular containers' requests, aligning with standard Kubernetes behavior. Additionally, the scoring logic in calcScore now utilizes a node state cloning mechanism to ensure init containers are evaluated against the node's full capacity. Review feedback suggests handling potential errors during JSON unmarshaling and optimizing the cloning process to avoid unnecessary performance overhead for pods that do not contain init containers.
|
@archlitchi , @DSFans2014 , @Shouren and @member can you please review this PR. |
@maishivamhoo123 I am busy testing the recent updates for k8s-dra-driver, i will be back when the tests are finished. |
|
@Shouren can you please check this google docs. |
|
@maishivamhoo123 Can you show me the Pod Annotations after a successful scheduling? |
|
@Shouren can you please review this PR? |
|
hi, since i just got this PR merged:#1818, does this one needs to adjust? |
Yes i need to change the JSON serialization logic to deep copy function i will change and let you know . Thank you! |
Signed-off-by: maishivamhoo123 <maishivamhoo@gmail.com>
Signed-off-by: maishivamhoo123 <maishivamhoo@gmail.com>
Signed-off-by: maishivamhoo123 <maishivamhoo@gmail.com>
Signed-off-by: maishivamhoo123 <maishivamhoo@gmail.com>
Signed-off-by: maishivamhoo123 <maishivamhoo@gmail.com>
d443f9e to
f6cc3d6
Compare
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: archlitchi, maishivamhoo123 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 |

I fixed the resource accounting logic for pods with Init Containers: the scheduler now correctly calculates the effective request as$max(\sum \text{App Containers}, \text{max}(\text{Init Containers}))$ . This prevents incorrect "node full" errors or quota denials for pods that reuse GPU resources during initialization.Technically, I modernized the codebase for Go 1.22+ by:Using the built-in max() function instead of manual if blocks.Implementing range over integers for cleaner loops.Removing redundant type declarations to satisfy staticcheck.Finally, I updated the unit tests in scheduler_test.go and score_test.go. Since the scoring logic now accurately reflects node utilization under the Binpack strategy, I adjusted the expected device UUIDs (e.g., device1 $\rightarrow$ device3) to match the scheduler's optimized selection. These changes ensure the HAMi scheduler is both logically sound and compliant with modern Go standards.
Fixes :- #1667
Summary by CodeRabbit
Bug Fixes
Tests