Skip to content

Add unit test for gpuPodSpecFilter container resource-list branch#2659

Merged
abrarshivani merged 1 commit into
NVIDIA:mainfrom
abrarshivani:unit-test-cmd-gpu-operator
Jul 24, 2026
Merged

Add unit test for gpuPodSpecFilter container resource-list branch#2659
abrarshivani merged 1 commit into
NVIDIA:mainfrom
abrarshivani:unit-test-cmd-gpu-operator

Conversation

@abrarshivani

@abrarshivani abrarshivani commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Description

gpuPodSpecFilter decides whether a pod is a GPU pod via two branches:

  1. container resource-list — a container requesting nvidia.com/gpu* or nvidia.com/mig-* in its limits/requests (gated on the pod being Running/Pending), and
  2. DRA / ResourceClaimsPodHasNVIDIAGPUClaim(...).

The existing TestGPUPodSpecFilterResourceClaims covers only branch (2). Per the coverage report, branch (1) — the nvidia.com/gpu / nvidia.com/mig- prefix match and the container-loop return true — was uncovered.

This PR adds TestGPUPodSpecFilterResourceList to cmd/gpu-operator/main_test.go covering branch (1):

  • nvidia.com/gpu in a container's limits and in requests
  • the nvidia.com/mig- prefix
  • a multi-container pod where only a later container requests a GPU
  • a pod with only cpu/memory resources (not a GPU pod)
  • the phase gate (a Succeeded pod with a GPU resource is ignored)

The pods carry no ResourceClaims, so the DRA branch resolves to false and only the resource-list branch is exercised. This complements the existing DRA test rather than duplicating it, bringing gpuPodSpecFilter to 100% statement coverage.

Tests only — no production changes.

Checklist

  • No secrets, sensitive information, or unrelated changes
  • Lint checks passing (make lint)
  • Generated assets in-sync (make validate-generated-assets)
  • Go mod artifacts in-sync (make validate-modules)
  • Test cases are added for new code paths

Testing

go test ./cmd/gpu-operator/... -covermode=count    # gpuPodSpecFilter: 100.0%
golangci-lint run ./cmd/gpu-operator/...           # 0 issues (GOOS=linux)

@copy-pr-bot

copy-pr-bot Bot commented Jul 22, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@abrarshivani
abrarshivani force-pushed the unit-test-cmd-gpu-operator branch from 5e4652a to c9b4a5a Compare July 23, 2026 19:38
@abrarshivani
abrarshivani marked this pull request as ready for review July 23, 2026 20:06
@tariq1890

Copy link
Copy Markdown
Contributor

Can you rebase this PR?

@abrarshivani
abrarshivani force-pushed the unit-test-cmd-gpu-operator branch from c9b4a5a to 0486a01 Compare July 24, 2026 19:18
@abrarshivani abrarshivani changed the title Add unit tests for cmd/gpu-operator gpuPodSpecFilter Add unit test for gpuPodSpecFilter container resource-list branch Jul 24, 2026
@abrarshivani
abrarshivani force-pushed the unit-test-cmd-gpu-operator branch from 0486a01 to 7abcc59 Compare July 24, 2026 19:31
@abrarshivani

Copy link
Copy Markdown
Contributor Author

@tariq1890 I've rebased the branch. Can you please take another look?

Comment thread cmd/gpu-operator/main_test.go
Comment thread cmd/gpu-operator/main_test.go Outdated
@abrarshivani
abrarshivani force-pushed the unit-test-cmd-gpu-operator branch from 7abcc59 to 6ebded8 Compare July 24, 2026 20:44
Comment thread cmd/gpu-operator/main_test.go Outdated
The existing TestGPUPodSpecFilterResourceClaims covers only the DRA/
ResourceClaims branch of gpuPodSpecFilter, leaving the container resource-list
branch (nvidia.com/gpu and nvidia.com/mig- in a container's limits/requests,
and the Running/Pending phase gate) untested. Add TestGPUPodSpecFilterResourceList
to cover it, bringing gpuPodSpecFilter to 100% statement coverage.

Signed-off-by: Abrar Shivani <ashivani@nvidia.com>
@abrarshivani
abrarshivani force-pushed the unit-test-cmd-gpu-operator branch from 6ebded8 to d63c96a Compare July 24, 2026 21:47
@abrarshivani
abrarshivani enabled auto-merge July 24, 2026 22:19
@abrarshivani
abrarshivani merged commit cb71b47 into NVIDIA:main Jul 24, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants