api/t/network: represent MAC addrs as byte slices#51355
Merged
robmry merged 1 commit intomoby:masterfrom Oct 30, 2025
Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR refactors MAC address handling across the codebase by introducing a new network.HardwareAddr type that wraps net.HardwareAddr with custom marshaling/unmarshaling behavior. This change improves type safety and eliminates repetitive MAC address parsing/validation logic.
Key changes:
- Introduced
network.HardwareAddrtype with custom text and JSON marshaling - Replaced string-based MAC address fields with
network.HardwareAddrthroughout the API types - Removed redundant MAC address validation code since parsing now happens during unmarshaling
Reviewed Changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| api/types/network/hwaddr.go | New type definition for HardwareAddr with marshaling support |
| api/types/network/hwaddr_test.go | Comprehensive tests for HardwareAddr marshaling/unmarshaling |
| api/types/network/endpoint.go | Updated MacAddress field to use HardwareAddr type |
| api/types/network/endpoint_resource.go | Updated MacAddress field to use HardwareAddr type |
| api/swagger.yaml | Added x-go-type annotations for MacAddress fields |
| daemon/server/router/container/backend.go | Updated ContainerInspect signature to return HardwareAddr |
| daemon/server/router/container/container_routes.go | Updated MAC address handling to use HardwareAddr type |
| daemon/server/router/container/container_routes_test.go | Updated tests to use HardwareAddr instead of strings |
| daemon/server/router/container/inspect.go | Updated MAC address comparison to use length check |
| daemon/cluster/executor/backend.go | Updated ContainerInspect signature to return HardwareAddr |
| daemon/inspect.go | Updated return type and nil handling for HardwareAddr |
| daemon/network.go | Removed manual MAC parsing, using type conversion instead |
| daemon/network/settings.go | Updated DesiredMacAddress to HardwareAddr type |
| daemon/container_operations.go | Removed manual MAC address validation and updated nil assignment |
| integration/internal/container/ops.go | Added MAC address parsing in WithMacAddress helper |
| integration/networking/mac_addr_test.go | Updated MAC address comparison to use slices.Equal |
| integration/networking/bridge_linux_test.go | Updated MAC address comparisons and removed redundant parsing |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
7065c16 to
0b130b3
Compare
This comment has been minimized.
This comment has been minimized.
Make invalid states unrepresentable by moving away from stringly-typed MAC address values in API structs. As go.dev/issue/29678 has not yet been implemented, provide our own HardwareAddr byte-slice type which implements TextMarshaler and TextUnmarshaler to retain compatibility with the API wire format. When stdlib's net.HardwareAddr type implements TextMarshaler and TextUnmarshaler and GODEBUG=netmarshal becomes the default, we should be able to make the type a straight alias for stdlib net.HardwareAddr as a non-breaking change. Signed-off-by: Cory Snider <csnider@mirantis.com>
0b130b3 to
19f4c27
Compare
robmry
approved these changes
Oct 30, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
- What I did
Make invalid states unrepresentable by moving away from stringly-typed MAC address values in API structs.
- How I did it
As https://go.dev/issue/29678 has not yet been implemented, provide our own HardwareAddr byte-slice type which implements TextMarshaler and TextUnmarshaler to retain compatibility with the API wire format.
When stdlib's net.HardwareAddr type implements TextMarshaler and TextUnmarshaler and GODEBUG=netmarshal becomes the default, we should be able to make the type a straight alias for stdlib net.HardwareAddr as a non-breaking change.
- How to verify it
CI.
- Human readable description for the release notes
- Go-SDK: MAC address fields are represented as byte slices compatible with the standard library net.HardwareAddr type instead of strings.- A picture of a cute animal (not mandatory but encouraged)