Repository navigation
hypervisor/kubevirt: base halted state on the whole workload - #6529
andrewd-zededa wants to merge 1 commit into
Conversation
Info() reported HALTED as soon as the VMIRS Get returned NotFound. The three objects form an ownership chain: the VMIRS owns the VMI, and the VMI owns the virt-launcher pod. EVE deletes only the VMIRS, so it is the first to go, and Kubernetes then collects its dependents in the background. The pod holds the RWO disk until it goes away. A domain was therefore reported as halted while its workload still ran. A peer that stands in for a downed node reads that state to decide if an app is really down, and a controller reads it to decide the app can move. Both can act too early. Info() now takes the state from the existence of the VMIRS, the VMI and the pod, each found by its App-Domain-Name label. An absent VMIRS with a surviving dependent gives HALTING and keeps a non-zero DomainId, because a zero DomainId is the confirmed-absent token. HALTED with a zero DomainId needs all three to be absent. The dependent lookup runs only on the absent-VMIRS branch, so a steady-state poll makes no more API calls than it did before. A config apply must not wait for this. A kubevirt deactivate now publishes HALTING, deletes the VMIRS, and returns. verifyStatus settles the state and releases the resources when Info reports all three objects absent. Kubernetes owns how long that takes, and on a node that is off it has no end, so no budget on the config path is the correct one. The paths that must finish before they return keep their behavior, because impatient is already true for them: handleDelete unpublishes DomainStatus as soon as it returns, and a purge or a restart advances its counter only after the teardown clears status.Activated. Two other reads of HALTING had to be separated from this one. waitForDomainGone took it for a guest that powered off while its hypervisor process stayed parked and held resources, a qemu -no-shutdown condition, so it stopped waiting and let the caller reap the domain. verifyStatus took it for a teardown to finish now. Under kubevirt HALTING is the reverse of both: nothing is parked, and Kubernetes is still at work. Both short circuits now apply to the other hypervisors only. Start() already waits for a stale generation to disappear, object and pods, before it creates the next one, because generations share the disk and the veth names. That is what keeps an asynchronous deactivate safe beside a create. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Signed-off-by: Andrew Durbin <andrewd@zededa.com>
cf1dd14 to
ff6f34d
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6529 +/- ##
==========================================
+ Coverage 25.96% 26.31% +0.35%
==========================================
Files 514 524 +10
Lines 94543 96324 +1781
==========================================
+ Hits 24547 25349 +802
- Misses 68103 68880 +777
- Partials 1893 2095 +202 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Claude finished @eriknordmark's task in 4m 27s —— View job Code reviewI reviewed the state-derivation logic in
Findings
Everything else — |
| status.DomainId = 0 | ||
| doCleanup(ctx, status) | ||
| } | ||
| status.DomainId = 0 |
There was a problem hiding this comment.
This unconditional status.DomainId = 0 defeats the very invariant this PR builds. During an async kubevirt deactivate, Info can return (DomainId, UNKNOWN, err) when the VMIRS is gone but the VMI/pod dependent check itself fails (transient API error) — confirmedAbsent deliberately preserves the id in that case. But here in verifyStatus, err != nil enters the outer if, configActivate is false so the recovery branch is skipped, and kubevirtDeactivateComplete is false (state is UNKNOWN, not HALTED), so control falls straight through to this line and publishes a zero DomainId — the confirmed-absent token — without absence ever being confirmed.
That exposes exactly the premature "workload gone" signal to peers/controller that the PR is meant to prevent, and it's sticky: once status.DomainId is 0, confirmedAbsent returns 0 for the rest of the reap (it echoes t.status.DomainId), so the domain reports gone for the whole remaining teardown window.
Consider guarding the zeroing for kubevirt when absence is not confirmed, e.g. skip it when ctx.hvTypeKube && !configActivate && err != nil (hold the id and let a later tick settle via kubevirtDeactivateComplete).
| if err := DomainShutdown(ctx, *status, false); err != nil { | ||
| log.Errorf("doInactivate(%s) Shutdown failed: %s", status.Key(), err) | ||
| } | ||
| return |
There was a problem hiding this comment.
In the async path a failed DomainShutdown (VMIRS delete) is only logged, then the function returns with State=HALTING and Activated=true while the VMIRS still exists. verifyStatus will then observe SCHEDULING/RUNNING (not absent) and take its rescheduling/running arm rather than retrying the delete, and nothing re-drives the teardown until the next config change — so a transient delete failure can silently leave a deactivated app running. Worth reconsidering whether the async path should retry or leave Activated/state such that the teardown is re-attempted.
eriknordmark
left a comment
There was a problem hiding this comment.
Andrew, some comments from claude to look at, where at least the first one looks like a real concern.
Measured on hardware: this eliminates the zero-byte data loss in #6495I have been tracking the failure #6495 describes — a tight write-then-restart of a Baseline, image without this change, measured over six days of soaking:
With this PR cherry-picked onto the same base, same device, same guest OS, same
P(0 losses in 30) at the baseline rate is 2.3e-05. A "tight cycle" is write → restart-request with a sub-second-to-few-second gap; the Method, so the result can be discounted appropriately:
Caveat: the image under test carries this PR and an unrelated local change raising The mechanism matches: |
eriknordmark
left a comment
There was a problem hiding this comment.
Note that this passes my previously failing tests - see details. Kicking off regression tests.
But still need to look at claude's review comments.
Correction to my 2026-09-19 measurement commentMy earlier comment reported 30 driven tight cycles with 0 losses as evidence this PR eliminates the zero-byte read in #6495. That result does not test this PR, and I am withdrawing it. The driver defaults to The arithmetic in that comment is sound but attaches to the wrong cause. The cycles were genuinely in the loss regime: all 29 derivable ages land at 150–174 s, inside the 123–174 s band where the baseline losses occur, so the zero is not explained by cycles being too slow to reach the window. What replaces itA Kill-vs-clean is decided host-side, from virt-launcher's repeated One methodological note for anyone reproducing this: the guest's own journal cannot be used to tell a kill from a clean stop. journald's At least one loss among tested cycles would confirm the mechanism. Zero would not refute it: there is no baseline loss rate under this classifier to test against, and establishing one would mean running the baseline image the same way. Two figures above are not re-derived in this pass and should not be mixed: the in-band loss rate I quote is 6 losses in 18 in-band reads of ztest's own |
|
This merged via #6505. I'll rebase with just the fixes requested in review and update comments/description |
|
This landed in master through #6505 — this change was its second commit, and #6505 merged on 2026-09-23 as Master carries it one refactor further: the pod lookup is The only thing here that master lacks is So rebasing this would re-apply the halted-state change and revert the |
|
@andrewd-zededa so per @eriknordmark's comments, can we close it? |
|
yes I'll close it. |
Description
Info() reported HALTED as soon as the VMIRS Get returned NotFound. The three objects form an ownership chain: the VMIRS owns the VMI, and the VMI owns the virt-launcher pod. EVE deletes only the VMIRS, so it is the first to go, and Kubernetes then collects its dependents in the background. The pod holds the RWO disk until it goes away.
A domain was therefore reported as halted while its workload still ran. A peer that stands in for a downed node reads that state to decide if an app is really down, and a controller reads it to decide the app can move. Both can act too early.
Info() now takes the state from the existence of the VMIRS, the VMI and the pod, each found by its App-Domain-Name label. An absent VMIRS with a surviving dependent gives HALTING and keeps a non-zero DomainId, because a zero DomainId is the confirmed-absent token. HALTED with a zero DomainId needs all three to be absent. The dependent lookup runs only on the absent-VMIRS branch, so a steady-state poll makes no more API calls than it did before.
A config apply must not wait for this. A kubevirt deactivate now publishes HALTING, deletes the VMIRS, and returns. verifyStatus settles the state and releases the resources when Info reports all three objects absent. Kubernetes owns how long that takes, and on a node that is off it has no end, so no budget on the config path is the correct one.
The paths that must finish before they return keep their behavior, because impatient is already true for them: handleDelete unpublishes DomainStatus as soon as it returns, and a purge or a restart advances its counter only after the teardown clears status.Activated.
Two other reads of HALTING had to be separated from this one. waitForDomainGone took it for a guest that powered off while its hypervisor process stayed parked and held resources, a qemu -no-shutdown condition, so it stopped waiting and let the caller reap the domain. verifyStatus took it for a teardown to finish now. Under kubevirt HALTING is the reverse of both: nothing is parked, and Kubernetes is still at work. Both short circuits now apply to the other hypervisors only.
Start() already waits for a stale generation to disappear, object and pods, before it creates the next one, because generations share the disk and the veth names. That is what keeps an asynchronous deactivate safe beside a create.
PR dependencies
None
How to test and validate this PR
pillar go-test:
Covers the VMIRS/VMI/pod state combinations, the async-deactivate hand-off, and the resulting HALTED/HALTING transitions without a live cluster.
evetest
Coming in PR #6505
Changelog notes
EVE could report an application halted before Kubernetes had actually torn it down (its VM instance or pod could still be running). App halted/running status now reflects the real state of the workload, and deactivating an app no longer blocks device configuration while Kubernetes finishes the teardown in the background.
PR Backports
Checklist
And the last but not least:
check them.
Please, check the boxes above after submitting the PR in interactive mode.