Skip to content

feat(scheduler): correct resource accounting for init containers - #1773

Merged
archlitchi merged 34 commits into
Project-HAMi:masterfrom
maishivamhoo123:fix/nodelock-time-parsec
Aug 10, 2026
Merged

feat(scheduler): correct resource accounting for init containers#1773
archlitchi merged 34 commits into
Project-HAMi:masterfrom
maishivamhoo123:fix/nodelock-time-parsec

Conversation

@maishivamhoo123

@maishivamhoo123 maishivamhoo123 commented Apr 18, 2026

Copy link
Copy Markdown
Member

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

    • Improved device scheduling, scoring, and allocation for pods with init containers, including safer usage accounting/rollback, correct slot handling, and clearer failure reporting.
    • Updated admission and resource quota logic to properly evaluate init-container resource requirements and reflect more accurate denial reasons.
    • Made generated reason output deterministic for consistent messaging.
  • Tests

    • Expanded scheduler filtering/scoring and webhook quota tests for init-container scenarios (including insufficiency and tie-handling), with updated expected failure reasons.

@github-actions github-actions Bot added the kind/bug Something isn't working label Apr 18, 2026
@hami-robot hami-robot Bot added the size/L label Apr 18, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

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.

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.

Comment thread pkg/scheduler/score.go Outdated
Comment thread pkg/scheduler/score.go Outdated
@codecov

codecov Bot commented Apr 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.73696% with 107 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/scheduler/scheduler.go 54.23% 19 Missing and 8 partials ⚠️
pkg/scheduler/score.go 87.76% 18 Missing and 5 partials ⚠️
pkg/device/quota.go 26.92% 16 Missing and 3 partials ⚠️
pkg/device/pods.go 51.35% 16 Missing and 2 partials ⚠️
pkg/scheduler/webhook.go 60.00% 7 Missing and 1 partial ⚠️
pkg/util/util.go 0.00% 7 Missing ⚠️
pkg/scheduler/policy/node_policy.go 40.00% 2 Missing and 1 partial ⚠️
pkg/device/common/common.go 0.00% 1 Missing ⚠️
pkg/device/nvidia/device.go 94.44% 0 Missing and 1 partial ⚠️
Flag Coverage Δ
unittests 63.56% <75.73%> (+0.18%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
pkg/device/initContainer.go 100.00% <100.00%> (ø)
pkg/device/common/common.go 50.00% <0.00%> (-3.34%) ⬇️
pkg/device/nvidia/device.go 97.00% <94.44%> (+0.03%) ⬆️
pkg/scheduler/policy/node_policy.go 93.18% <40.00%> (-6.82%) ⬇️
pkg/util/util.go 71.05% <0.00%> (-2.26%) ⬇️
pkg/scheduler/webhook.go 70.40% <60.00%> (-13.55%) ⬇️
pkg/device/pods.go 86.33% <51.35%> (-10.83%) ⬇️
pkg/device/quota.go 72.92% <26.92%> (-2.67%) ⬇️
pkg/scheduler/score.go 89.17% <87.76%> (-2.93%) ⬇️
pkg/scheduler/scheduler.go 68.26% <54.23%> (-0.93%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@maishivamhoo123

Copy link
Copy Markdown
Member Author

@archlitchi , @DSFans2014 , @Shouren and @member can you please review this PR.

@Shouren

Shouren commented Apr 21, 2026

Copy link
Copy Markdown
Member

@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.

@maishivamhoo123

maishivamhoo123 commented Apr 26, 2026

Copy link
Copy Markdown
Member Author

@Shouren can you please check this google docs.

@maishivamhoo123

Copy link
Copy Markdown
Member Author
Screenshot 2026-04-27 021917

@Shouren can you please check this [https://docs.google.com/document/d/1nX1FlJEiZ8lNKOAOuZHtiUs4OSwj5VJxVE1cU0y1LEU/edit?usp=sharing](Google Docs).

@Shouren

Shouren commented Apr 28, 2026

Copy link
Copy Markdown
Member

@Shouren can you please check this google docs.

@maishivamhoo123 Can you show me the Pod Annotations after a successful scheduling?

Comment thread pkg/scheduler/score.go Outdated
@maishivamhoo123

Copy link
Copy Markdown
Member Author

@Shouren can you please review this PR?

@archlitchi

Copy link
Copy Markdown
Member

hi, since i just got this PR merged:#1818, does this one needs to adjust?

@maishivamhoo123

Copy link
Copy Markdown
Member Author

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>
Comment thread pkg/scheduler/webhook.go

@DSFans2014 DSFans2014 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

@hami-robot hami-robot Bot added the lgtm label Aug 10, 2026

@archlitchi archlitchi 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

@archlitchi archlitchi 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

@hami-robot

hami-robot Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

[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

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

@archlitchi
archlitchi merged commit 9e75c87 into Project-HAMi:master Aug 10, 2026
16 checks passed
@maishivamhoo123
maishivamhoo123 deleted the fix/nodelock-time-parsec branch August 10, 2026 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants