k8s-device-plugin icon indicating copy to clipboard operation
k8s-device-plugin copied to clipboard

[Refactor] Simplify UnmarshalJSON with Dedicated Handlers

Open haitwang-cloud opened this issue 1 year ago • 4 comments

This PR refactors the UnmarshalJSON method for ReplicatedDevices to improve code clarity and structure. Key changes include:

  • Modularization: Created separate handlers (handleStringInput, handleNumericInput, handleListInput) for different input types, enhancing readability and simplifying future maintenance.

  • Robust Error Handling: Enhanced the error handling in handleListInput to allow processing of list elements independently.

  • Code Refactoring: Eliminated redundancy by centralizing error checking logic.

  • Generics Readiness: Prepared handleNumericInput for future adaptation to Go's generics (once available).

haitwang-cloud avatar May 06 '24 09:05 haitwang-cloud

@klueska PTAL

haitwang-cloud avatar May 06 '24 09:05 haitwang-cloud

Upon reviewing, I identified a bug in the previous submission that resulted in the failure of two existing unit test functions. To address this, I've removed the switch statement, which was causing the issue.

Here are the current unit test results:

(base) ➜  v1 git:(main) ✗ go test ./...                          
ok      github.com/NVIDIA/k8s-device-plugin/api/config/v1       0.634s

haitwang-cloud avatar May 07 '24 07:05 haitwang-cloud

Ping @klueska

haitwang-cloud avatar May 21 '24 05:05 haitwang-cloud

Ping @elezar

haitwang-cloud avatar Jun 20 '24 06:06 haitwang-cloud

This PR is stale because it has been open 90 days with no activity. This PR will be closed in 30 days unless new comments are made or the stale label is removed.

github-actions[bot] avatar Oct 07 '24 04:10 github-actions[bot]