add MAC, IPv4, IPv6 addresses to nework inspect#4680
add MAC, IPv4, IPv6 addresses to nework inspect#4680coderbirju wants to merge 1 commit intocontainerd:mainfrom
Conversation
2385db1 to
eb356cf
Compare
eb356cf to
365205b
Compare
|
Apologies for the late reply, you're right we can skip the assert statements as the field existence is already validated through struct unmarshaling. |
| Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { | ||
| return helpers.Command("network", "inspect", data.Identifier("test-network")) | ||
| }, | ||
| Expected: func(data test.Data, helpers test.Helpers) *test.Expected { |
There was a problem hiding this comment.
There are no tests for the items added in this PR's changes. Should add assertions for IPv4Address, MacAddress, and IPv6Address.
Signed-off-by: Arjun Raja Yogidas <arjunry@amazon.com>
365205b to
0756765
Compare
|
Failures seem to be unrelated to the changes |
|
Thanks for fixes. I'll reply within this week 🙏 |
| continue | ||
| } | ||
|
|
||
| if len(subnets) > 0 { |
There was a problem hiding this comment.
What situations can lead to an empty subnets list?
|
|
||
| // Test IPv4Address has CIDR notation (not empty and contains '/') | ||
| assert.Assert(t, container.IPv4Address != "", "IPv4Address should not be empty") | ||
| assert.Assert(t, strings.Contains(container.IPv4Address, "/"), "IPv4Address should contain CIDR notation with /") |
There was a problem hiding this comment.
IMO, it would be better to verify that the container IP is within the subnet, in addition to checking that container.IPv4Address contains /.
Example:
_, subnet, _ := net.ParseCIDR(dc[0].IPAM.Config[0].Subnet)
containerIP, _, _ := net.ParseCIDR(container.IPv4Address)
assert.Assert(t, subnet.Contains(containerIP), "IPv4Address should be within the network's subnet")| assert.Assert(t, strings.Contains(container.IPv4Address, "/"), "IPv4Address should contain CIDR notation with /") | ||
|
|
||
| // Test MacAddress is present and has valid format | ||
| assert.Assert(t, container.MacAddress != "", "MacAddress should not be empty") | ||
|
|
||
| // Test IPv6Address is empty for IPv4-only network | ||
| assert.Equal(t, "", container.IPv6Address, "IPv6Address should be empty for IPv4-only network") |
There was a problem hiding this comment.
When checking CI logs, there are below messages:
network_inspect_test.go:446: assertion failed: container.IPv4Address is "": IPv4Address should not be empty
This is because nerdctl network inspect on windows environments does not return NetNS information.
nerdctl/pkg/containerinspector/containerinspector_windows.go
Lines 25 to 29 in deec874
| if subnet.Contains(ip) { | ||
| endpoint.MacAddress = iface.HardwareAddr | ||
| setIPAddresses(endpoint, addr) | ||
| return true |
There was a problem hiding this comment.
In the current implementation, when a container belongs to a dual-stack network with both IPv4 and IPv6, only one IP address is displayed. Both IPv4 and IPv6 addresses should be displayed.
sudo nerdctl network create --ipv6 --subnet 10.1.0.0/24 --subnet fd00::/64 test-dual-stack
sudo nerdctl run -d --name test-container --network test-dual-stack alpine sleep infinity
sudo nerdctl network inspect test-dual-stack | jq -r '.[].Containers'There was a problem hiding this comment.
+1 here we are returning true but we are parsing a range of subnets.
| return subnets | ||
| } | ||
|
|
||
| // isUsableInterface checks if a network interface is usable (not loopback and up) |
There was a problem hiding this comment.
nit: and interface is up.
| func matchInterfaceToSubnets(endpoint *EndpointResource, iface *native.NetInterface, subnets []*net.IPNet) bool { | ||
| for _, addr := range iface.Addrs { | ||
| ip, _, err := net.ParseCIDR(addr) | ||
| if err != nil || ip.IsLoopback() || ip.IsLinkLocalUnicast() { |
There was a problem hiding this comment.
nit: handle error and other conditional separately. Not important but the purpose is different.
| // IPv4Address string `json:"IPv4Address"` | ||
| // IPv6Address string `json:"IPv6Address"` | ||
| MacAddress string `json:"MacAddress"` | ||
| IPv4Address string `json:"IPv4Address"` |
There was a problem hiding this comment.
we are parsing a range of subnets but we are supposed take the first IPV4 and one IPV6 address i think for docker compatibility, how that is decided?
| // IPv6Address string `json:"IPv6Address"` | ||
| MacAddress string `json:"MacAddress"` | ||
| IPv4Address string `json:"IPv4Address"` | ||
| IPv6Address string `json:"IPv6Address"` |
There was a problem hiding this comment.
nit: GlobalIPV6Address
compatible with convention in https://docs.docker.com/reference/api/engine/version/v1.44/#tag/Container/operation/ContainerInspect
Current network inspect respone provides only container names
This PR adds other fields in the EndpointResource Struct
Testing:
CIDR Notation:
Result
Multi-Network Container:
-hoge
-fuga