From 4f1e7f56d1ac9e7125862dadaab4021fa185968d Mon Sep 17 00:00:00 2001 From: Dmitrii Andreev Date: Thu, 9 Oct 2025 12:59:25 +0300 Subject: [PATCH] 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. --- client/allocrunner/networking_cni.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/client/allocrunner/networking_cni.go b/client/allocrunner/networking_cni.go index 60a5ec451..f9f35c264 100644 --- a/client/allocrunner/networking_cni.go +++ b/client/allocrunner/networking_cni.go @@ -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]