Skip to content

Commit

Permalink
change subnet check using ip location to avoid ipam init err (#3962)
Browse files Browse the repository at this point in the history
* change subnet check using ip location to avoid ipam init err

* fix finalizer


---------

Signed-off-by: bobz965 <[email protected]>
  • Loading branch information
bobz965 committed Apr 30, 2024
1 parent f974fd4 commit 928929d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
11 changes: 5 additions & 6 deletions pkg/controller/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

Expand Down
22 changes: 8 additions & 14 deletions pkg/controller/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 928929d

Please sign in to comment.