Skip to content

Add mock-NVML XID and recovery-action support for GPU health e2e - #1509

Open
vishalanarase wants to merge 5 commits into
kubernetes-sigs:mainfrom
vishalanarase:fix-1457
Open

vishalanarase wants to merge 5 commits into
kubernetes-sigs:mainfrom
vishalanarase:fix-1457

Conversation

@vishalanarase

Copy link
Copy Markdown
Member

What type of PR is this?

/kind feature

What this PR does / why we need it:

CPU-only mock-NVML CI cannot exercise GPU health checking. The pinned mock emits at most one failure-injector XID, always with GPU instance and compute instance 0, and it does not implement NVML_FI_DEV_GET_GPU_RECOVERY_ACTION. This driver ignores instance 0 for a full GPU and classifies an XID from the recovery action, so those tests never observe a taint.
The mock setup now patches the pinned library at build time. Tests write /driver-root/health-control.json in the GPU plugin container. Each event sets the GPU, XID, GPU instance, and compute instance. Omitted instance IDs mean the full GPU (0xFFFFFFFF). recoveryActions accepts GPU_RECOVERY_ACTION_NONE, GPU_RESET, and the other NVML recovery actions, and a later rewrite of the file moves a GPU back to NONE for a future taint-removal test.
tests/bats/test_gpu_health.bats runs in the mock-NVML suite and checks:

  • A MIG-scoped XID (GI=3, CI=1) is not applied to the full GPU.
  • Recovery action NONE publishes gpu.nvidia.com/xid with effect None.
  • GPU_RESET publishes effect NoSchedule, and that taint remains after the mock reports NONE again.
  • --additional-xids-to-ignore keeps a GPU_RESET XID informational.

On Kubernetes 1.35 and earlier, the Kind cluster enables DRADeviceTaints so those ResourceSlice taints are stored.

Which issue(s) this PR is related to:

Fixes #1457

Special notes for your reviewer:

The health-control sources live in this repo and are copied into the pinned k8s-test-infra mock checkout during setup-mock-gpu.sh. nvmlDeviceGetFieldValues still returns the historical not-supported stub unless the caller asks for field 230 (NVML_FI_DEV_GET_GPU_RECOVERY_ACTION).

AI assistance was used to draft this change.

Does this PR introduce a user-facing change?

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

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/feature Categorizes issue or PR as related to a new feature. labels Sep 30, 2026
@netlify

netlify Bot commented Sep 30, 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 31dc64b

@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 added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Sep 30, 2026
Signed-off-by: Vishal Anarase <iamvishalanarase@gmail.com>
Signed-off-by: Vishal Anarase <iamvishalanarase@gmail.com>
Signed-off-by: Vishal Anarase <iamvishalanarase@gmail.com>
@vishalanarase

Copy link
Copy Markdown
Member Author

/test pull-dra-driver-nvidia-gpu-e2e-lambda-gpu-gh200

@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: @cdesiniotis @varunrsekar

@guptaNswati guptaNswati self-assigned this Oct 26, 2026
@shivamerla

Copy link
Copy Markdown
Contributor

/milestone v0.6.0

@kubernetes-prow kubernetes-prow Bot added this to the v0.6.0 milestone Nov 2, 2026
write_if_changed(header_path, text)


def patch_events(events_path):

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.

This edits our local copy of k8s-test-infra by exact string match, so it will break the next time we bump the pin. Upstream HEAD has already replaced data.gpuInstanceId = 0 with C.uint(nvmlNoMIGInstanceID), so this die() would fail the mock-NVML job. Could you skip this step when upstream already sets the full-GPU value? Longer term, could you open an issue or PR in NVIDIA/k8s-test-infra for GI/CI on XID events and the recovery-action field (230)? Then this patch can go away and this PR only needs to bump the pin and add the tests.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The pinned mock still rewrites gpuInstanceId = 0 to the full-GPU sentinel. If the file already uses 0xFFFFFFFF or nvmlNoMIGInstanceID, that step is skipped instead of failing the job. The longer-term request is in NVIDIA/k8s-test-infra#1384, with the suggested control-file and field-230 change. Once that lands, this patch can go away and the driver only needs a pin bump.

if not bridge.is_dir() or not engine.is_dir():
die(f"mocknvml tree is incomplete: {mocknvml_dir}")

patch_header(bridge / "nvml_types.h")

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.

With the pin at 18befbf, which main already uses, most of this script never does anything. nvml_types.h already defines nvmlFieldValue_t. nvmlDeviceGetFieldValues is already exported from bridge/fieldvalues.go, so the stub removal and the overlay/fieldvalues.go copy get skipped. The PCI bus ID lookup already goes through canonicalPCIBusID. Could you drop patch_header, remove_field_value_stub, patch_pci_bus_id_lookup, the overlay branch in copy_sources, overlay/fieldvalues.go, and their constants, and only target the pinned version?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Dropped patch_header, remove_field_value_stub, patch_pci_bus_id_lookup, the field-values overlay copy, and overlay/fieldvalues.go. The script now only targets the pinned checkout: it copies the health-control sources, claims those events before pendingXidClaim(), and hooks recovery-action field 230 into GetFieldValue.

skip "requires mock NVML health-control injection"
fi
clear_health_control
log_objects

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.

This test file leaves state behind that affects subsequent files. /driver-root is a hostPath, so the control file survives plugin restarts, and the last test leaves the plugin installed with ADDITIONAL_XIDS_TO_IGNORE=79.

When the next file upgrades the chart, the plugin restarts with an empty delivered-ID map and processes ignored-79 again. With the default ignore list, it treats XID 79 as fatal and adds a NoSchedule taint to gpu-0, affecting every later test. CI currently passes because the following test_cd_* files don’t need that GPU.

Please add a teardown_file that clears the control file before reinstalling the plugin with the default args. This ensures the plugin restarts cleanly and removes the taints introduced by this file.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added teardown_file. It clears /driver-root/health-control.json, then reinstalls the plugin with the suite's default args (logVerbosity=6, and compute domains left disabled when this run disabled them). The next file's upgrade no longer replays ignored-79 as a fatal XID on gpu-0.

Limit the local mock patch to the pinned checkout, and skip the GI/CI rewrite when upstream already reports the full-GPU sentinel. Clear the health-control file and reinstall the plugin after the health tests so a later file does not replay XID 79 as fatal.

Signed-off-by: Vishal Anarase <iamvishalanarase@gmail.com>
@kubernetes-prow kubernetes-prow Bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Nov 25, 2026
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Explain Change →

Walkthrough

The changes add JSON-configured XID events and recovery actions to mock NVML, patch the mock engine to expose them, and integrate the patches into GPU setup. The e2e workflow conditionally enables DRADeviceTaints based on Kubernetes version. New BATS tests check XID taints, recovery-action updates, and ignored XIDs.

Merge Risk: Low · up to 31dc6

This PR adds mock-NVML health-check e2e coverage and does not change driver behavior. One test does not actually prove that a NoSchedule taint persists after the GPU recovery action changes to NONE. The weakness is limited to CI test confidence and can be fixed by injecting a later XID before asserting.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: mock-NVML support for XID and recovery-action events, used for GPU health e2e tests. The changeset adds health-control parsing, a build-time patch to the mock NVML sou…
Description check Passed The description is on topic. It explains why the CPU-only mock-NVML CI cannot exercise GPU health checks, describes the health-control JSON file, the build-time patch, the new bats tests, and the DRAD…
Linked Issues check Passed Directly linked issue #1457 is the only active target. Its coding requirements and the implementing changes are:

- Configurable XID events with GPU, GI, and CI [#1457]: healthcontrol/control.go par…
Out of Scope Changes check Passed All changed files support the mock-NVML GPU health-check objective of #1457:

- hack/ci/mock-nvml/healthcontrol/*: health-control parsing, store, overlay hooks, and build-time patcher.
- `hack/ci/mo…
Full details: Title check

Explanation

The title names the main change: mock-NVML support for XID and recovery-action events, used for GPU health e2e tests. The changeset adds health-control parsing, a build-time patch to the mock NVML source, and bats tests for GPU health taints, which all match the title.

Full details: Description check

Explanation

The description is on topic. It explains why the CPU-only mock-NVML CI cannot exercise GPU health checks, describes the health-control JSON file, the build-time patch, the new bats tests, and the DRADeviceTaints change for Kubernetes 1.35 and earlier. These match the changed files.

Full details: Linked Issues check

Explanation

Directly linked issue #1457 is the only active target. Its coding requirements and the implementing changes are:

  • Configurable XID events with GPU, GI, and CI [#1457]: healthcontrol/control.go parses HealthEvent{GPU, XID, GPUInstanceID, ComputeInstanceID}. Omitted instance IDs default to FullGPUInstanceID (0xFFFFFFFF). overlay/engine_hooks.go claims the next event through ClaimHealthControlEvent. patch_mock.py inserts that claim before the pending-XID claim.
  • Configurable NVML_FI_DEV_GET_GPU_RECOVERY_ACTION [#1457]: patch_mock.py adds recovery-action lookup for field ID 230 in GetFieldValue. HealthStore.RecoveryAction supplies the per-GPU value.
  • Tests for NONE and GPU_RESET [#1457]: tests/bats/test_gpu_health.bats covers NONE publishing gpu.nvidia.com/xid with effect None, and GPU_RESET publishing effect NoSchedule.
  • Informational None versus sticky NoSchedule taints [#1457]: the GPU_RESET test checks that the taint persists after the mock reports NONE.
  • --additional-xids-to-ignore override [#1457]: the suite checks that the GPU_RESET XID stays informational when ignored.
  • Simulated recovery back to NONE [#1457]: HealthStore rereads the file on each query, so a later rewrite changes the action.

The unit tests in control_test.go cover parsing, default instance IDs, action names, claim-once behavior, and the last-valid-document rule. Tests for the health-control path are present as well.

Scope limit: this review relies on the PR summary and the diff summary. The bats and mock behavior were not executed. The results of the e2e run are not established by this review.

Full details: Out of Scope Changes check

Explanation

All changed files support the mock-NVML GPU health-check objective of #1457:

  • hack/ci/mock-nvml/healthcontrol/*: health-control parsing, store, overlay hooks, and build-time patcher.
  • hack/ci/mock-nvml/apply-health-control.sh, setup-mock-gpu.sh, setup-mock-gpu-in-kind.sh: wire the patch into the mock build and builder container, including the python3 prerequisite.
  • hack/ci/mock-nvml/e2e-test.sh: enables DRADeviceTaints on Kubernetes 1.35 and earlier, so ResourceSlice taints are stored. Taints are required by the tests.
  • .github/workflows/mock-nvml-e2e.yaml: changes the pinned NVIDIA/k8s-test-infra commit. The patched mock depends on this pin. The new pin is not independently verified in this review.
  • tests/bats/Makefile: adds test_gpu_health.bats to the mock-NVML suite.
  • .gitignore: excludes Python bytecode generated by the patcher and its tests. This is a minor supporting change.

No change is unrelated to the issue.

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

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

Note

Quiet mode is enabled, so only the most important comments were posted inline. Other review comments are grouped below.

Other comments: 1

tests/bats/test_gpu_health.bats: 1

164-168: Minor · Functional Correctness · Quick win

Observe the NONE recovery action before asserting that the taint is sticky.

The driver reads the recovery action only while it handles an XID (cmd/gpu-kubelet-plugin/device_health.go:513). This test writes NONE for gpu:1 but injects no later XID. The driver never reads NONE, so the NoSchedule assertion passes on the taint from the earlier event. The assertion cannot show that the taint survives recovery. It also passes if the driver ignores NONE.

After writing NONE, inject a later XID on gpu-1. Wait until the driver has handled that event before asserting NoSchedule. Use a positive-condition wait, not the fixed sleep 3, so the test does not depend on elapsed time.

Source: Learnings

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 495bf4c and 31dc64b.

Files selected for processing: 13

  • .github/workflows/mock-nvml-e2e.yaml
  • .gitignore
  • hack/ci/mock-nvml/apply-health-control.sh
  • hack/ci/mock-nvml/e2e-test.sh
  • hack/ci/mock-nvml/healthcontrol/control.go
  • hack/ci/mock-nvml/healthcontrol/control_test.go
  • hack/ci/mock-nvml/healthcontrol/overlay/engine_hooks.go
  • hack/ci/mock-nvml/healthcontrol/overlay/keep.go
  • hack/ci/mock-nvml/healthcontrol/patch_mock.py
  • hack/ci/mock-nvml/setup-mock-gpu-in-kind.sh
  • hack/ci/mock-nvml/setup-mock-gpu.sh
  • tests/bats/Makefile
  • tests/bats/test_gpu_health.bats

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/feature Categorizes issue or PR as related to a new feature. 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.

Add mock-NVML support for GPU health-checking and XID e2e tests

3 participants