Skip to content

Commit

Permalink
fix: calculate subnet before handle finalizer (#3469)
Browse files Browse the repository at this point in the history
* fix: calculate subnet before handle finalizer
---------

Signed-off-by: bobz965 <zhangbingbing2_yewu@cmss.chinamobile.com>
  • Loading branch information
bobz965 committed Dec 1, 2023
1 parent 739825f commit 1476c0a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions pkg/controller/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (c *Controller) enqueueAddOrDelIP(obj interface{}) {
}
c.updateSubnetStatusQueue.Add(ipObj.Spec.Subnet)
for _, as := range ipObj.Spec.AttachSubnets {
klog.V(3).Infof("enqueue update status subnet %s", as)
klog.V(3).Infof("enqueue update attach status for subnet %s", as)
c.updateSubnetStatusQueue.Add(as)
}
}
Expand All @@ -31,7 +31,7 @@ func (c *Controller) enqueueUpdateIP(_, newObj interface{}) {
ipObj := newObj.(*kubeovnv1.IP)
klog.V(3).Infof("enqueue update status subnet %s", ipObj.Spec.Subnet)
for _, as := range ipObj.Spec.AttachSubnets {
klog.V(3).Infof("enqueue update status subnet %s", as)
klog.V(3).Infof("enqueue update status for attach subnet %s", as)
c.updateSubnetStatusQueue.Add(as)
}
}
22 changes: 11 additions & 11 deletions pkg/controller/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -691,14 +691,24 @@ func (c *Controller) handleAddOrUpdateSubnet(key string) error {
klog.Error(err)
return err
}
klog.V(4).Infof("handle add or update subnet %s", cachedSubnet.Name)
klog.V(3).Infof("handle add or update subnet %s", cachedSubnet.Name)

subnet, err := formatSubnet(cachedSubnet.DeepCopy(), c)
if err != nil {
klog.Error(err)
return err
}

if subnet.Spec.Protocol == kubeovnv1.ProtocolDual {
err = calcDualSubnetStatusIP(subnet, c)
} else {
err = calcSubnetStatusIP(subnet, c)
}
if err != nil {
klog.Errorf("calculate subnet %s used ip failed, %v", subnet.Name, err)
return err
}

deleted, err := c.handleSubnetFinalizer(subnet)
if err != nil {
klog.Errorf("handle subnet finalizer failed %v", err)
Expand All @@ -715,16 +725,6 @@ func (c *Controller) handleAddOrUpdateSubnet(key string) error {
}
c.patchSubnetStatus(subnet, "ValidateLogicalSwitchSuccess", "")

if subnet.Spec.Protocol == kubeovnv1.ProtocolDual {
err = calcDualSubnetStatusIP(subnet, c)
} else {
err = calcSubnetStatusIP(subnet, c)
}
if err != nil {
klog.Errorf("calculate subnet %s used ip failed, %v", subnet.Name, err)
return err
}

if err := c.ipam.AddOrUpdateSubnet(subnet.Name, subnet.Spec.CIDRBlock, subnet.Spec.Gateway, subnet.Spec.ExcludeIps); err != nil {
return err
}
Expand Down

0 comments on commit 1476c0a

Please sign in to comment.