Skip to content

Conversation

andrewlee1089
Copy link
Contributor

Do not garbage collect IPs of stopped VMs using non-default multus networks

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

Pull Request

What type of this PR

Examples of user facing changes:

  • Features
  • Bug fixes
  • Docs
  • Tests

Which issue(s) this PR fixes

Fixes #5556

Copy link

Warning

Gemini encountered an error creating the summary. You can try again by commenting /gemini summary.

@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. bug Something isn't working labels Aug 5, 2025
@andrewlee1089 andrewlee1089 force-pushed the patch-3 branch 2 times, most recently from bdc96d9 to 33e50d5 Compare August 5, 2025 08:23
…tworks

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]>
@coveralls
Copy link

Pull Request Test Coverage Report for Build 16744851721

Details

  • 0 of 11 (0.0%) changed or added relevant lines in 1 file are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.005%) to 21.461%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pkg/controller/gc.go 0 11 0.0%
Files with Coverage Reduction New Missed Lines %
pkg/ovs/ovn-nb-bfd.go 2 61.61%
Totals Coverage Status
Change from base Build 16741249923: -0.005%
Covered Lines: 10569
Relevant Lines: 49247

💛 - Coveralls

@SkalaNetworks
Copy link
Contributor

What is the purpose of vm.Spec.Template.ObjectMeta.Annotations[nadv1.NetworkAttachmentAnnot] in normal conditions?

Could it be used to mount networks on the VM without using the native integration of KubeVirt?

I struggle to see why someone would append Multus networks in this annotation when they could simply use the networks of the VM. Kubevirt handles creating the annotation for us.

@oilbeater
Copy link
Collaborator

/gemini summary

Copy link

Summary of Changes

I've addressed a bug where the IP addresses of stopped Kubevirt VMs were being incorrectly garbage collected. This happened when VMs were configured with non-default Multus networks but did not have a specific network attachment annotation. My change ensures that the system correctly identifies and retains the IPs for these VMs by only attempting to process network attachment annotations when they are explicitly defined.

Highlights

  • Bug Fix: I've implemented a fix to prevent the premature garbage collection of IPs for stopped Kubevirt VMs. This issue occurred specifically when these VMs were using non-default Multus networks but lacked a specific network attachment annotation.
  • Improved Network Attachment Annotation Handling: The logic for finding Logical Switch Ports (LSPs) from Multus network annotations now includes a check to ensure the nadv1.NetworkAttachmentAnnot annotation is present and non-empty before attempting to parse it. This prevents errors and ensures that LSPs are only collected when the relevant annotation exists.
Changelog
  • pkg/controller/gc.go
    • Modified the getVMLsps function to add a conditional check for the nadv1.NetworkAttachmentAnnot annotation. Previously, the code would attempt to parse this annotation unconditionally. Now, it first verifies that the annotation string is not empty before proceeding to parse it and extract Multus network Logical Switch Ports (LSPs). This prevents errors and ensures correct LSP collection when the annotation is absent.
Activity
  • A bot reported an error when attempting to create a summary.
  • Coveralls reported that test coverage decreased by 0.005% to 21.461%, with 0% of the 11 changed or added relevant lines in pkg/controller/gc.go being covered.
  • SkalaNetworks asked for clarification on the purpose of vm.Spec.Template.ObjectMeta.Annotations[nadv1.NetworkAttachmentAnnot] in normal conditions and questioned why Multus networks would be appended to this annotation instead of using the VM's native networks.
  • oilbeater requested a new Gemini summary.

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Aug 6, 2025
@oilbeater
Copy link
Collaborator

oilbeater commented Aug 6, 2025

I struggle to see why someone would append Multus networks in this annotation when they could simply use the networks of the VM. Kubevirt handles creating the annotation for us.

I guess someone would like to inject other multus config like default-route through this way.

@oilbeater oilbeater merged commit f03180c into kubeovn:master Aug 6, 2025
136 of 138 checks passed
oilbeater pushed a commit that referenced this pull request Aug 6, 2025
…tworks (#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]>
(cherry picked from commit f03180c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working lgtm This PR has been approved by a maintainer need backport size:S This PR changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] KubeOVN garbage collects IP for stopped kubeOVN VM with non-default multus network:
4 participants