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 <[email protected]>
  • Loading branch information
lynn901 authored and bobz965 committed Dec 16, 2023
1 parent 407a26f commit d30a4cf
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 @@ -562,6 +562,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.ovnClient.ListPodLogicalSwitchPorts(key)
if err != nil {
klog.Errorf("failed to list lsps of pod '%s', %v", pod.Name, err)
Expand All @@ -575,6 +581,7 @@ func (c *Controller) changeVMSubnet(vmName, namespace, providerName, subnetName
return err
}
}
c.ipam.ReleaseAddressByPod(key, subnetName)
}
}
return nil
Expand Down

0 comments on commit d30a4cf

Please sign in to comment.