client: enhance CNI address handling for backward compatibility

Add fallback logic in cniToAllocNet to populate the Address field with the IPv6 address when no IPv4 address is available. This change ensures compatibility with existing code that relies on the Address field for service registration, particularly in scenarios where only IPv6 addresses are present.
This commit is contained in:
Dmitrii Andreev
2025-10-09 12:59:25 +03:00
parent b9bda8f2c1
commit 4f1e7f56d1

View File

@@ -507,6 +507,13 @@ func (c *cniNetworkConfigurator) cniToAllocNet(res *cni.Result) (*structs.AllocN
}
// Fallback: if no IPv4 address but we have IPv6, copy it to Address field
// for backward compatibility with code that only checks Address field
// (e.g. service registration with address_mode="alloc")
if netStatus.Address == "" && netStatus.AddressIPv6 != "" {
netStatus.Address = netStatus.AddressIPv6
}
// Use the first DNS results, if non-empty
if len(res.DNS) > 0 {
cniDNS := res.DNS[0]