fix(mock): rediscover resource name changes - #23
blackdragoon26 wants to merge 2 commits into
Conversation
Signed-off-by: blackdragoon26 <sankalp.jha9643@gmail.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: blackdragoon26 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Welcome @blackdragoon26! It looks like this is your first PR to Project-HAMi/mock-device-plugin 🎉 |
📝 WalkthroughWalkthrough
ChangesDynamic resource publication
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant ResourceSource
participant MockLister
participant DevicePluginManager
ResourceSource->>MockLister: SetResource(resource counts)
MockLister->>MockLister: Update plugin counts and compare names
MockLister->>DevicePluginManager: Send changed sorted resource list
Suggested labels: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/pkg/mock/lister.go`:
- Around line 101-110: The resource update path around SetResource must
serialize publication order so concurrent calls cannot send stale lists after
newer ones. Add a dedicated publication mutex or ordered publisher, acquire it
before sending on ResUpdateChan while keeping l.mutex released during the send,
and release it afterward; add a concurrent regression test verifying consumers
receive updates in the same order as the committed l.resources state.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: d61db0e4-1f98-4eea-b53c-3310f4bb359a
📒 Files selected for processing (2)
internal/pkg/mock/lister.gointernal/pkg/mock/lister_test.go
Signed-off-by: blackdragoon26 <sankalp.jha9643@gmail.com>
What type of PR is this?
Bug fix.
What this PR does / why we need it:
This PR fixes dynamic resource discovery in
MockLister.SetResource.Previously, resource names were advertised only before the first mock plugin was created. If the resource set later changed
, for example, when enabling Ascend
hami-vnpu-coreadded a new-coreresource, and the existing plugin counts were updated, but the device-plugin manager was not notified about the new resource name. Consequently, no plugin was created for that resource.This change:
Validation completed on macOS:
go test ./...go test -race ./internal/pkg/mockgo vet ./...git diff --checkWhich issue(s) this PR fixes: Fixes #22
Special notes for your reviewer:
The change is limited to the generic mock resource-discovery path and its unit tests. It does not require GPU hardware or a Kubernetes cluster to reproduce and verify.
The resource-name list is sorted before comparison and publication, preventing Go map iteration order from causing unnecessary discovery updates.
Does this PR introduce a user-facing change?:
Yes. Runtime additions or removals of mock resource types are now reflected through the device-plugin manager instead of being ignored after startup.
AI Disclosure:
This change was developed with Codex assistance. I reviewed and validated the implementation, tests, repository behavior, and issue reproduction, and I take responsibility for the submitted changes.
Summary by CodeRabbit
Bug Fixes
Tests