Skip to content

Commit

Permalink
do not gc vm pod lsp when vm still exists (#1558) (#1561)
Browse files Browse the repository at this point in the history
  • Loading branch information
hongzhen-ma committed May 27, 2022
1 parent a4c2ef3 commit fb1f59b
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions pkg/controller/gc.go
Expand Up @@ -288,6 +288,12 @@ func (c *Controller) markAndCleanLSP() error {
}
}

// The lsp for vm pod should not be deleted if vm still exists
vmLsps := c.getVmLsps()
for _, vmLsp := range vmLsps {
ipMap[vmLsp] = struct{}{}
}

lsps, err := c.ovnClient.ListLogicalSwitchPorts(c.config.EnableExternalVpc, nil)
if err != nil {
klog.Errorf("failed to list logical switch port, %v", err)
Expand Down Expand Up @@ -622,3 +628,34 @@ func (c *Controller) isOVNProvided(providerName string, pod *corev1.Pod) (bool,
}
return true, nil
}

func (c *Controller) getVmLsps() []string {
var vmLsps []string

if !c.config.EnableKeepVmIP {
return vmLsps
}

nss, err := c.namespacesLister.List(labels.Everything())
if err != nil {
klog.Errorf("failed to list namespaces, %v", err)
return vmLsps
}

for _, ns := range nss {
vms, err := c.config.KubevirtClient.VirtualMachine(ns.Name).List(&metav1.ListOptions{})
if err != nil {
if !k8serrors.IsNotFound(err) {
klog.Errorf("failed to list vm in namespace %s, %v", ns, err)
}
continue
} else {
for _, vm := range vms.Items {
vmLsp := ovs.PodNameToPortName(vm.Name, ns.Name, util.OvnProvider)
vmLsps = append(vmLsps, vmLsp)
}
}
}

return vmLsps
}

0 comments on commit fb1f59b

Please sign in to comment.