From cfd2bd70a1faa1b49b1ed3899f68d29a38f504a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=A5=96=E5=BB=BA?= Date: Mon, 8 Jul 2024 18:18:58 +0800 Subject: [PATCH] ipam: fix ip not released for non-ovn subnets (#4265) Signed-off-by: zhangzujian --- pkg/ipam/subnet.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/ipam/subnet.go b/pkg/ipam/subnet.go index 344d4b4639a..34bfe6fa60e 100644 --- a/pkg/ipam/subnet.go +++ b/pkg/ipam/subnet.go @@ -211,7 +211,7 @@ func (s *Subnet) getV4RandomAddress(ippoolName, podName, nicName string, mac *st // After 'macAdd' introduced to support only static mac address, pod restart will run into error mac AddressConflict // controller will re-enqueue the new pod then wait for old pod deleted and address released. // here will return only if both ip and mac exist, otherwise only ip without mac returned will trigger CreatePort error. - if s.V4NicToIP[nicName] != nil && s.NicToMac[nicName] != "" { + if s.V4NicToIP[nicName] != nil && (s.NicToMac[nicName] != "" || (mac != nil && *mac == "")) { if !slices.Contains(skippedAddrs, s.V4NicToIP[nicName].String()) { return s.V4NicToIP[nicName], nil, s.NicToMac[nicName], nil } @@ -268,7 +268,7 @@ func (s *Subnet) getV6RandomAddress(ippoolName, podName, nicName string, mac *st // After 'macAdd' introduced to support only static mac address, pod restart will run into error mac AddressConflict // controller will re-enqueue the new pod then wait for old pod deleted and address released. // here will return only if both ip and mac exist, otherwise only ip without mac returned will trigger CreatePort error. - if s.V6NicToIP[nicName] != nil && s.NicToMac[nicName] != "" { + if s.V6NicToIP[nicName] != nil && (s.NicToMac[nicName] != "" || (mac != nil && *mac == "")) { if !slices.Contains(skippedAddrs, s.V6NicToIP[nicName].String()) { return nil, s.V6NicToIP[nicName], s.NicToMac[nicName], nil }