Skip to content

Commit

Permalink
keep vm vip when enableKeepVmIP is true (#3053)
Browse files Browse the repository at this point in the history
Co-authored-by: huangsm43 <huangsm43@midea.com>
  • Loading branch information
mingoooo and huangsm43 committed Jul 19, 2023
1 parent ed58b21 commit 52232b5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion pkg/controller/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -1452,6 +1452,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]
Expand All @@ -1462,7 +1463,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
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/vip.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,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 {
Expand All @@ -505,7 +505,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])
Expand Down

0 comments on commit 52232b5

Please sign in to comment.