From b46b103c4cd39742fa4ba67e64db6be0a860a700 Mon Sep 17 00:00:00 2001 From: changluyi Date: Wed, 7 Dec 2022 09:32:45 +0800 Subject: [PATCH] fix: sometimes alloc ipv6 address failed sometimes ipam.GetStaticAddress return NoAvailableAddress when use ipam.GetStaticAddress with param ipv6 address without clean Zero such as "fd00::00e9:0ed1", and exactly subnet.V6FreeIPList has a range with start fd00::e9:ed1 and end with any v6 address,or start with an any v6 address and end with fd00::e9:ed1, it will cause ipr.Start.Equal(ip) or ipr.End.Equal(ip) failed, and no v6 address allocated --- pkg/ipam/subnet.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/ipam/subnet.go b/pkg/ipam/subnet.go index c86cbc460aa..2313a1c7c20 100644 --- a/pkg/ipam/subnet.go +++ b/pkg/ipam/subnet.go @@ -285,6 +285,11 @@ func (subnet *Subnet) GetStaticAddress(podName string, ip IP, mac string, force if v4 && !subnet.V4CIDR.Contains(net.ParseIP(string(ip))) { return ip, mac, OutOfRangeError } + + if v6 { + ip = IP(net.ParseIP(string(ip)).String()) + } + if v6 && !subnet.V6CIDR.Contains(net.ParseIP(string(ip))) { return ip, mac, OutOfRangeError }