Skip to content

Commit 52232b5

Browse files
mingoooohuangsm43
and
huangsm43
authored
keep vm vip when enableKeepVmIP is true (#3053)
Co-authored-by: huangsm43 <huangsm43@midea.com>
1 parent ed58b21 commit 52232b5

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

pkg/controller/pod.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -1452,6 +1452,7 @@ func (c *Controller) acquireAddress(pod *v1.Pod, podNet *kubeovnNet) (string, st
14521452
podName := c.getNameByPod(pod)
14531453
key := fmt.Sprintf("%s/%s", pod.Namespace, podName)
14541454

1455+
var isVMPod bool
14551456
isStsPod, _ := isStatefulSetPod(pod)
14561457
// if pod has static vip
14571458
vipName := pod.Annotations[util.VipAnnotation]
@@ -1462,7 +1463,10 @@ func (c *Controller) acquireAddress(pod *v1.Pod, podNet *kubeovnNet) (string, st
14621463
return "", "", "", podNet.Subnet, err
14631464
}
14641465
portName := ovs.PodNameToPortName(podName, pod.Namespace, podNet.ProviderName)
1465-
if err = c.podReuseVip(vipName, portName, isStsPod); err != nil {
1466+
if c.config.EnableKeepVmIP {
1467+
isVMPod, _ = isVmPod(pod)
1468+
}
1469+
if err = c.podReuseVip(vipName, portName, isStsPod || isVMPod); err != nil {
14661470
return "", "", "", podNet.Subnet, err
14671471
}
14681472
return vip.Status.V4ip, vip.Status.V6ip, vip.Status.Mac, podNet.Subnet, nil

pkg/controller/vip.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ func (c *Controller) patchVipStatus(key, v4ip string, ready bool) error {
491491
return nil
492492
}
493493

494-
func (c *Controller) podReuseVip(key, portName string, isStsPod bool) error {
494+
func (c *Controller) podReuseVip(key, portName string, keepVIP bool) error {
495495
// when pod use static vip, label vip reserved for pod
496496
oriVip, err := c.virtualIpsLister.Get(key)
497497
if err != nil {
@@ -505,7 +505,7 @@ func (c *Controller) podReuseVip(key, portName string, isStsPod bool) error {
505505
var op string
506506

507507
if vip.Labels[util.IpReservedLabel] != "" {
508-
if isStsPod && vip.Labels[util.IpReservedLabel] == portName {
508+
if keepVIP && vip.Labels[util.IpReservedLabel] == portName {
509509
return nil
510510
} else {
511511
return fmt.Errorf("vip '%s' is in use by pod %s", vip.Name, vip.Labels[util.IpReservedLabel])

0 commit comments

Comments
 (0)