Skip to content

Commit 4f1e7f5

Browse files
committed
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.
1 parent b9bda8f commit 4f1e7f5

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

client/allocrunner/networking_cni.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,13 @@ func (c *cniNetworkConfigurator) cniToAllocNet(res *cni.Result) (*structs.AllocN
507507

508508
}
509509

510+
// Fallback: if no IPv4 address but we have IPv6, copy it to Address field
511+
// for backward compatibility with code that only checks Address field
512+
// (e.g. service registration with address_mode="alloc")
513+
if netStatus.Address == "" && netStatus.AddressIPv6 != "" {
514+
netStatus.Address = netStatus.AddressIPv6
515+
}
516+
510517
// Use the first DNS results, if non-empty
511518
if len(res.DNS) > 0 {
512519
cniDNS := res.DNS[0]

0 commit comments

Comments
 (0)