diff --git a/pkg/controller/ip.go b/pkg/controller/ip.go index d51148f61ef..bc255044fc9 100644 --- a/pkg/controller/ip.go +++ b/pkg/controller/ip.go @@ -358,12 +358,12 @@ func (c *Controller) syncIPFinalizer(cl client.Client) error { }) } -func (c *Controller) handleAddIPFinalizer(cachedIP *kubeovnv1.IP, finalizer string) error { +func (c *Controller) handleAddIPFinalizer(cachedIP *kubeovnv1.IP) error { if !cachedIP.DeletionTimestamp.IsZero() || len(cachedIP.GetFinalizers()) != 0 { return nil } newIP := cachedIP.DeepCopy() - controllerutil.AddFinalizer(newIP, finalizer) + controllerutil.AddFinalizer(newIP, util.KubeOVNControllerFinalizer) patch, err := util.GenerateMergePatchPayload(cachedIP, newIP) if err != nil { klog.Errorf("failed to generate patch payload for ip %s, %v", cachedIP.Name, err) @@ -545,17 +545,16 @@ func (c *Controller) createOrUpdateIPCR(ipCRName, podName, ip, mac, subnetName, ipCR, err = c.config.KubeOvnClient.KubeovnV1().IPs().Update(context.Background(), newIPCR, metav1.UpdateOptions{}) if err != nil { - err := fmt.Errorf("failed to update ip CR %s: %v", newIPCR.Name, err) + err := fmt.Errorf("failed to update ip CR %s: %v", ipCRName, err) klog.Error(err) return err } - } - if err := c.handleAddIPFinalizer(ipCR, util.KubeOVNControllerFinalizer); err != nil { + } + if err := c.handleAddIPFinalizer(ipCR); err != nil { klog.Errorf("failed to handle add ip finalizer %v", err) return err } - return nil } diff --git a/pkg/controller/subnet.go b/pkg/controller/subnet.go index 71d74ff5cb7..23cd9bf1530 100644 --- a/pkg/controller/subnet.go +++ b/pkg/controller/subnet.go @@ -933,10 +933,15 @@ func (c *Controller) handleUpdateSubnetStatus(key string) error { klog.Error(err) return err } - return nil + } else { + if _, err = c.calcSubnetStatusIP(subnet); err != nil { + klog.Error(err) + return err + } } - if _, err = c.calcSubnetStatusIP(subnet); err != nil { - klog.Error(err) + + if err := c.checkSubnetUsingIPs(subnet); err != nil { + klog.Errorf("inconsistency detected in status of subnet %s : %v", subnet.Name, err) return err } return nil @@ -2140,12 +2145,6 @@ func (c *Controller) calcDualSubnetStatusIP(subnet *kubeovnv1.Subnet) (*kubeovnv subnet.Status.V6UsingIPRange = v6UsingIPStr subnet.Status.V4AvailableIPRange = v4AvailableIPStr subnet.Status.V6AvailableIPRange = v6AvailableIPStr - - if err := c.checkSubnetUsingIPs(subnet); err != nil { - klog.Errorf("inconsistency detected in status of subnet %s : %v", subnet.Name, err) - return nil, err - } - bytes, err := subnet.Status.Bytes() if err != nil { klog.Error(err) @@ -2263,11 +2262,6 @@ func (c *Controller) calcSubnetStatusIP(subnet *kubeovnv1.Subnet) (*kubeovnv1.Su return subnet, nil } - if err := c.checkSubnetUsingIPs(subnet); err != nil { - klog.Errorf("inconsistency detected in status of subnet %s : %v", subnet.Name, err) - return nil, err - } - bytes, err := subnet.Status.Bytes() if err != nil { klog.Error(err)