From d058761dc78c54a1a127756c8c716a255f7bae4f Mon Sep 17 00:00:00 2001 From: Dmitrii Andreev Date: Wed, 8 Oct 2025 17:27:27 +0300 Subject: [PATCH] client: add test for IPv6-only CNI interfaces Add a test case to verify that CNI results containing only IPv6 addresses are handled correctly. This is a regression test for a bug introduced in GH-23882 where IPv6-only interfaces would fail with 'no interface with an address' error. The test verifies that when a CNI plugin returns only an IPv6 address (without IPv4), the allocation network status should be properly populated with the IPv6 address in the AddressIPv6 field. --- client/allocrunner/networking_cni_test.go | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/client/allocrunner/networking_cni_test.go b/client/allocrunner/networking_cni_test.go index 43745d3d7..3264f5c76 100644 --- a/client/allocrunner/networking_cni_test.go +++ b/client/allocrunner/networking_cni_test.go @@ -498,6 +498,34 @@ func TestCNI_cniToAllocNet_Dualstack(t *testing.T) { test.Eq(t, "eth0", allocNet.InterfaceName) } +// TestCNI_cniToAllocNet_IPv6Only asserts that CNI results containing only IPv6 +// addresses work correctly. This is a regression test for a bug introduced in +// GH-23882 where IPv6-only interfaces would fail with "no interface with an address". +func TestCNI_cniToAllocNet_IPv6Only(t *testing.T) { + ci.Parallel(t) + + cniResult := &cni.Result{ + Interfaces: map[string]*cni.Config{ + "eth0": { + Sandbox: "nomad-sandbox", + IPConfigs: []*cni.IPConfig{ + {IP: net.ParseIP("fd00:a110:c8::b")}, // only IPv6 + }, + }, + }, + } + + c := &cniNetworkConfigurator{ + logger: testlog.HCLogger(t), + } + allocNet, err := c.cniToAllocNet(cniResult) + must.NoError(t, err) + must.NotNil(t, allocNet) + test.Eq(t, "", allocNet.Address) + test.Eq(t, "fd00:a110:c8::b", allocNet.AddressIPv6) + test.Eq(t, "eth0", allocNet.InterfaceName) +} + func TestCNI_addCustomCNIArgs(t *testing.T) { ci.Parallel(t) cniArgs := map[string]string{