Skip to content

Commit f03180c

Browse files
Do not garbage collect IPs of stopped VMs using non-default multus networks (#5557)
If a kubevirt VM: - is not using the default multus network - is stopped - does not have any annotation under `vm.Spec.Template.ObjectMeta.Annotations[nadv1.NetworkAttachmentAnnot]` Then GC would delete the IP of this VM. To fix, we ensure that we find the LSPs of VMs on the spec before it tries (and maybe fails) to get the LSPs defined as annotations Signed-off-by: Andrew Lee <[email protected]>
1 parent 325b583 commit f03180c

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

pkg/controller/gc.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,15 +1021,18 @@ func (c *Controller) getVMLsps() []string {
10211021
vmLsps = append(vmLsps, vmLsp)
10221022
}
10231023

1024-
attachNets, err := nadutils.ParseNetworkAnnotation(vm.Spec.Template.ObjectMeta.Annotations[nadv1.NetworkAttachmentAnnot], vm.Namespace)
1025-
if err != nil {
1026-
klog.Errorf("failed to get attachment subnet of vm %s, %v", vm.Name, err)
1027-
continue
1028-
}
1029-
for _, multiNet := range attachNets {
1030-
provider := fmt.Sprintf("%s.%s.%s", multiNet.Name, multiNet.Namespace, util.OvnProvider)
1031-
vmLsp := ovs.PodNameToPortName(vm.Name, ns.Name, provider)
1032-
vmLsps = append(vmLsps, vmLsp)
1024+
nadAnnotation := vm.Spec.Template.ObjectMeta.Annotations[nadv1.NetworkAttachmentAnnot]
1025+
if nadAnnotation != "" {
1026+
attachNets, err := nadutils.ParseNetworkAnnotation(nadAnnotation, vm.Namespace)
1027+
if err != nil {
1028+
klog.Errorf("failed to get attachment subnet of vm %s, %v", vm.Name, err)
1029+
continue
1030+
}
1031+
for _, multiNet := range attachNets {
1032+
provider := fmt.Sprintf("%s.%s.%s", multiNet.Name, multiNet.Namespace, util.OvnProvider)
1033+
vmLsp := ovs.PodNameToPortName(vm.Name, ns.Name, provider)
1034+
vmLsps = append(vmLsps, vmLsp)
1035+
}
10331036
}
10341037

10351038
for _, network := range vm.Spec.Template.Spec.Networks {

0 commit comments

Comments
 (0)