Skip to content

Commit

Permalink
keep vm vip when enableKeepVmIP is true
Browse files Browse the repository at this point in the history
  • Loading branch information
huangsm43 committed Jul 19, 2023
1 parent fa404a0 commit 94621b0
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 @@ -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]
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/vip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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])
Expand Down

0 comments on commit 94621b0

Please sign in to comment.