From 69c63825a35fa535a3517757c0c83b33fe2a818e Mon Sep 17 00:00:00 2001 From: bobz965 Date: Mon, 27 Nov 2023 10:37:53 +0800 Subject: [PATCH] fix: calculate subnet before handle finalizer Signed-off-by: bobz965 --- pkg/controller/ip.go | 8 ++++---- pkg/controller/subnet.go | 22 +++++++++++----------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/pkg/controller/ip.go b/pkg/controller/ip.go index 6de106e6a9e9..267a9e32c56d 100644 --- a/pkg/controller/ip.go +++ b/pkg/controller/ip.go @@ -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) } } diff --git a/pkg/controller/subnet.go b/pkg/controller/subnet.go index 2ab5a56c7635..9248dfc65d83 100644 --- a/pkg/controller/subnet.go +++ b/pkg/controller/subnet.go @@ -692,7 +692,7 @@ 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 { @@ -700,6 +700,16 @@ func (c *Controller) handleAddOrUpdateSubnet(key string) error { 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) @@ -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 }