Skip to content

Commit

Permalink
fix finalizer
Browse files Browse the repository at this point in the history
Signed-off-by: bobz965 <[email protected]>
  • Loading branch information
zbb88888 committed Apr 30, 2024
1 parent 15af50d commit 1f2a90e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
18 changes: 9 additions & 9 deletions pkg/controller/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,12 +354,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 @@ -481,7 +481,7 @@ func (c *Controller) createOrUpdateIPCR(ipCRName, podName, ip, mac, subnetName,

v4IP, v6IP := util.SplitStringIP(ip)
if ipCR == nil {
ipCR, err = c.config.KubeOvnClient.KubeovnV1().IPs().Create(context.Background(), &kubeovnv1.IP{
_, err = c.config.KubeOvnClient.KubeovnV1().IPs().Create(context.Background(), &kubeovnv1.IP{
ObjectMeta: metav1.ObjectMeta{
Name: ipName,
Labels: map[string]string{
Expand Down Expand Up @@ -539,13 +539,17 @@ func (c *Controller) createOrUpdateIPCR(ipCRName, podName, ip, mac, subnetName,
return nil
}

ipCR, err = c.config.KubeOvnClient.KubeovnV1().IPs().Update(context.Background(), newIPCR, metav1.UpdateOptions{})
_, 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); err != nil {
klog.Errorf("failed to handle add ip finalizer %v", err)
return err
}
return nil
}

Expand All @@ -560,10 +564,6 @@ func (c *Controller) subnetCountIP(subnet *kubeovnv1.Subnet) error {
klog.Error(err)
return 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
10 changes: 0 additions & 10 deletions pkg/controller/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -757,11 +757,6 @@ func (c *Controller) handleAddOrUpdateSubnet(key string) error {
return err
}

if err := c.checkSubnetUsingIPs(subnet); err != nil {
klog.Errorf("inconsistency detected in status of subnet %s : %v", subnet.Name, err)
return err
}

deleted, err := c.handleSubnetFinalizer(subnet)
if err != nil {
klog.Errorf("handle subnet finalizer failed %v", err)
Expand Down Expand Up @@ -1980,11 +1975,6 @@ func (c *Controller) reconcileU2OInterconnectionIP(subnet *kubeovnv1.Subnet) 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

0 comments on commit 1f2a90e

Please sign in to comment.