Skip to content

Add unit tests for gpu-kubelet-plugin/sharing.go - #1471

Open
vishalanarase wants to merge 3 commits into
kubernetes-sigs:mainfrom
vishalanarase:test/unit-tests-gpu-kubelet-plugin-sharing
Open

vishalanarase wants to merge 3 commits into
kubernetes-sigs:mainfrom
vishalanarase:test/unit-tests-gpu-kubelet-plugin-sharing

Conversation

@vishalanarase

@vishalanarase vishalanarase commented Sep 21, 2026 •

Copy link
Copy Markdown
Member

What type of PR is this?

/kind cleanup
/kind bug

What this PR does / why we need it:

Cover the time-slicing and MPS paths that need no GPU or privileges: ID derivation, the control daemon lifecycle helpers, deployment rendering against the shipped template, and the reachable Start/Stop branches.

cmd/gpu-kubelet-plugin/sharing.go had two tests (setMpsShmMountPath and the image-pull settings of the rendered deployment). This adds coverage for the rest of the file

Which issue(s) this PR is related to:

Fixes #1309 Part of #1297

Special notes for your reviewer:

Does this PR introduce a user-facing change?

NONE

NONE

Additional documentation (design docs, usage docs, etc.):

NONE

Checklist

  • make check test passes locally
  • make check-generate passes if api/ changed (CRDs, deepcopy, informers, listers, clientset)
  • make check-modules passes if go.mod / go.sum changed
  • Tests added or updated for the change
  • Helm chart (deployments/helm) updated if flags, RBAC, or defaults changed

Cover the time-slicing and MPS paths that need no GPU or privileges: ID
derivation, the control daemon lifecycle helpers, deployment rendering
against the shipped template, and the reachable Start/Stop branches.

Start and Stop stay partially covered, as mounting the shm tmpfs needs
CAP_SYS_ADMIN; getDefaultShmSize reads /proc/meminfo directly and is
left untested.

Signed-off-by: Vishal Anarase <iamvishalanarase@gmail.com>
@kubernetes-prow kubernetes-prow Bot added release-note-none Denotes a PR that doesn't merit a release note. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. labels Sep 21, 2026
@kubernetes-prow kubernetes-prow Bot added the kind/bug Categorizes issue or PR as related to a bug. label Sep 21, 2026
@netlify

netlify Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

👷 Deploy request for dra-driver-nvidia-gpu pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 8acc8c6

@kubernetes-prow
kubernetes-prow Bot requested a review from klueska September 21, 2026 07:59
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: vishalanarase
Once this PR has been reviewed and has the lgtm label, please assign dims for approval. For more information see the 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

@kubernetes-prow
kubernetes-prow Bot requested a review from shengnuo September 21, 2026 07:59
@kubernetes-prow kubernetes-prow Bot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Sep 21, 2026
@vishalanarase

Copy link
Copy Markdown
Member Author

When you get a chance, could you please take a look at this PR? I’d appreciate your review and feedback. Thanks!
cc: @klueska @shengnuo

@vishalanarase

Copy link
Copy Markdown
Member Author

Just following up on this PR, as it's still pending review. Could you please take a look when you get a chance? Thanks!
CC: @klueska @shengnuo

@vishalanarase

vishalanarase commented Nov 18, 2026 •

Copy link
Copy Markdown
Member Author

This PR has been awaiting review for over month, and I've already followed up a couple of times.

Could someone please prioritise the review and share feedback? I'd appreciate getting this moving forward.

Comment thread cmd/gpu-kubelet-plugin/sharing_test.go Resolved
Comment thread cmd/gpu-kubelet-plugin/sharing_test.go Resolved
Comment thread cmd/gpu-kubelet-plugin/sharing_test.go Resolved
@shivamerla

Copy link
Copy Markdown
Contributor

Thanks for your patience, and sorry for the delay. These are solid tests: they check real behavior, and rendering the real template catches broken YAML. I left a few small comments. Dropping the bug label since this only adds tests.

/remove-kind bug

@kubernetes-prow kubernetes-prow Bot removed the kind/bug Categorizes issue or PR as related to a bug. label Nov 20, 2026
…nit-tests-gpu-kubelet-plugin-sharing

Signed-off-by: Vishal Anarase <iamvishalanarase@gmail.com>
Clear LD_PRELOAD for every fake nvidia-smi case, use client-go's
NewClientset, and note that the MPS Start success path is covered by
the GPU sharing bats tests.

Signed-off-by: Vishal Anarase <iamvishalanarase@gmail.com>
@kubernetes-prow

Copy link
Copy Markdown
Contributor

Adding label do-not-merge/contains-merge-commits because PR contains merge commits, which are not allowed in this repository.
Use git rebase to reapply your commits on top of the target branch. Detailed instructions for doing so can be found here.

Details

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-sigs/prow repository.

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The PR adds unit tests for GPU time-slicing and MPS sharing. The tests cover time-slice command behavior, MPS daemon configuration and identifiers, Deployment rendering and lookup, CDI edits, and startup, readiness, and stop outcomes. The changes are limited to tests and do not alter production behavior.

Possibly related issues

Merge Risk: Minimal · up to 8acc8

This change adds tests for GPU time-slicing and MPS sharing and leaves runtime behavior untouched. No user or production impact is expected, and no merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: adding unit tests for gpu-kubelet-plugin/sharing.go. The raw summary confirms the PR adds tests and fixtures for time-slicing and MPS paths in sharing_test.go, so the …
Description check Passed The description states the PR adds coverage for time-slicing and MPS paths in sharing.go, including ID derivation, control-daemon lifecycle helpers, deployment rendering, and Start/Stop branches. This…
Linked Issues check Passed [#1309] requests unit tests for cmd/gpu-kubelet-plugin/sharing.go. The reviewed diff adds 736 lines of tests to cmd/gpu-kubelet-plugin/sharing_test.go with no production code change. The added tests c…
Out of Scope Changes check Passed All visible changes are test code in cmd/gpu-kubelet-plugin/sharing_test.go. They add test helpers (fakeUUIDProvider, testConfig, mpsDeployment, templatePath), new imports for test dependencies, and t…
Full details: Title check

Explanation

The title names the main change: adding unit tests for gpu-kubelet-plugin/sharing.go. The raw summary confirms the PR adds tests and fixtures for time-slicing and MPS paths in sharing_test.go, so the title matches the changeset.

Full details: Description check

Explanation

The description states the PR adds coverage for time-slicing and MPS paths in sharing.go, including ID derivation, control-daemon lifecycle helpers, deployment rendering, and Start/Stop branches. This matches the raw summary of sharing_test.go. It also links the related issues.

Full details: Linked Issues check

Explanation

[#1309] requests unit tests for cmd/gpu-kubelet-plugin/sharing.go. The reviewed diff adds 736 lines of tests to cmd/gpu-kubelet-plugin/sharing_test.go with no production code change. The added tests cover: osFileChecker.Stat; NewTimeSlicingManager; TimeSlicingManager.SetTimeSlice (DEFAULT reset ordering, interval-to-nvidia-smi mapping, empty UUID list, nvidia-smi failure paths); NewMpsManager; GetMpsControlDaemonID (stability, claim UID, device set, device order, MIG contribution); NewMpsControlDaemon; IsControlDaemonStarted/IsControlDaemonStopped (existing, absent, other namespace, API error); and renderMpsControlDaemonDeployment against templates/mps-control-daemon.tmpl.yaml. These are the unit-testable sharing.go paths the issue targets. Gaps: the MPS Start success path and getDefaultShmSize are not unit tested. The PR description states these need a GPU, privileges, or /proc/meminfo, and the linked issue sets no coverage target, so these gaps do not fail the issue requirement. The root diff output was truncated after sharing_test.go, so files later in path order were not directly confirmed. The raw summary reports only this file changed.

Full details: Out of Scope Changes check

Explanation

All visible changes are test code in cmd/gpu-kubelet-plugin/sharing_test.go. They add test helpers (fakeUUIDProvider, testConfig, mpsDeployment, templatePath), new imports for test dependencies, and test functions for sharing.go. Each change maps to the sharing.go unit-test objective of [#1309]. No production code, API types, chart, or template changes appear in the diff. The root diff was truncated after this file, so later paths were not directly confirmed; the change summary reports only this file.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 5da6f62 and 8acc8c6.

Files selected for processing: 1

  • cmd/gpu-kubelet-plugin/sharing_test.go

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

@vishalanarase

Copy link
Copy Markdown
Member Author

Thanks for your patience, and sorry for the delay. These are solid tests: they check real behavior, and rendering the real template catches broken YAML. I left a few small comments. Dropping the bug label since this only adds tests.

/remove-kind bug

Thanks for the review. I addressed the three comments: LD_PRELOAD is cleared for every fake nvidia-smi case, the tests use NewClientset, and TestMpsControlDaemonStart notes that the success path needs a real tmpfs mount and root and is covered by tests/bats/test_gpu_sharing.bats.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/contains-merge-commits kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

[Unit Test] Add unit tests for gpu-kubelet-plugin/sharing.go

2 participants