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
bobz965 committed Apr 30, 2024
1 parent 15af50d commit 72aa01d
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 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 Down

0 comments on commit 72aa01d

Please sign in to comment.