Skip to content

feat: add DeepCopy function for DeviceUsage and its nested types#1818

Merged
hami-robot[bot] merged 2 commits into
Project-HAMi:masterfrom
Shouren:feat/deepcopy-for-nodeusage
May 6, 2026
Merged

feat: add DeepCopy function for DeviceUsage and its nested types#1818
hami-robot[bot] merged 2 commits into
Project-HAMi:masterfrom
Shouren:feat/deepcopy-for-nodeusage

Conversation

@Shouren

@Shouren Shouren commented Apr 29, 2026

Copy link
Copy Markdown
Member

What type of PR is this?
/kind feature

What this PR does / why we need it:
This PR add the DeepCopy function for DeviceUsage and its nested types. So we can deepcopy them directly instead of using JSON serialization (e.g. in #1773)

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

AI Assistance Notice:
Kimi Code CLI helps me generating the test code

Signed-off-by: Shouren Yang <yangshouren@gmail.com>

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request implements DeepCopy methods for various structures across the pkg/device, pkg/scheduler, and pkg/scheduler/policy packages to ensure proper object duplication and isolation. Comprehensive unit tests have been added to verify that mutations to the copied objects do not affect the originals. I have identified a potential issue where the DeepCopy implementation for CustomInfo (a map[string]any) performs a shallow copy of the map values; if these values contain reference types, they will remain shared between the original and the copy. I recommend either implementing a more robust deep copy mechanism for these maps or explicitly documenting this limitation.

Comment thread pkg/device/devices.go
Comment thread pkg/device/pods.go
… field

Signed-off-by: Shouren Yang <yangshouren@gmail.com>
@Shouren Shouren force-pushed the feat/deepcopy-for-nodeusage branch from eacc7b8 to f340bc4 Compare April 29, 2026 08:55
@codecov

codecov Bot commented Apr 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.95960% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/device/pods.go 90.00% 2 Missing and 2 partials ⚠️
Flag Coverage Δ
unittests 58.34% <95.95%> (+0.35%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
pkg/device/devices.go 92.40% <100.00%> (+1.03%) ⬆️
pkg/scheduler/nodes.go 86.88% <100.00%> (+1.43%) ⬆️
pkg/scheduler/policy/gpu_policy.go 100.00% <100.00%> (ø)
pkg/device/pods.go 60.44% <90.00%> (+12.57%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@archlitchi archlitchi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/lgtm

@hami-robot

hami-robot Bot commented May 6, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: archlitchi, Shouren

The full list of commands accepted by this bot can be found here.

The pull request process is described 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

@hami-robot hami-robot Bot merged commit 53e849d into Project-HAMi:master May 6, 2026
13 checks passed
mesutoezdil pushed a commit to mesutoezdil/HAMi that referenced this pull request Jun 14, 2026
…ject-HAMi#1818)

* feat: add DeepCopy function for DeviceUsage and its nested types

Signed-off-by: Shouren Yang <yangshouren@gmail.com>

* fix: issue from golangci-lint about formatted, maps.Copy and embedded field

Signed-off-by: Shouren Yang <yangshouren@gmail.com>

---------

Signed-off-by: Shouren Yang <yangshouren@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants