Commit d3070d1
fix(controller): clean orphaned attachment IPs on KubeVirt NAD hotplug (#6519)
* fix(controller): clean orphaned attachment IPs on KubeVirt NAD hotplug
When KubeVirt VEP #140 (LiveUpdateNADRef) changes a VM's secondary
network NAD reference, the old attachment IP CR and OVN LSP were never
released because keepIPCR=true (VMI still alive). This caused IP leaks
and orphaned OVN logical switch ports.
Add getVMOrphanedAttachmentPorts() to detect attachment networks on
a VM pod that are no longer in the VM's spec.template.spec.networks.
In the keepIPCR=true branch of handleDeletePod, selectively delete
orphaned attachment LSPs and release their IPs, while preserving the
shared primary network LSP and other unchanged attachment IPs.
Only vm.Spec.Template.Spec.Networks is used as the authoritative source
(not template annotations) because VEP #140 modifies spec.networks
and template annotations may not be synced.
Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>
* fix(controller): also clean stale attachment IPs on new VM pod creation
Address review feedback: the orphaned attachment cleanup in
handleDeletePod only works when the NAD change happens before pod
deletion. In the stop→patch NAD→start workflow, the old pod deletion
is processed before the NAD patch, so stale IPs are missed.
Add cleanStaleVMAttachmentIPs() in reconcileAllocateSubnets to detect
and remove attachment LSPs/IPs that belong to the VM but are not part
of the current pod's networks. This ensures stale resources are cleaned
regardless of operation ordering.
Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>
* fix(controller): address review feedback on stale IP cleanup robustness
1. cleanStaleVMAttachmentIPs now calls getPodKubeovnNets internally
(after pod re-fetch) instead of relying on needAllocatePodNets,
which only contained nets needing allocation and would incorrectly
flag already-allocated nets as stale.
2. In keepIPCR=true branch, iterate vmOrphanedPorts directly and get
subnet name from IP CR spec instead of depending on podNets, which
could be nil if getPodKubeovnNets fails.
3. Use ipClient.WaitToBeReady for new attachment IP assertion to avoid
timing-dependent failures.
4. Add ExpectNotEmpty guard before primary IP comparison.
Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>
* fix(controller): skip IP cleanup when stale LSP deletion fails
If DeleteLogicalSwitchPort fails in cleanStaleVMAttachmentIPs, skip
the corresponding IP CR deletion and IPAM release to avoid IP conflicts
where an address is reused while its OVN port still exists.
Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>
* fix(controller): use map for orphaned ports lookup and add Patch retry
- Change vmOrphanedPorts from []string to map[string]bool for O(1)
lookup instead of O(n) slices.Contains in the port cleanup loop.
- Add PollUntilContextTimeout retry to VMClient.Patch following the
same pattern as other framework clients (handleWaitingAPIError).
Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>
* ci: install multus before kubevirt e2e tests
The new kubevirt attachment network e2e tests require Multus CRD
(NetworkAttachmentDefinition) to be available. Add kind-install-multus
before kind-install-kubevirt in CI workflows.
Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>
* fix(controller): compare OVN ports against VM spec for orphan detection
Refactor getVMOrphanedAttachmentPorts to compare OVN's actual existing
ports against the VM spec's desired ports, instead of reading stale
pod annotations via getPodAttachmentNet. The pod being deleted may not
have accurate NAD info, while OVN DB is the source of truth for what
ports actually exist.
The function now:
- Takes the existing OVN ports list (already fetched in handleDeletePod)
- Builds expected ports from vm.Spec.Template.Spec.Networks (same
pattern as gc.go getVMLsps)
- Returns ports in OVN but not in the expected set as orphaned
Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>
* refactor(controller): simplify orphaned port cleanup code
- Merge two loops in handleDeletePod keepIPCR branch into one: LSP
deletion and IP cleanup now happen in the same iteration over ports.
- Combine two iterations over VM spec.networks in
getVMOrphanedAttachmentPorts into a single pass.
- Add early exit in cleanStaleVMAttachmentIPs when OVN has no ports,
avoiding expensive getPodKubeovnNets call.
- Reorder cleanStaleVMAttachmentIPs to query OVN first (cheap) before
pod network parsing (expensive).
- Use ipCR.Spec.Subnet consistently instead of port.ExternalIDs["ls"]
for subnet name in cleanStaleVMAttachmentIPs.
Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>
---------
Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 0e0fa7d commit d3070d1
File tree
5 files changed
+378
-5
lines changed- .github/workflows
- pkg/controller
- test/e2e
- framework
- kubevirt
5 files changed
+378
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1154 | 1154 | | |
1155 | 1155 | | |
1156 | 1156 | | |
| 1157 | + | |
1157 | 1158 | | |
1158 | 1159 | | |
1159 | 1160 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
754 | 754 | | |
755 | 755 | | |
756 | 756 | | |
| 757 | + | |
757 | 758 | | |
758 | 759 | | |
759 | 760 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
728 | 728 | | |
729 | 729 | | |
730 | 730 | | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
731 | 739 | | |
732 | 740 | | |
733 | 741 | | |
| |||
1049 | 1057 | | |
1050 | 1058 | | |
1051 | 1059 | | |
| 1060 | + | |
1052 | 1061 | | |
1053 | 1062 | | |
1054 | 1063 | | |
| |||
1105 | 1114 | | |
1106 | 1115 | | |
1107 | 1116 | | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
1108 | 1124 | | |
1109 | 1125 | | |
1110 | 1126 | | |
1111 | 1127 | | |
1112 | 1128 | | |
1113 | 1129 | | |
1114 | 1130 | | |
1115 | | - | |
1116 | 1131 | | |
1117 | | - | |
1118 | | - | |
1119 | | - | |
1120 | | - | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
1121 | 1165 | | |
1122 | 1166 | | |
1123 | 1167 | | |
| |||
2407 | 2451 | | |
2408 | 2452 | | |
2409 | 2453 | | |
| 2454 | + | |
| 2455 | + | |
| 2456 | + | |
| 2457 | + | |
| 2458 | + | |
| 2459 | + | |
| 2460 | + | |
| 2461 | + | |
| 2462 | + | |
| 2463 | + | |
| 2464 | + | |
| 2465 | + | |
| 2466 | + | |
| 2467 | + | |
| 2468 | + | |
| 2469 | + | |
| 2470 | + | |
| 2471 | + | |
| 2472 | + | |
| 2473 | + | |
| 2474 | + | |
| 2475 | + | |
| 2476 | + | |
| 2477 | + | |
| 2478 | + | |
| 2479 | + | |
| 2480 | + | |
| 2481 | + | |
| 2482 | + | |
| 2483 | + | |
| 2484 | + | |
| 2485 | + | |
| 2486 | + | |
| 2487 | + | |
| 2488 | + | |
| 2489 | + | |
| 2490 | + | |
| 2491 | + | |
| 2492 | + | |
| 2493 | + | |
| 2494 | + | |
| 2495 | + | |
| 2496 | + | |
| 2497 | + | |
| 2498 | + | |
| 2499 | + | |
| 2500 | + | |
| 2501 | + | |
| 2502 | + | |
| 2503 | + | |
| 2504 | + | |
| 2505 | + | |
| 2506 | + | |
| 2507 | + | |
| 2508 | + | |
| 2509 | + | |
| 2510 | + | |
| 2511 | + | |
| 2512 | + | |
| 2513 | + | |
| 2514 | + | |
| 2515 | + | |
| 2516 | + | |
| 2517 | + | |
| 2518 | + | |
| 2519 | + | |
| 2520 | + | |
| 2521 | + | |
| 2522 | + | |
| 2523 | + | |
| 2524 | + | |
| 2525 | + | |
| 2526 | + | |
| 2527 | + | |
| 2528 | + | |
| 2529 | + | |
| 2530 | + | |
| 2531 | + | |
| 2532 | + | |
| 2533 | + | |
| 2534 | + | |
| 2535 | + | |
| 2536 | + | |
| 2537 | + | |
| 2538 | + | |
| 2539 | + | |
| 2540 | + | |
| 2541 | + | |
| 2542 | + | |
| 2543 | + | |
| 2544 | + | |
| 2545 | + | |
| 2546 | + | |
| 2547 | + | |
| 2548 | + | |
| 2549 | + | |
| 2550 | + | |
| 2551 | + | |
| 2552 | + | |
| 2553 | + | |
| 2554 | + | |
| 2555 | + | |
| 2556 | + | |
| 2557 | + | |
| 2558 | + | |
| 2559 | + | |
| 2560 | + | |
| 2561 | + | |
| 2562 | + | |
| 2563 | + | |
| 2564 | + | |
| 2565 | + | |
| 2566 | + | |
| 2567 | + | |
| 2568 | + | |
| 2569 | + | |
| 2570 | + | |
| 2571 | + | |
| 2572 | + | |
| 2573 | + | |
| 2574 | + | |
| 2575 | + | |
| 2576 | + | |
2410 | 2577 | | |
2411 | 2578 | | |
2412 | 2579 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
| |||
176 | 178 | | |
177 | 179 | | |
178 | 180 | | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
179 | 221 | | |
180 | 222 | | |
181 | 223 | | |
| |||
0 commit comments