Skip to content

Commit

Permalink
fix IP residue after changing subnet of vm in some scenarios (#3370)
Browse files Browse the repository at this point in the history
Signed-off-by: yuanliu <yuanliu_yewu@cmss.chinamobile.com>
  • Loading branch information
lynn901 authored and bobz965 committed Nov 6, 2023
1 parent f593a04 commit 366e641
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/controller/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,12 @@ func (c *Controller) changeVMSubnet(vmName, namespace, providerName, subnetName
if ipCr != nil {
if ipCr.Spec.Subnet != subnetName {
key := fmt.Sprintf("%s/%s", pod.Namespace, vmName)
if err := c.config.KubeOvnClient.KubeovnV1().IPs().Delete(context.Background(), ipName, metav1.DeleteOptions{}); err != nil {
if !k8serrors.IsNotFound(err) {
klog.Errorf("failed to delete ip %s, %v", ipName, err)
return err
}
}
ports, err := c.OVNNbClient.ListNormalLogicalSwitchPorts(true, map[string]string{"pod": key})
if err != nil {
klog.Errorf("failed to list lsps of pod '%s', %v", pod.Name, err)
Expand All @@ -534,6 +540,7 @@ func (c *Controller) changeVMSubnet(vmName, namespace, providerName, subnetName
return err
}
}
c.ipam.ReleaseAddressByPod(key)
}
}
return nil
Expand Down

0 comments on commit 366e641

Please sign in to comment.