|
| 1 | +diff --git a/pkg/controller/pod.go b/pkg/controller/pod.go |
| 2 | +--- a/pkg/controller/pod.go |
| 3 | ++++ b/pkg/controller/pod.go |
| 4 | +@@ -1061,6 +1061,7 @@ |
| 5 | + } |
| 6 | + } |
| 7 | + } |
| 8 | ++ var hasAliveVMSibling bool |
| 9 | + isVMPod, vmName := isVMPod(pod) |
| 10 | + if isVMPod && c.config.EnableKeepVMIP { |
| 11 | + ports, err := c.OVNNbClient.ListNormalLogicalSwitchPorts(true, map[string]string{"pod": podKey}) |
| 12 | +@@ -1081,6 +1082,18 @@ |
| 13 | + if !isOwnerRefToDel { |
| 14 | + klog.Infof("try keep ip for vm pod %s", podKey) |
| 15 | + keepIPCR = true |
| 16 | ++ // The VM LSP is shared across every virt-launcher pod of the VM |
| 17 | ++ // (ExternalIDs["pod"] is keyed by VM name). Port-group memberships, |
| 18 | ++ // however, belong to whichever virt-launcher pod is currently |
| 19 | ++ // running the VM. If another live sibling exists (e.g. a |
| 20 | ++ // live-migration destination while the completed source is being |
| 21 | ++ // GC'd), its memberships must not be wiped out. |
| 22 | ++ siblings, listErr := c.podsLister.Pods(pod.Namespace).List(labels.Everything()) |
| 23 | ++ if listErr != nil { |
| 24 | ++ klog.Errorf("failed to list pods in namespace %s: %v", pod.Namespace, listErr) |
| 25 | ++ return listErr |
| 26 | ++ } |
| 27 | ++ hasAliveVMSibling = hasAliveSiblingVMPod(siblings, vmName, pod.Name) |
| 28 | + } |
| 29 | + } |
| 30 | + if keepIPCR { |
| 31 | +@@ -1106,12 +1119,18 @@ |
| 32 | + return err |
| 33 | + } |
| 34 | + if keepIPCR { |
| 35 | +- // always remove lsp from port groups |
| 36 | +- for _, port := range ports { |
| 37 | +- klog.Infof("remove lsp %s from all port groups", port.Name) |
| 38 | +- if err = c.OVNNbClient.RemovePortFromPortGroups(port.Name); err != nil { |
| 39 | +- klog.Errorf("failed to remove lsp %s from all port groups: %v", port.Name, err) |
| 40 | +- return err |
| 41 | ++ // always remove lsp from port groups, unless another live virt-launcher |
| 42 | ++ // pod owns the memberships (e.g. live-migration destination while the |
| 43 | ++ // completed source is being GC'd). |
| 44 | ++ if hasAliveVMSibling { |
| 45 | ++ klog.Infof("skip removing lsp from port groups: another alive virt-launcher pod exists for vm %s/%s", pod.Namespace, vmName) |
| 46 | ++ } else { |
| 47 | ++ for _, port := range ports { |
| 48 | ++ klog.Infof("remove lsp %s from all port groups", port.Name) |
| 49 | ++ if err = c.OVNNbClient.RemovePortFromPortGroups(port.Name); err != nil { |
| 50 | ++ klog.Errorf("failed to remove lsp %s from all port groups: %v", port.Name, err) |
| 51 | ++ return err |
| 52 | ++ } |
| 53 | + } |
| 54 | + } |
| 55 | + } else { |
| 56 | +@@ -2358,6 +2377,27 @@ |
| 57 | + return false, "" |
| 58 | + } |
| 59 | + |
| 60 | ++// hasAliveSiblingVMPod reports whether pods contains any alive virt-launcher |
| 61 | ++// pod owned by the VMI vmName, excluding the pod with name excludePodName. |
| 62 | ++// It is used to decide whether a VM LSP's port-group memberships are still |
| 63 | ++// owned by another running sibling (e.g. a live-migration destination) when a |
| 64 | ++// completed/GC'd source pod is being processed. |
| 65 | ++func hasAliveSiblingVMPod(pods []*v1.Pod, vmName, excludePodName string) bool { |
| 66 | ++ for _, p := range pods { |
| 67 | ++ if p == nil || p.Name == excludePodName { |
| 68 | ++ continue |
| 69 | ++ } |
| 70 | ++ isVM, name := isVMPod(p) |
| 71 | ++ if !isVM || name != vmName { |
| 72 | ++ continue |
| 73 | ++ } |
| 74 | ++ if isPodAlive(p) { |
| 75 | ++ return true |
| 76 | ++ } |
| 77 | ++ } |
| 78 | ++ return false |
| 79 | ++} |
| 80 | ++ |
| 81 | + func isOwnsByTheVM(vmi metav1.Object) (bool, string) { |
| 82 | + for _, owner := range vmi.GetOwnerReferences() { |
| 83 | + if owner.Kind == util.KindVirtualMachine && |
0 commit comments