Skip to content

Commit

Permalink
fix: ip delete use wrong key, ip delete only once (#3698)
Browse files Browse the repository at this point in the history
Signed-off-by: bobz965 <zhangbingbing2_yewu@cmss.chinamobile.com>
  • Loading branch information
bobz965 authored Feb 5, 2024
1 parent d3ef892 commit a28af4a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 4 additions & 0 deletions pkg/controller/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions pkg/controller/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit a28af4a

Please sign in to comment.