Skip to content

feat: add nodegroup resource limits#5461

Open
ruanwenjun wants to merge 1 commit into
volcano-sh:masterfrom
ruanwenjun:codex/nodegroup-resource-limits-upstream
Open

feat: add nodegroup resource limits#5461
ruanwenjun wants to merge 1 commit into
volcano-sh:masterfrom
ruanwenjun:codex/nodegroup-resource-limits-upstream

Conversation

@ruanwenjun

Copy link
Copy Markdown
Contributor

Summary

  • Add volcano.sh/nodegroup-resource-limits queue annotation to cap queue usage per nodegroup.
  • Track allocated resources by queue + nodegroup in the nodegroup plugin and reject nodes when future usage would exceed the configured limit.
  • Add unit tests for no annotation, under-limit scheduling, fallback after preferred nodegroup reaches its logical limit, invalid annotation handling, and allocation event accounting.
  • Document the new annotation in the nodegroup plugin user guide.

Closes #4954

Test Plan

  • go test ./pkg/scheduler/plugins/nodegroup

Copilot AI review requested due to automatic review settings June 17, 2026 05:36
@volcano-sh-bot volcano-sh-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 17, 2026

Copilot AI 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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds per-queue, per-nodegroup resource limits to the nodegroup scheduler plugin using a queue annotation, with supporting tests and documentation.

Changes:

  • Parse volcano.sh/nodegroup-resource-limits from queue annotations and enforce limits during predicate evaluation.
  • Track per-(queue,nodegroup) allocated resources across session open and allocation/deallocation events.
  • Add unit tests and user-guide documentation for the new annotation behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
pkg/scheduler/plugins/nodegroup/nodegroup.go Implements annotation parsing, allocation accounting, and predicate-time enforcement of per-nodegroup limits.
pkg/scheduler/plugins/nodegroup/errors.go Adds new scheduling failure reasons for invalid/exceeded resource limits.
pkg/scheduler/plugins/nodegroup/nodegroup_test.go Adds tests for limit enforcement and allocation event updates.
docs/user-guide/how_to_use_nodegroup_plugin.md Documents the new queue annotation format and scheduling semantics.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 413 to +418
return fmt.Errorf("job %s not found in session", task.Job)
}
attr := np.queueAttrs[job.Queue]
if attr.resourceLimitErr != nil {
return newFitErr(task, node, errNodeGroupResourceLimitInvalid)
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in the latest push by making the resourceLimitErr check nil-safe before reading it.

Comment on lines +532 to +536
err := ssn.PredicateFn(targetTask, node)
code := api.Success
if err != nil {
code = err.(*api.FitError).Status[0].Code
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in the latest push by using errors.As and failing the test with the unexpected error type.

Comment on lines +519 to +526
for _, job := range ssn.Jobs {
for _, task := range job.Tasks {
if task.Name == test.targetTaskName {
targetTask = task
break
}
}
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in the latest push with a labeled break once the target task is found.

@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 introduces a feature to configure queue resource limits for each nodegroup via the volcano.sh/nodegroup-resource-limits annotation, updating the documentation, scheduler plugin logic, and adding corresponding unit tests. The review feedback highlights a potential nil pointer dereference in nodegroup.go where attr.resourceLimitErr is accessed without a nil check on attr.

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.

return fmt.Errorf("job %s not found in session", task.Job)
}
attr := np.queueAttrs[job.Queue]
if attr.resourceLimitErr != nil {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

A nil pointer dereference will occur here if attr is nil. In Volcano, job.Queue might not always be present in np.queueAttrs (for example, if the queue is not found in the session), which is why other parts of this plugin explicitly check for attr == nil (e.g., line 421).

Please add a nil check for attr before accessing attr.resourceLimitErr.

Suggested change
if attr.resourceLimitErr != nil {
if attr != nil && attr.resourceLimitErr != nil {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in the latest push by guarding attr before checking resourceLimitErr.

@ruanwenjun ruanwenjun force-pushed the codex/nodegroup-resource-limits-upstream branch from ab2708f to 9e0926b Compare June 17, 2026 05:40
@ruanwenjun ruanwenjun requested a review from Copilot June 17, 2026 05:57

Copilot AI 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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment on lines +353 to +365
limit := attr.nodeGroupResourceLimits[group]
if limit == nil {
return nil
}

allocated := attr.nodeGroupAllocated[group]
if allocated == nil {
allocated = api.EmptyResource()
}
futureUsed := allocated.Clone().Add(task.Resreq)
if ok, resourceNames := futureUsed.LessEqualWithDimensionAndResourcesName(limit, task.Resreq); !ok {
return fmt.Errorf("nodegroup %s resource limit exceeded, insufficient resources: %v", group, resourceNames)
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in the latest push by preserving the resource keys explicitly configured for each nodegroup and comparing only those dimensions. Added CPU-only limit tests for omitted memory and CPU enforcement.

if !errors.As(err, &fitErr) {
t.Fatalf("expected *api.FitError, got %T: %v", err, err)
}
return fitErr.Status[0].Code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in the latest push by checking that FitError.Status is non-empty before reading the first status code.

@ruanwenjun ruanwenjun force-pushed the codex/nodegroup-resource-limits-upstream branch from 9e0926b to 34a4c29 Compare June 18, 2026 01:48
@volcano-sh-bot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign lowang-bh for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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 size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 18, 2026
@ruanwenjun ruanwenjun force-pushed the codex/nodegroup-resource-limits-upstream branch from 34a4c29 to 75f9ffb Compare June 18, 2026 08:06

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

/area scheduling

Thanks for the PR, cool feature, this is a nice addition to the nodegroup plugin. The limit accounting path is now much clearer, the edge cases from the previous bot comments look covered, and the docs/tests make the new Queue annotation behavior easy to follow. I left one API-surface comment about where the public volcano.sh/* keys should live before this gets finalized.

Great work!

NodeGroupNameKey = "volcano.sh/nodegroup-name"
rootQueueID = "root"

nodeGroupResourceLimitsAnnotationKey = "volcano.sh/nodegroup-resource-limits"

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.

Since both of these are user-facing volcano.sh/* keys, can we move them to the official scheduling API constants under staging/src/volcano.sh/apis/pkg/apis/scheduling/v1beta1/labels.go and reference them from here? NodeGroupNameKey is already used as an external node label key, and volcano.sh/nodegroup-resource-limits is now a documented Queue annotation, so keeping the literals private to the plugin makes the public API surface harder to discover and easier to duplicate later.

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.

Yes export this as a const in the staging/src/volcano.sh/apis just as mate said will be better

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved both user-facing keys to scheduling v1beta1 API constants in labels.go and updated the nodegroup plugin/tests to reference schedulingv1.NodeGroupNameKey and schedulingv1.NodeGroupResourceLimitsAnnotationKey.

@JesseStutler

Copy link
Copy Markdown
Member

/cc Will take a look in recent days

@volcano-sh-bot

Copy link
Copy Markdown
Contributor

@JesseStutler: GitHub didn't allow me to request PR reviews from the following users: in, recent, days, Will, take, a, look.

Note that only volcano-sh members and repo collaborators can review this PR, and authors cannot review their own PRs.

Details

In response to this:

/cc Will take a look in recent days

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Signed-off-by: ruanwenjun <wenjun@apache.org>
@ruanwenjun ruanwenjun force-pushed the codex/nodegroup-resource-limits-upstream branch from 75f9ffb to f3a1bf1 Compare June 26, 2026 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/scheduling size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

Support for Queue-level Quotas per Node Group to enable logical resource overflow.

5 participants