Repository navigation
kubevirt: keep domain bookkeeping until Cleanup - #6271
Conversation
12beebb to
431cc4d
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6271 +/- ##
==========================================
+ Coverage 24.65% 25.01% +0.35%
==========================================
Files 516 526 +10
Lines 94177 95905 +1728
==========================================
+ Hits 23222 23986 +764
- Misses 69090 69872 +782
- Partials 1865 2047 +182 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Correcting the hardware section I posted earlier today: it claimed the guest data What the change does do. Restart-request to app-online went from 34–100 s Why that is not enough. The state never resolves, the 63 s backoff expires, and the replacement is created Data survival. Only the cycle where the restart is issued immediately after Net: the three commits are still correct in themselves — the bookkeeping and the Separately, both cycles log |
|
|
||
| // The vmiList entry must outlive Stop: Info() resolves a domain through | ||
| // it, and domainmgr polls Info() to learn when the guest actually | ||
| // stopped. Delete() and Cleanup() own the removal. |
There was a problem hiding this comment.
in the Info(), this will allow the function to find the 'vmis' struct, and move on, but later, in the scheduledOnMe():
onMe, _, err := ctx.scheduledOnMe(vmis.mtype, vmis.name)
if err != nil {
if isK3sUnreachable(err) {
return 0, types.UNKNOWN, nil
}
return 0, types.BROKEN, logError("Failed to determine scheduled node: %s", err)
}
if it is deleted in the kuberntes cluster, it is going to return here the types.BROKEN. which is also a problem.
Mayin in the 'vmis' struct, we can add a 'pendingOnDelete' bool, and set it here. Over in the Info(), checks on this bool on error, and return Unknown still.
There was a problem hiding this comment.
types.BROKEN is gone — #6257 rewrote Info() to confirm existence with its own Get first, so a deleted VMIRS returns HALTED/zero before scheduledOnMe runs. That is also why I didn't add pendingOnDelete: the live Get answers it better than a flag, which would be wrong if the delete itself failed.
The case underneath your comment is still real though. Info now Gets the same VMIRS up to three times, and a delete landing after the first is caught by none of them — the second's NotFound is dropped by the fall-through, the third ends at return id, types.SCHEDULING, err. waitForDomainGone returns true on any Info error before it looks at the state, so the race ends the graceful wait early.
Fixed in 5fafb53: errors.IsNotFound -> 0, HALTED, nil at both lookups, with a test that fails without it. Does that cover what you meant?
There was a problem hiding this comment.
I think this code added is fine. but I think there is still a problem on the ScheduledOnMe() in the deletion case:
the function checks the VMIRS first, if this is gone, it returns 'not found', I think the problem is that, even the VMIRS can be removed quickly, the VMI itself may still stay around fairly longer. So, this deletion case, I think we need the same check as confirmVMIRSGone() to verify.
There was a problem hiding this comment.
The code you quoted is gone: #6257 merged on Aug 14 and replaced it. Info() no longer derives existence from scheduledOnMe — it starts with replicaSetUID(kubeName), and NotFound there is the confirmed-absent answer. This PR only adds the backstops for absence observed later in the same call.
The underlying point stands though, and #6257 handles it at creation rather than in Info: Start calls sweepStaleGenerations, which deletes each stale VMIRS and then waits in confirmVMIRSGone until both the object and its kubevirt.io=virt-launcher pods are gone before the next generation is created. Gating Info instead would only delay the answer domainmgr is polling for, which just needs to know the workload is down.
Does that cover what you had in mind, or do you see a path to creating a generation that bypasses sweepStaleGenerations?
431cc4d to
260c5a0
Compare
|
Heads-up on a force-push that changes what this PR contains. This branch is now based on #6257. Its two commits are the base here, included Consequences worth flagging rather than leaving to be discovered in the diff:
On testing: the two substantive commits have since been exercised in the 7-leg When #6257 merges I will rebase and its commits will drop out. It force-pushes often, so |
|
Correction to my comment above: it said the included #6257 commits are "at On why the base is not #6257's current tip: #6257's latest pillar commit Reproducible on @andrewd-zededa flagging the build break on your side. Nothing else about this PR changed: the branch head is still |
Replaces the three lf-edge#6271 kubevirt commits with lf-edge#6257 at df8ae7c plus the two of them that survive on top of it, since lf-edge#6257 fixes the VMIRS-delete logging the same way and rewrites Info to derive DomainId from a live Get rather than vmiList. Adds the proposed volumemgr readiness-publish follow-up to lf-edge#6240. Also records that lf-edge#5971 and rucoder#3 are held at the tips the 7/7 image used rather than caught up, so the bring-up baseline is not a variable in this run. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
A failed VMIRS delete logged only the error, so an operator reading the log could not tell which app's replicaset failed to go away -- and this path fires during every teardown that races the Kubernetes API. Include the replicaset name, and drop the trailing newline that logrus adds itself. Also records lf-edge#6271's presence in the branch composition table, including which of its commits lf-edge#6257 supersedes, and corrects the lf-edge#6190 row: the fault-injection gates are compiled in whenever the build arg is non-empty, not only when it is y. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
260c5a0 to
fc0f374
Compare
|
Rebased onto #6257's The three Re-derived after the rebase, since #6257 reworked The description now names |
…rkers The lf-edge#6257 replay left conflict markers in four hypervisor files. Take the lf-edge#6257 side, matching how the same overlap was resolved on the newgo line. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Signed-off-by: eriknordmark <erik@zededa.com>
d66956b to
0282bd8
Compare
|
I converted this to draft to make sure it is not merged before #6257, which this PR is based on |
0282bd8 to
b4b2723
Compare
domainmgr asks the hypervisor to shut a domain down and then polls Info() until it reports the domain gone, before creating any replacement. Stop() dropped the vmiList entry Info() needs in order to read the guest's phase, so after Stop every poll could only answer SCHEDULING -- never the HALTED that ends the wait. domainmgr therefore polls out the entire graceful-shutdown budget and escalates to a forced shutdown even when KubeVirt stopped the guest promptly. Leave the entry in place in Stop and remove it in Cleanup, the unconditional tail of doInactivate. Delete cannot own the removal: it only runs while DomainId is still set, which is no longer true once the domain goes away during the graceful wait, and Cleanup's IsMetaReplicaVMI path did not remove it either. The removal is deferred so a Cleanup that fails partway still releases the entry. On EVE-kvm the same sequence polls real domain state throughout, because the containerd-backed Stop it inherits keeps no such bookkeeping. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Delete asked scheduledOnMe() which node the domain is placed on and then discarded its error. A failed lookup -- a failed config load, a missing node name, an unreachable client, or a ReplicaSet Get that did not answer -- reports onMe=false, which is indistinguishable from the legitimate "scheduled on another node" case tested on the next line. Delete therefore returned nil, reporting a successful teardown to domainmgr while deleting nothing, whenever the Kubernetes API was briefly unavailable. Check the error and return it, as Stop already does with the same call. domainmgr logs a Delete failure and waits for the domain regardless, so the retry behaviour is unchanged. Note this also surfaces an already-deleted ReplicaSet as a Delete error rather than a silent success, since the lookup's Get reports NotFound through the same path. That is a louder log on a teardown that had nothing left to do; softening it would need the lookup to distinguish NotFound from a genuine API failure, which it currently does not. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
A failed VMIRS delete logged only the error, so an operator reading the log could not tell which app's replicaset failed to go away -- and this path fires during every teardown that races the Kubernetes API. Include the replicaset name, and drop the trailing newline that logrus adds itself. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Info confirms the replicaset exists and then fetches it again to read the guest's phase. A workload deleted between those two calls made the second lookup fail with NotFound, which Info reported as an error alongside a still-scheduling state; domainmgr's wait for the domain to disappear treats any such error as "already gone" and stops waiting. That is the same early return the graceful wait exists to prevent, reached through a narrower window. Absence is now reported identically wherever it is observed, which also drops a redundant lookup of an object already known to be gone. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
b4b2723 to
6df3bfb
Compare
Records the composition after recreating the branch on master: the conversion chain via fork#6, plus lf-edge#6271 and lf-edge#6314, plus the three branch-local changes a PR-only replay would drop. Notes the k build tag, without which most of the newly integrated code is never compiled. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Records the composition after recreating the branch on master: the chaos conversion chain via fork#7, plus lf-edge#6271 and lf-edge#6314, plus the branch-local PVC reclaim a PR-only replay would drop. Restates that this line only exercises the fault gates when the build passes FAULT_INJECTION, and where the rootfs cap and the storage-resizer pin come from. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Records the composition after recreating the branch on master: the conversion chain via fork#6, plus lf-edge#6271 and lf-edge#6314, plus the three branch-local changes a PR-only replay would drop. Notes the k build tag, without which most of the newly integrated code is never compiled. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
|
||
| delete(ctx.prevDomainMetric, keyToDelete) | ||
|
|
||
| // The vmiList entry must outlive Stop: Info() needs it to read the guest's |
There was a problem hiding this comment.
While this hunk redefines what Stop does and does not own, the force
argument beside it is still never read: it occurs exactly once in the function,
in the signature. Because it is named force rather than _, nothing flags
it, so the call site reads as though it were honoured.
The other backends do act on it -- xen appends -F to xl shutdown
(xen.go:482), containerd passes it through to CtrStopContainer
(containerd.go:185) -- and kvm was just fixed to do the same in #6441, which
leaves KubeVirt as the one backend where a forced stop is identical to a
graceful one. The caller that matters is domainmgr's doInactivate: it
escalates to Stop(..., true) once the graceful wait has had its budget, and
then logs Shutdown(force) succeeded.
Today that escalation has nowhere to land here. StopReplicaVMI and
StopReplicaPodContainer both delete with a bare metav1.DeleteOptions{}, so
the API server applies the object's default grace period whether or not force
was asked for, and GracePeriodSeconds appears nowhere under
pkg/pillar/hypervisor/. Making a forced stop mean anything would require
saying so explicitly on those deletes.
Not necessarily asking to fix it in this PR -- but this is the live change to
this function, and the comment being added here is about Stop's contract, so
it seems worth deciding rather than leaving the argument silently unread. If it
is out of scope, a follow-up issue would at least keep the next reader from
assuming it works.
|
@milan-zededa #6257 merged on Aug 14, so this is out of draft. Your four comments that belong to it are moot now — resolving them. |
Description
Fixes to the KubeVirt hypervisor backend, found while investigating why an app
restart on EVE-k behaves differently from the same operation on EVE-kvm.
1.
kubevirt: keep domain bookkeeping until Cleanupdomainmgrasks the hypervisor to shut a domain down and then pollsInfo()until it reports the domain gone, before creating any replacement.
kubevirtContext.Stop()dropped thevmiListentry thatInfo()resolves adomain through, so every poll after
Stopfailed.waitForDomainGonetreats afailed poll as "the domain is gone", so it returned on its first one-second tick
and cleared
DomainId.The effect is that domainmgr requests deletion of a VMIRS and creates the
replacement roughly a second later, while KubeVirt is still shutting the old VMI
down — virt-handler signals a graceful shutdown and only kills the VMI once the
grace period expires (30 s by default). On a lab device two
virt-launcherpodsfor the same app were observed running at once as a result. Clearing
DomainIdalso made the forced-shutdown escalation in
doInactivateunreachable, since itis guarded on
DomainIdbeing set.The entry now stays in place in
Stopand is removed inCleanup, theunconditional tail of
doInactivate.Deletecannot own the removal: it onlyruns while
DomainIdis still set, which is no longer true once the domain goesaway during the graceful wait, and
Cleanup'sIsMetaReplicaVMIpath did notremove it either — so dropping the
Stopremoval on its own would leak an entryon every successful graceful shutdown. The removal is deferred, since
Cleanupcan fail after the domain is already on its way out.
For contrast, the same sequence on EVE-kvm polls real domain state, backs off
1/2/4/8/16/32 s, and escalates before anything replaces the domain, because the
containerd-backed
Stopit inherits keeps no such state.2.
kubevirt: name the replicaset in the delete errorA failed VMIRS delete logged only the error, so an operator could not tell which
app's replicaset failed to go away — and this path fires during every teardown that
races the Kubernetes API. The name is now included, and the trailing newline logrus
adds itself is dropped.
3.
kubevirt: don't ignore the scheduling lookup error on DeleteDeleteaskedscheduledOnMe()which node the domain is placed on and thendiscarded its error. A failed lookup reports
onMe=false, which is indistinguishablefrom the legitimate "scheduled on another node" case tested on the next line, so
Deletereturned nil — reporting a successful teardown while deleting nothing —whenever the Kubernetes API was briefly unavailable.
Stopalready checks the sameerror. (Not every failure path is
(false, false):replicaPodScheduledOnMe's"Unhandled scheduling state" returns
scheduledOnNone=truealongside its error, so thecheck has to key on the error rather than on
scheduledOnNone.)All five
Deletecall sites in domainmgr log the error and continue (three ofthem are behind
!ctx.hvTypeKubeand unreachable on EVE-k), so no caller'scontrol flow changes. Note this also surfaces an already-deleted ReplicaSet as a
Deleteerror rather than a silent success, since the lookup'sGetreportsNotFoundthrough the same path.4.
kubevirt: treat a mid-call NotFound as goneInfoconfirms the replicaset exists and then fetches it again to read the guest'sphase. A workload deleted between those two calls made the second lookup fail with
NotFound, whichInforeported as an error alongside a still-scheduling state —and
waitForDomainGonereturns true on anyInfoerror before it inspects thestate, so the graceful wait ended early. That is the same premature "domain is
gone" commit 1 exists to prevent, reached through a one-poll race rather than on
every shutdown.
NotFoundnow reports absence identically wherever it is observed,which also drops a redundant third
Getof an object already known to be gone.Raised by @naiming-zededa in review: the concern was that keeping the
vmiListentry past
Stopwould let a deleted replicaset reachscheduledOnMeand bereported
BROKEN. TheInforework that landed in master with #6257 removedthat specific outcome, but the error path it named was still wrong for the
reason above.
Known gaps (deliberately not addressed here)
Stop'sforceparameter is still ignored. This matchesKvmContext.Stop,which also discards it (
_ bool); in both backends the actual forcing is doneby the subsequent
Delete. Now that the escalation is reachable, a stuckdomain can spend an extra
maxDelayinforce-truebeforeDeleteruns.The KVM-analogous fix would be to make kubevirt's
Deletethe forcing step(delete with
GracePeriodSeconds: 0), not to act onforceinStop.Stopstill skips the graceful wait entirely, becausedoInactivateonly callswaitForDomainGoneon the success branch.How to test and validate this PR
Automated:
go build -tags k ./hypervisor/,go vet -tags k ./hypervisor/andgo test -tags k ./hypervisor/underpkg/pillar. Note thekbuild tag isrequired —
hypervisor/kubevirt.gois behind//go:build k, so a build withoutit does not compile this file at all.
TestCreateReplicaPodConfigfails in thatbare host run, on
mastertoo — it mocks the kubeconfig at the real/run/.kube/k3s/k3s.yaml, which a non-root user cannot create; CI runs in acontainer as root and is unaffected (#6290).
On an EVE-k device, restart or deactivate an app instance and watch
waitForDomainGonein the device log:waiting for 1sfollowed byerror info domain <name>, thena replacement VMIRS created within about a second.
state still RUNNING waited …with the delay backing off, until theVMI is actually gone (or the budget expires and the forced path runs), and no
replacement until then.
Cross-check that
kubectl get pods -n eve-kube-appnever shows twovirt-launcherpods for the same app during a restart.Result on hardware (amd64 EVE-k)
Run on a Supermicro SYS-E300-8D EVE-k node with the patched image, using the
preceding build without these commits as the control. The exercise is an
integration test that writes ~128 KB inside a VM app's guest and then restarts
the app instance; each test run does one cycle where the restart is requested
90–240 s after the write and one where it is requested in the same millisecond.
The graceful wait now happens. Time from the restart request to the app being
back online:
The ranges do not overlap. That is the intended effect:
waitForDomainGonepollsreal domain state instead of accepting the first failed
Infoas "gone", so thereplacement is no longer created about a second after the delete request.
Data survival is improved but not fixed. Only the same-millisecond cycle ever
loses the guest's write:
Why, from the device log. The wait this change enables cannot currently
succeed, because
Stopdeletes the VMIRS and the wait then polls that sameVMIRS by name:
Every tick returns
NotFound, so the state never resolves, the full 1+2+4+8+16+32= 63 s backoff runs out, and the replacement is created with the old VMI still
present — by the code's own
VMI still availableon the preceding line. Theidentical sequence appears in a cycle that kept its data (
98ea9e82…, VMIRSztest-…-98ea9-1, give-up at 04:38:42.782,doActivate20 ms later), so theoverlap is now the steady state of every EVE-k app restart on this build, and
whether the guest's last write survives is a race inside that window.
So this change converts a 1-second false "domain is gone" into a 63-second wait
that ends in the same conclusion. It removes the misleading bookkeeping and the
misleading log, and it is a prerequisite for a correct wait, but on its own it
does not stop the replacement from overlapping the old VMI. A follow-up should
make the wait poll the VMI object (which outlives its ReplicaSet) rather than the
ReplicaSet that
Stophas just removed.Also visible in both cycles, and probably worth its own fix:
kubeapi.DetachOldWorkload: a node name is required— the old workload's volumedetach does not happen.
Those numbers predate #6257, which has since merged and is part of the base this
branch now sits on. They were measured against an
Infothat returned an error whenevervmiListhad no entry for the domain; master'sInfoinstead resolves existence througha live VMIRS
Getand reportsHALTEDonly when the object is confirmed absent. How thegraceful wait behaves on the current base therefore needs re-deriving, and I have not
re-measured it on hardware since the rebase.
The rest of the suite was unaffected: 46 passes, plus failures this node also
produces without the change (it has no assignable audio/COM hardware).
Result in the kvm→k conversion matrix (with #5971)
Separately from the hardware run above, the two substantive commits were exercised in the
7-leg EVE-kvm→EVE-k boot-disk conversion matrix, on integration image
0.0.0-newgo-allprs2-f40d7876. That build carries #5971 (the Gokube-initdaemon)and rucoder#3 on top of the conversion chain, plus #6257, #6197, #6240, #6259 and
#6190 — so it is the combination this PR will actually ship into, not a standalone build.
7/7. Six legs green in the batch (
ext4-shrink,twodisk-ext4,twodisk-zfs,zfs-grow,ext4-toofull,zfs-notail);ext4-growlost its emulator to a QEMU AHCIabort (
prdt_warnings=4 aborts=1) while another test shared the host, and passed onre-run with
prdt_warnings=0 aborts=0. Every leg came in faster than on the two previous7/7 images of that branch line, including
twodisk-zfs, which is the historicallyfragile leg.
Scope of that evidence, precisely:
keep domain bookkeeping until Cleanupanddon't ignore the scheduling lookup error on Delete— content-identical in that image to the commits here(patch-ids
7d1df4a12b16andc21b35662d3f).name the replicaset in the delete errorortreat a mid-call NotFound as gone, both committed after that image was built.not a targeted test of the graceful-stop behaviour itself; that evidence is the
hardware section above.
Changelog notes
On EVE-k, an app restart or deactivate no longer creates the replacement while
the previous instance is still shutting down.
PR Backports
Checklist
And the last but not least:
check them.
Reasons for the unchecked boxes: no documentation change — this alters
bookkeeping ownership inside one hypervisor backend, with no new knob or
user-visible surface. The patched image has been run on an amd64 EVE-k device
(see the hardware result above); arm64 is untested.