Skip to content

feat(Kunlun): add Kunlun vXPU mock resources - #26

Closed
spencercjh wants to merge 2 commits into
Project-HAMi:masterfrom
spencercjh:feat/mock-kunlun-vxpu
Closed

spencercjh wants to merge 2 commits into
Project-HAMi:masterfrom
spencercjh:feat/mock-kunlun-vxpu

Conversation

@spencercjh

@spencercjh spencercjh commented Aug 25, 2026 •

Copy link
Copy Markdown

Most of this Pull Request was generated or revised with the assistance of AI tools(Raft with GPT-5.6 Sol High). I have reviewed the resulting content and take full responsibility for its accuracy, security, licensing compliance, and inclusion in this project.

What

  • enable the existing Kunlun configuration path in the mock device plugin
  • derive kunlunxin.com/vxpu from healthy entries' count and kunlunxin.com/vxpu-memory from their devmem
  • acknowledge the Scheduler's hami.io/node-handshake-xpu request with the real device-plugin's Reported_* protocol
  • keep Kunlun configuration per instance and validate its virtual resource names before registration
  • document a production-shaped P800-OAM registration record and add focused device/config/handshake regression tests

Why

HAMi already schedules Kunlun vXPU resources from hami.io/node-register-xpu, but the mock plugin did not register the corresponding kubelet resources or participate in the Scheduler health handshake. If the Scheduler started before the annotation appeared, its fresh Requesting_* marker caused the now-visible XPU inventory to remain absent from the Scheduler cache.

The original implementation also treated devcore as the virtual-device count. The real vXPU device plugin reports one P800-OAM as count: 4, devmem: 98304, and devcore: 100; the virtual count must therefore use count, not devcore.

Impact

  • Kunlun support is enabled only when both virtual resource names are valid and configured.
  • No separate physical count-resource status patch is required; healthy annotation entries are the source of virtual count and memory capacity.
  • Handshake acknowledgement uses a JSON Patch test before replace, so a stale poll cannot overwrite a newer Scheduler request.
  • Malformed, empty, null-entry, or negative-capacity annotations fail closed and publish zero virtual capacity.
  • Existing NVIDIA, Hygon, Ascend, AMD, and Iluvatar implementations are unchanged.

Validation

Using the repository Go 1.21 toolchain and host verification:

  • go test ./...
  • go test -race ./...
  • go test -shuffle=on ./...
  • go vet ./...
  • CGO_ENABLED=0 go build ./cmd/k8s-device-plugin
  • git diff --check
  • golangci-lint run --new-from-rev a3a8764b12069b46c594eb0ea97f7e94031f8c01 ./... (0 new issues)

Real-cluster regression on K3s v1.32.5 + HAMi v2.10.0 followed the failing startup order: install Scheduler/Mock first, wait for Requesting_*, then add one P800-OAM annotation. The fixed mock reported the handshake; the Scheduler added vendor XPU; Node capacity became vxpu=4, vxpu-memory=98304; and a Pod requesting one vXPU became Running. Its to-allocate and allocated annotations both identified XPU-MOCK-0,XPU,24576,25, and the mock received both Allocate calls.

Full-repository lint still reports the same three pre-existing findings in untouched cmd/k8s-device-plugin/main.go and internal/pkg/mock/server.go; this update adds none.

Signed-off-by: spencercjh <spencercjh@gmail.com>
@coderabbitai

coderabbitai Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 59 minutes.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ae02bdb7-8679-4076-86ee-b0a4e22085f8

📥 Commits

Reviewing files that changed from the base of the PR and between d3b1687 and a130831.

📒 Files selected for processing (7)
  • README.md
  • internal/pkg/api/device/device.go
  • internal/pkg/api/device/device_test.go
  • internal/pkg/api/device/kunlun/device.go
  • internal/pkg/api/device/kunlun/device_test.go
  • internal/pkg/config/config.go
  • internal/pkg/config/kunlun_test.go

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@hami-robot

hami-robot Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

@spencercjh spencercjh changed the title feat: add Kunlun vXPU mock resources feat(Kunlun): add Kunlun vXPU mock resources Aug 26, 2026
Signed-off-by: spencercjh <spencercjh@gmail.com>
@spencercjh

spencercjh commented Aug 26, 2026 •

Copy link
Copy Markdown
Author

Tested with HAMi v2.10.0 on a fresh local K3d cluster.

Procedure:

  1. Installed HAMi with devicePlugin.enabled=false, mockDevicePlugin.enabled=true, and scheduler.leaderElect=false.
  2. Built this PR image locally and imported mock-device-plugin:pr26-a130831 into the K3d node.
  3. Added this Node annotation on k3d-hami-mock-pr26-a130831-server-0:
hami.io/node-register-xpu=[{"id":"XPU-MOCK-0","count":1,"devmem":24576,"devcore":1,"type":"XPU","health":true}]
  1. The node has only normal K3d/K3s labels. No Kunlun-specific label was added. Mock updated hami.io/node-handshake-xpu to Reported_... and registered:
kunlunxin.com/vxpu=1
kunlunxin.com/vxpu-memory=24576
  1. Created a Pod with schedulerName: hami-scheduler, kunlunxin.com/vxpu=1, and kunlunxin.com/vxpu-memory=1024.

Result: PASS. The Pod is Running on k3d-hami-mock-pr26-a130831-server-0. Scheduler selected XPU-MOCK-0 and wrote:

hami.io/xpu-devices-to-allocate=XPU-MOCK-0,XPU,24576,25:;
hami.io/xpu-devices-allocated=XPU-MOCK-0,XPU,24576,25:;
hami.io/vgpu-node=k3d-hami-mock-pr26-a130831-server-0

Mock logs contain Into Allocate. This confirms the new XPU registration-handshake fix works in the actual Scheduler and Allocate path.

@spencercjh
spencercjh marked this pull request as ready for review August 26, 2026 04:19
@moezdil

moezdil commented Sep 22, 2026

Copy link
Copy Markdown

Old PRs and issues are being closed because they are no longer relevant. Or it was closed because of th
inactivity or PR/issues owners.
If you believe the issue is still relevant, please submit feedback.

@moezdil moezdil closed this Sep 22, 2026
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