Skip to content

Conversation

@ouyangshengjia
Copy link
Contributor

@ouyangshengjia ouyangshengjia commented Jul 24, 2025

What type of PR is this?

/kind bug

What this PR does / why we need it:

volcano-scheduler with the startup argument --csi-storage=false(the argument defaults false), will panic when scheduling Pods with delayed binding PVCs.

Which issue(s) this PR fixes:

Fixes #4480

Special notes for your reviewer:

@JesseStutler

Does this PR introduce a user-facing change?

NONE

@volcano-sh-bot volcano-sh-bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jul 24, 2025
Copy link

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

Choose a reason for hiding this comment

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

Summary of Changes

Hello @ouyangshengjia, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request provides a crucial bug fix for the Volcano scheduler, resolving a panic that previously occurred when scheduling Pods that use delayed binding PersistentVolumeClaims. The root cause was an attempt to perform storage capacity checks even when the CSI storage feature was explicitly disabled. The changes introduce a safeguard to prevent these unnecessary checks under such conditions, thereby ensuring the scheduler's stability and correct operation.

Highlights

  • Bug Fix: Addresses a critical panic in the Volcano scheduler that occurred when scheduling Pods with delayed binding PersistentVolumeClaims (PVCs), specifically when the --csi-storage feature was disabled (which is its default setting).
  • Conditional Logic: Introduces a new conditional check at the beginning of the hasEnoughCapacity function in pkg/scheduler/capabilities/volumebinding/binder.go. This check ensures that if capacityCheckEnabled is false, the function immediately returns true (indicating sufficient capacity) and nil for capacity and error, bypassing the problematic capacity check logic.
  • Testing: Adds a new unit test, TestBinderWithCapacityCheckDisabled, to pkg/scheduler/capabilities/volumebinding/binder_test.go. This test verifies that the hasEnoughCapacity function behaves as expected when the capacity check feature is disabled, confirming the bug fix.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@volcano-sh-bot volcano-sh-bot added the kind/bug Categorizes issue or PR as related to a bug. label Jul 24, 2025
Copy link

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

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 correctly fixes a panic in the Volcano scheduler that occurs when scheduling pods with delayed binding PVCs and CSI storage is disabled. The fix involves adding a check to bypass capacity validation when the feature is disabled, which prevents a nil pointer dereference. A new test case has been added to cover this scenario, and I've suggested an improvement to this test to make it more robust. Overall, the change is good and addresses the reported issue effectively.

Comment on lines +980 to +984
// This is an optional feature. If disabled, we assume that
// there is enough storage.
if !b.capacityCheckEnabled {
return true, nil, nil
}

Choose a reason for hiding this comment

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

medium

This check prevents a nil pointer dereference when b.capacityCheckEnabled is false. This is a good defensive programming practice.

Comment on lines +2361 to +2376
func TestBinderWithCapacityCheckDisabled(t *testing.T) {
logger, ctx := ktesting.NewTestContext(t)
ctx, cancel := context.WithCancel(ctx)
defer cancel()

binder := &volumeBinder{
capacityCheckEnabled: false,
}
sufficient, _, err := binder.hasEnoughCapacity(logger, "", nil, nil, nil)
if err != nil {
t.Errorf("returned error: %v", err)
}
if !sufficient {
t.Error("expected sufficient, got insufficient")
}
}

Choose a reason for hiding this comment

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

medium

While this test passes with the fix, it's a bit brittle because it passes nil for the claim parameter. This would cause a panic on claim.Spec if the capacityCheckEnabled check wasn't at the very beginning of the function.

To make the test more robust and accurately reflect the scenario that caused the original panic (accessing a nil csiDriverLister), it would be better to pass a valid claim with a storage request. This ensures we are testing the intended logic path.

This change will make the test more resilient to future code refactoring.

logger, ctx := ktesting.NewTestContext(t)
ctx, cancel := context.WithCancel(ctx)
defer cancel()

binder := &volumeBinder{
	capacityCheckEnabled: false,
}

// A PVC with a storage request is needed to get past the first check in hasEnoughCapacity
// and properly test the scenario where csiDriverLister would be accessed.
pvc := makeTestPVC("test-pvc", "1Gi", "", pvcUnbound, "", "1", &waitClassWithProvisioner)
sufficient, _, err := binder.hasEnoughCapacity(logger, provisioner, pvc, &storagev1.StorageClass{}, nil)
if err != nil {
	t.Errorf("returned error: %v", err)
}
if !sufficient {
	t.Error("expected sufficient, got insufficient")
}

@JesseStutler
Copy link
Member

/lgtm
/cc @Monokaix

@volcano-sh-bot volcano-sh-bot requested a review from Monokaix July 25, 2025 01:34
@volcano-sh-bot volcano-sh-bot added the lgtm Indicates that a PR is ready to be merged. label Jul 25, 2025
@Monokaix
Copy link
Member

/approve

@volcano-sh-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Monokaix

The full list of commands accepted by this bot can be found here.

The pull request process is described here

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 Jul 25, 2025
@Monokaix
Copy link
Member

Please also cherry-pick to release1.12

@volcano-sh-bot volcano-sh-bot merged commit 9140855 into volcano-sh:master Jul 25, 2025
19 checks passed
@ouyangshengjia ouyangshengjia deleted the pvc-panic branch July 25, 2025 03:38
@ouyangshengjia
Copy link
Contributor Author

Please also cherry-pick to release1.12

@Monokaix This bug was introduced by the feature "adapt k8s 1.33". It does not exist in release1.12.

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. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Volcano scheduler panic when scheduling Pods with delayed binding PVCs

4 participants