Skip to content

Commit

Permalink
do not gc vm pod lsp when vm still exists (#1558)
Browse files Browse the repository at this point in the history
  • Loading branch information
hongzhen-ma committed May 26, 2022
1 parent 4a28c01 commit 81781a0
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions pkg/controller/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ func (c *Controller) markAndCleanLSP() error {
}
}

// The lsp for vm pod should not be deleted if vm still exists
vmLsps := c.getVmLsps()
ipNames = append(ipNames, vmLsps...)

lsps, err := c.ovnClient.ListLogicalSwitchPort(c.config.EnableExternalVpc)
if err != nil {
klog.Errorf("failed to list logical switch port, %v", err)
Expand Down Expand Up @@ -575,3 +579,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 81781a0

Please sign in to comment.