diff --git a/pkg/controller/pod.go b/pkg/controller/pod.go index 6fd970bbce3..e934cbbfcae 100644 --- a/pkg/controller/pod.go +++ b/pkg/controller/pod.go @@ -1367,6 +1367,7 @@ func (c *Controller) acquireAddress(pod *v1.Pod, podNet *kubeovnNet) (string, st podName := c.getNameByPod(pod) key := fmt.Sprintf("%s/%s", pod.Namespace, podName) + var isVMPod bool isStsPod, _ := isStatefulSetPod(pod) // if pod has static vip vipName := pod.Annotations[util.VipAnnotation] @@ -1377,7 +1378,10 @@ func (c *Controller) acquireAddress(pod *v1.Pod, podNet *kubeovnNet) (string, st return "", "", "", podNet.Subnet, err } portName := ovs.PodNameToPortName(podName, pod.Namespace, podNet.ProviderName) - if err = c.podReuseVip(vipName, portName, isStsPod); err != nil { + if c.config.EnableKeepVmIP { + isVMPod, _ = isVmPod(pod) + } + if err = c.podReuseVip(vipName, portName, isStsPod || isVMPod); err != nil { return "", "", "", podNet.Subnet, err } return vip.Status.V4ip, vip.Status.V6ip, vip.Status.Mac, podNet.Subnet, nil diff --git a/pkg/controller/vip.go b/pkg/controller/vip.go index ed9a958920c..a59bc275b22 100644 --- a/pkg/controller/vip.go +++ b/pkg/controller/vip.go @@ -439,7 +439,7 @@ func (c *Controller) patchVipStatus(key, v4ip string, ready bool) error { return nil } -func (c *Controller) podReuseVip(key, portName string, isStsPod bool) error { +func (c *Controller) podReuseVip(key, portName string, keepVIP bool) error { // when pod use static vip, label vip reserved for pod oriVip, err := c.virtualIpsLister.Get(key) if err != nil { @@ -453,7 +453,7 @@ func (c *Controller) podReuseVip(key, portName string, isStsPod bool) error { var op string if vip.Labels[util.IpReservedLabel] != "" { - if isStsPod && vip.Labels[util.IpReservedLabel] == portName { + if keepVIP && vip.Labels[util.IpReservedLabel] == portName { return nil } else { return fmt.Errorf("vip '%s' is in use by pod %s", vip.Name, vip.Labels[util.IpReservedLabel])