From 0fcfa1e2c7ed35ed099bb4f0c4e7d87956b69721 Mon Sep 17 00:00:00 2001 From: bobz965 Date: Mon, 5 Feb 2024 11:09:51 +0800 Subject: [PATCH] fix: ip delete use wrong key, ip delete only once Signed-off-by: bobz965 --- pkg/controller/init.go | 4 ++++ pkg/controller/ip.go | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/controller/init.go b/pkg/controller/init.go index 1c2e2b59093..262f19da50e 100644 --- a/pkg/controller/init.go +++ b/pkg/controller/init.go @@ -577,6 +577,10 @@ func (c *Controller) syncIPCR() error { for _, ipCR := range ips { ip := ipCR.DeepCopy() + if ip.DeletionTimestamp != nil && util.ContainsString(ip.Finalizers, util.ControllerName) { + klog.Infof("enqueue update for deleting ip %s", ip.Name) + c.updateIPQueue.Add(ip.Name) + } changed := false if ipMap.Has(ip.Name) && ip.Spec.PodType == "" { ip.Spec.PodType = util.VM diff --git a/pkg/controller/ip.go b/pkg/controller/ip.go index f5ad6351372..2e6c88df527 100644 --- a/pkg/controller/ip.go +++ b/pkg/controller/ip.go @@ -277,6 +277,7 @@ func (c *Controller) handleUpdateIP(key string) error { return err } if !cachedIP.DeletionTimestamp.IsZero() { + klog.Infof("handle deleting ip %s", cachedIP.Name) subnet, err := c.subnetsLister.Get(cachedIP.Spec.Subnet) if err != nil { klog.Errorf("failed to get subnet %s: %v", cachedIP.Spec.Subnet, err) @@ -317,8 +318,9 @@ func (c *Controller) handleUpdateIP(key string) error { } } if cleanIPAM { - klog.V(3).Infof("release ipam address %s for deleted ip %s from subnet %s", cachedIP.Spec.IPAddress, cachedIP.Name, cachedIP.Spec.Subnet) - c.ipam.ReleaseAddressByPod(cachedIP.Name, cachedIP.Spec.Subnet) + podKey := fmt.Sprintf("%s/%s", cachedIP.Spec.Namespace, cachedIP.Spec.PodName) + klog.Infof("ip cr %s release ipam pod key %s from subnet %s", cachedIP.Name, podKey, cachedIP.Spec.Subnet) + c.ipam.ReleaseAddressByPod(podKey, cachedIP.Spec.Subnet) } if err = c.handleDelIPFinalizer(cachedIP, util.ControllerName); err != nil { klog.Errorf("failed to handle del ip finalizer %v", err) @@ -329,7 +331,7 @@ func (c *Controller) handleUpdateIP(key string) error { } func (c *Controller) handleDelIP(ip *kubeovnv1.IP) error { - klog.V(3).Infof("handle delete ip %s from subnet %s", ip.Name, ip.Spec.Subnet) + klog.Infof("deleting ip %s enqueue update status subnet %s", ip.Name, ip.Spec.Subnet) c.updateSubnetStatusQueue.Add(ip.Spec.Subnet) for _, as := range ip.Spec.AttachSubnets { klog.V(3).Infof("enqueue update attach status for subnet %s", as)