Skip to content

Commit

Permalink
fix: calculate subnet before handle finalizer
Browse files Browse the repository at this point in the history
Signed-off-by: bobz965 <[email protected]>
  • Loading branch information
bobz965 committed Nov 30, 2023
1 parent 45cee57 commit 69c6382
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
8 changes: 4 additions & 4 deletions pkg/controller/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ import (

func (c *Controller) enqueueAddOrDelIP(obj interface{}) {
ipObj := obj.(*kubeovnv1.IP)
klog.V(3).Infof("enqueue update status subnet %s", ipObj.Spec.Subnet)
klog.Infof("enqueue update status subnet %s", ipObj.Spec.Subnet)
if strings.HasPrefix(ipObj.Name, util.U2OInterconnName[0:19]) {
return
}
c.updateSubnetStatusQueue.Add(ipObj.Spec.Subnet)
for _, as := range ipObj.Spec.AttachSubnets {
klog.V(3).Infof("enqueue update status subnet %s", as)
klog.Infof("enqueue update attach status for subnet %s", as)
c.updateSubnetStatusQueue.Add(as)
}
}

func (c *Controller) enqueueUpdateIP(_, newObj interface{}) {
ipObj := newObj.(*kubeovnv1.IP)
klog.V(3).Infof("enqueue update status subnet %s", ipObj.Spec.Subnet)
klog.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.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 @@ -692,14 +692,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.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 @@ -716,16 +726,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 69c6382

Please sign in to comment.