Skip to content

test(gpu-kubelet-plugin): add CDI unit test - #1442

Open
tico88612 wants to merge 4 commits into
kubernetes-sigs:mainfrom
tico88612:test/cdi
Open

tico88612 wants to merge 4 commits into
kubernetes-sigs:mainfrom
tico88612:test/cdi

Conversation

@tico88612

Copy link
Copy Markdown
Member

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

Added unit test for gpu-kubelet-plugin CDI

Which issue(s) this PR is related to:

Fixed #1303

Special notes for your reviewer:

Some code was assisted by AI. I've had a preliminary look.

Does this PR introduce a user-facing change?

NONE

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


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

@kubernetes-prow kubernetes-prow Bot added the release-note-none Denotes a PR that doesn't merit a release note. label Sep 10, 2026
@kubernetes-prow kubernetes-prow Bot added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Sep 10, 2026
@netlify

netlify Bot commented Sep 10, 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 3d42525

@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: tico88612
Once this PR has been reviewed and has the lgtm label, please assign shivamerla 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 added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 10, 2026
@tico88612

Copy link
Copy Markdown
Member Author

/cc @shivamerla

@tico88612

Copy link
Copy Markdown
Member Author

@shivamerla could you take a look on this? thank you!

@shivamerla

Copy link
Copy Markdown
Contributor

Thanks for this, and sorry it sat for a while. Main has since added its own cdi_test.go (10833dc), and the CDI cache now validates device nodes, so this needs a rework rather than just a rebase. Please rebase, reuse the existing fakeNVCDI and helpers, give the fixtures real device nodes and a matching GpuInfo.Minor, and drop the cache hit/miss cases main already covers.

@kubernetes-prow kubernetes-prow Bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 20, 2026
@tico88612

Copy link
Copy Markdown
Member Author

@shivamerla I will do this in this week.

Verify that underlying common edits errors are not cached and invalid
cached values return an error without calling the CDI library.

Signed-off-by: ChengHao Yang <17496418+tico88612@users.noreply.github.com>
Verify that device specs are cached independently by UUID, underlying
errors are not cached, and invalid cached values return an error.

Signed-off-by: ChengHao Yang <17496418+tico88612@users.noreply.github.com>
Verify that cache warmup continues after a UUID lookup fails, reuses
cached entries for repeated UUIDs, and populates the cache for later
lookups without additional CDI library calls.

Signed-off-by: ChengHao Yang <17496418+tico88612@users.noreply.github.com>
Verify regular GPU claim spec generation, including claim device naming
and the placement of common, device, and group container edits.

Cover common edits and device spec errors, checking that no claim spec
file is written on failure.

Signed-off-by: ChengHao Yang <17496418+tico88612@users.noreply.github.com>
@kubernetes-prow kubernetes-prow Bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 25, 2026
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Adds unit tests for CDI cache behavior, including per-UUID entries, error handling, and warmup. Adds table-driven tests for successful CreateClaimSpecFile execution and failures when fetching common edits or device specs.

Possibly related issues

  • The unit test coverage tracker includes the CDI test objective addressed by this PR.
Merge Risk: Minimal · up to 3d425

This PR only adds tests for CDI behavior and does not change production code. No merge-blocking risk is identified. The reviewer has asked for a rebase to reuse existing helpers and drop overlapping cases, which is a follow-up and not a defect.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the test area (gpu-kubelet-plugin CDI) and the change type (unit test). The changeset adds CDI unit tests in cmd/gpu-kubelet-plugin/cdi_test.go, so the title matches the main change. I…
Description check Passed The description states that it adds a unit test for the gpu-kubelet-plugin CDI code, references issue #1303, and notes AI assistance. This relates directly to the changeset. The description is brief a…
Linked Issues check Passed Direct linked issue #1303 requires unit tests for cmd/gpu-kubelet-plugin/cdi.go. The reviewed head contains cmd/gpu-kubelet-plugin/cdi_test.go. Its tests cover: validateCommonDeviceNodes (complete, mi…
Out of Scope Changes check Passed The changed file, as supplied by the PR summary, is cmd/gpu-kubelet-plugin/cdi_test.go only (+315/-0, no declaration changes). Every test in the read portion targets CDI behavior in the gpu-kubelet-pl…
Full details: Title check

Explanation

The title names the test area (gpu-kubelet-plugin CDI) and the change type (unit test). The changeset adds CDI unit tests in cmd/gpu-kubelet-plugin/cdi_test.go, so the title matches the main change. It is short and specific enough for a scanning teammate. It does not name the cache or claim-spec coverage, which is acceptable because the title need not cover every detail.

Full details: Description check

Explanation

The description states that it adds a unit test for the gpu-kubelet-plugin CDI code, references issue #1303, and notes AI assistance. This relates directly to the changeset. The description is brief and omits detail on the cache and claim-spec test cases, but the check is lenient and the content is on topic.

Full details: Linked Issues check

Explanation

Direct linked issue #1303 requires unit tests for cmd/gpu-kubelet-plugin/cdi.go. The reviewed head contains cmd/gpu-kubelet-plugin/cdi_test.go. Its tests cover: validateCommonDeviceNodes (complete, missing, and wrong-root node sets); GetCommonEditsCached (incomplete edits not cached, complete edits cached once, underlying errors not cached, invalid cached type rejected); GetDeviceSpecsByUUIDCached (complete specs cached, incomplete specs rejected and not cached across several invalid paths); validateClaimCDIDeviceNodes for GPU, static MIG, dynamic MIG, and VFIO; CreateClaimSpecFile (minor mismatch rejected, claim edits merged into the written spec); getDeviceSpecsByUUIDAndMinor and InvalidateDeviceSpec cache refresh; and GetDevNodesForMigDevice reading from ALT_PROC_DRIVER_PATH. These cover the CDI functions the issue names. The PR description gives no non-coding requirement. Limits: the whole-PR diff tool returned no text, so the base-to-head change set rests on the supplied summary (single new test file, no declaration changes). The file read was truncated at 16000 bytes, so the tail of the file was not read. Tests were not executed; compilation and pass status are unverified. The reviewer rework request (rebase, reuse fakeNVCDI, remove duplicate cases) is a review-process item, not an issue requirement, and is not assessed here.

Full details: Out of Scope Changes check

Explanation

The changed file, as supplied by the PR summary, is cmd/gpu-kubelet-plugin/cdi_test.go only (+315/-0, no declaration changes). Every test in the read portion targets CDI behavior in the gpu-kubelet-plugin: CDI common edits, device spec caching, claim spec generation, and MIG device node lookup. The ALT_PROC_DRIVER_PATH test uses common.ConfigureProcDevicesPath and common.ConfigureProcDriverPath as test fixtures for GetDevNodesForMigDevice. These are supporting setup for a cdi.go path, not unrelated changes. The unread tail of the file could not be checked for out-of-scope content. This does not change the result based on the supplied evidence.

  • 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 3d42525.

Files selected for processing: 1

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

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

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. 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/L Denotes a PR that changes 100-499 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/cdi.go

2 participants