Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keep vm vip when enableKeepVmIP is true #3053

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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