Repository navigation
eve-k: fix purge leaving stale VMIRS generations and volume refs - #6257
Conversation
|
I need to take another pass on this and get the verbosity on some the comments down and some verification on the new evetest tests. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #6257 +/- ##
==========================================
+ Coverage 24.28% 24.96% +0.68%
==========================================
Files 512 524 +12
Lines 93831 95833 +2002
==========================================
+ Hits 22786 23927 +1141
- Misses 69244 69862 +618
- Partials 1801 2044 +243 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| // is now scheduled on a node other than excludeDevName, and returns the | ||
| // EdgeDevice matching that node name. | ||
| // | ||
| // This deliberately does NOT use EdgeCluster.FindDeviceHostingApp: that |
There was a problem hiding this comment.
If this can be useful for other (e.g. cluster/failover) tests, maybe we should make this a method of EdgeCluster
There was a problem hiding this comment.
Done. FindDeviceHostingApp could return a device that no longer runs the app. It reads the cluster info that each device published last, and that data can be older than the event the caller waits for. When the device is off, its own old data still names it as the host and it sends nothing more. The method now accepts excludeDevNames. It ignores an excluded device as a source of cluster info, and it never returns one. The parameter is variadic, so the six existing calls do not change. It also subscribes before it reads the cached data, because the old order could lose an update that arrived between the two steps. waitForAppOffDevice is deleted and findAppNodeName stays private, so this PR adds no new public API, just a small signature modification.
4312474 to
6903be4
Compare
|
Rebased on latest master |
6903be4 to
73111d4
Compare
73111d4 to
df8ae7c
Compare
|
FWIW I tried a test on EVE-kvm (reboot from controller + purge) and it shows a subset of the EVE-k symptoms across two EVE-kvm runs:
|
My evetest runs just completed on kvm:
|
eb094a6 to
825635f
Compare
825635f to
1aa70b6
Compare
|
Independent reproduction and validation of the volume-ref half of this change Defect 3 reproduces on EVE-kvm as readily as on EVE-k.
The signature is identical in all six failures, on both hypervisors: No error is recorded anywhere — the app waits on an event no agent will send. A All four passing runs log the new branch exactly once, on the key the failures The control's device log contains that line zero times. It shares the base Worth a look: the results table lists Scope of what I ran: defects 1 and 2 are untested here — my test inspects One practical note: my branch also adds |
|
@eriknordmark I have another evetest fix coming to make the tests in this more reliable. Thanks for the independent repros. |
1aa70b6 to
74a5b1b
Compare
|
Claude finished @eriknordmark's task in 5m 18s —— View job Code review
I reviewed the three-defect fix (Info existence check, Two non-blocking items posted inline:
Neither blocks merge. The core logic looks correct and is backed by the on-device kvm/kube runs and the independent volume-ref reproduction in the thread. |
| if !ok { | ||
| return logError("Start domain %s: could not parse purge counter from %s", domainName, vmis.name) | ||
| } | ||
| if err := ctx.sweepStaleGenerations(appUUID, vmis.name, desiredCounter, vmis.mtype); err != nil { |
There was a problem hiding this comment.
sweepStaleGenerations now runs synchronously inside Start, which domainmgr calls from its handler/timer goroutine (doActivate → doActivateTail → Start) with no ps.StillRunning() kick during the call. For each stale generation, confirmVMIRSGone/confirmPodReplicaSetGone can block up to sweepConfirmRetries * sweepConfirmInterval = 5×10s = 50s, and this is before Start's own existing 5×10s Create-retry loop. domainmgr's errorTime is 3 min (domainmgr.go:86). One stale generation (the normal reboot-after-purge case) is ~100s worst case and safe, but if more than one stale generation is present the cumulative blocking can approach/exceed the watchdog window and reboot the whole device.
Each individual API call is bounded by apiCtx(), so this is a slow-path/accumulation concern rather than an infinite hang. Worth confirming the bound is acceptable, or kicking ps.StillRunning() between sweep iterations. Since generations are swept sequentially with a confirm-wait each, consider capping total sweep time or draining all deletes first and confirming once.
| return fmt.Errorf("confirmVMIRSGone(%s): %w", name, listErr) | ||
| } | ||
| podsGone = len(pods.Items) == 0 |
There was a problem hiding this comment.
Minor: when domainNameLabel == "" this skips the pod check entirely (podsGone stays true), so the confirm passes as soon as the VMIRS object is gone — reintroducing the very virt-launcher-pod teardown race the function guards against. It's only reachable if a VMIRS has a nil Spec.Selector (i.e. domainNameByName[name] was never populated), which CreateReplicaVMIConfig never produces, so this is a latent edge rather than a live bug. Consider logging when the label is empty so a future selector-less object doesn't silently short-circuit the pod wait.
A purge must delete the previous generation of an app. In the kube path it can leave that generation in the cluster. No test found this, because no test looked at the cluster after a purge. These tests purge a container app. eve-k runs a container app in a shim VM, so the app has a VMIRS. - purge_replaces_vmirs_test: purge a running app. Make sure that only the new VMIRS and one PVC stay. - purge_after_power_cycle_test: purge the app while the device is off, then power the device on. Both tests go at the end of TestAppsSuite, after the cheaper subtests. Each one needs a device built from scratch, because the assertions are about which generation of a workload exists and a reused device could leak one in. Neither declares a hypervisor variant. HYPERVISOR is a parameter of the suite, and the suite is run once for each hypervisor, so a variant would run the same combination one more time. TestVMAppPurgeReplacesVMIRS reads the parameter and skips when it is not kubevirt, because a VMIRS and a PVC exist nowhere else. TestVMAppPurgeAfterPowerCycle runs on each of them. The kvm run of the power-cycle test is the control. A kvm domain is a local qemu process, and no cluster object stays alive after the node stops, so a second generation cannot occur there. The kvm run must therefore pass, and a pass keeps a surviving generation on the kube path. The kvm run still tests the parts of a purge that are the same for each hypervisor: the purge must complete and must not stop for ever in zedmanager, and the old generation's disk must go away. It also shows that the kube fixes do not make kvm worse. The two runs use one test body, because only the last assertions are different: VMIRS and PVC objects for kubevirt, files on disk and the qemu domain state directory for kvm. The name of each helper file ends in _helpers_test, so a file named for a test holds only that test and the tests stay easy to read. The existing helpers_test keeps the helpers that any app test uses. The rest go in files named for the state that they observe, and not for the test that needed them first, because one catch-all file gives a contributor no clue where to put the next helper, and it becomes large: - appstate_helpers_test: pillar's own view of the app, from pubsub and from persisted state, by app UUID. - appworkload_helpers_test: where the app runs, as the hypervisor sees it. VMIRS objects for kubevirt, qemu domain state directories for kvm, and the kubectl call that lists them. - appvolumes_helpers_test: the app's disk in each of its three forms, and the storage rules. These rules stay true after a delete or a restart, so they must not go in a purge file. - purge_helpers_test: what the purge tests build before they run, and the assertions that have no meaning if there is no purge. testsuite_test holds the file map and the three questions that tell you where a new helper goes. README.md points to this suite as the example. The disk assertions depend on a property of the framework, so a note in appvolumes_helpers_test records it. PurgeApplication increases the generationCount of each volume that the app uses, together with the app purge counter, the same as a controller does. Only that increase makes zedmanager replace the volume: it finds the volumes to replace with the key of the volume reference, which holds the volume UUID, the generation counters and the app UUID. An app purge counter alone changes none of them, so the reference still matches and nothing is removed or added. If the framework loses that increase, the assertions on the volume generation key and on the old artifact stop being possible to satisfy, not merely weaker. EdgeCluster.FindDeviceHostingApp could return a device that no longer runs the app. It reads the cluster info that each device published last, and that data can be older than the event that the caller waits for. The fault is clearest when a device is off: its own old data still names it as the host, and the device sends nothing more. The method now accepts excludeDevNames. It does not read cluster info from an excluded device, and it never returns one. The parameter is variadic, so the calls that exist do not change. The method also subscribes before it reads the cached data, because the old order could lose an update that arrived between the two steps. WaitUntilNodesAreReady already used the correct order. The power-cycle test calls EdgeDevice.SyncDisks before it removes the power. EVE unpacks the container image layers without an fsync, and a test device mounts /persist without dirsync, because Setup passes set_no_dirsync unless a test asks for WithDirSync. If the power stops in the writeback window, the layers keep the directory tree but each file becomes empty: approximately 150 MB of layers became 3 MB in one run. Nothing extracts them again, each later volume from that image is empty, and the app then starts and stops in a loop while EVE reports it as RUNNING. The sync keeps that out of a test whose subject is the purge. Each purge test has two phases, because the purge and the reclamation of the old disk use different clocks: - The purge end state: the counter increased by one, the purge phase is NotInprogress, the app is RUNNING, there is one volume with a new generation, and there is one VMIRS or one qemu domain. This settles in approximately one minute. - The removal of the old generation's storage: the old artifact is gone and no artifact stays that no VolumeStatus names, or, for kubevirt, no PVC stays that no VolumeStatus names. volumemgr does this on its own schedule, approximately five minutes after the purge in a test. This is much sooner than the one hour VdiskGCTime, but much later than the purge. A check for the second in the window of the first fails on time and not on substance. This was true for the PVC check also. On kubevirt each test waits for the node to become Ready before it waits for the app, and again after the power cycle, because the reboot stops k3s. Each other app test in this package does the first of these. Without the wait, the app stays in INITIAL while k3s and Longhorn start, which used six of the ten minutes of the app limit in a test, and the test then failed on time and not on substance. purge_helpers_test holds each timeout in one block with the reason for its value. Eventually stops as soon as the condition is true, so a large limit costs nothing when the system operates correctly, and it only delays a true failure. Each limit comes from a measured time with headroom. If a limit starts to expire, find what changed. Do not increase the number. If the app is not RUNNING, the failure message now includes BootFailed, TriedCount and the error from DomainStatus. The state alone cannot tell you that a guest started and then stopped itself. A helper that says nothing about apps goes on EdgeDevice, so that each test package can use it, and not in a helper file of this package. This commit adds three. PathExists takes any kind of node, and not only a regular file as FileExists does, and it returns the error instead of ending the test, so a caller can retry it inside Eventually. ListDirEntries returns the sorted entries of a directory, and a directory that EVE has not created yet gives an empty list and no error. SyncDisks flushes the caches, and it carries the reason above. The tests read a file with EdgeDevice.ReadFile, which the framework already had. README.md lists each of these. VERSION goes to 1.3, because these methods and the EdgeCluster change are part of the framework. The tests under tests/ are bind-mounted into the evetest container, but the framework that they link against is compiled into the image, and the image tag follows VERSION. README.md asks for the bump after each change outside tests/ and sdn/vm/. The device requirements ask for no grub CPU options. kube-init widens the EVE cpuset for the length of the deploy and restores it on RUNNING (prereqs.WidenEVECPUs), so cluster formation no longer needs the test to raise eve_max_vcpus itself. findAppNodeName stays private. The rest of the new public API is EdgeDevice.Name and FindDeviceHostingApp's excludeDevNames. Neither is exercised by a test in this commit; both are ready for the cluster test that follows. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Andrew Durbin <andrewd@zededa.com>
Each cluster test asked for dom0_max_vcpus=4, eve_max_vcpus=3 and ctrd_max_vcpus=3, so that cluster formation did not run on the single core that eve_max_vcpus gives EVE by default. kube-init now does this itself: prereqs.WidenEVECPUs gives the EVE services the host's full CPU mask for the length of the deploy and restores it on RUNNING. That covers the same first boot on every device, and not only on a device that a test configured. The grub options therefore add nothing, and each one is a way for a test to differ from a real deployment. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Andrew Durbin <andrewd@zededa.com>
A purge must delete the previous generation of an app before it creates
the next one. In the kube path three defects stop this. The old VMIRS
then keeps running, and EVE reports the purge as complete.
1. Info() says a domain is gone when it only cannot see it.
Info() returns domainID 0 if it finds no replica on this node.
domainmgr copies that 0 into DomainStatus. zedmanager reads 0 as
"there is no domain", so it skips the teardown and releases the
purge. Info() now gets identity and existence from the cluster:
- domainID is workloadID(), a hash of the VMIRS metadata.uid. It was
rand.Uint32(), which has no relation to the cluster.
- Task() keeps the DomainStatus. The kube name now comes from the
status and not from the vmiList cache, which goes stale.
- Info() returns 0 only when the VMIRS is absent. If it cannot
confirm absence, it returns the last known id.
2. Nothing deletes an old generation after a reboot.
/run is tmpfs, so a reboot deletes the purge state. The VMIRS stays
in etcd. zedmanager finds no domain to halt and advances the counter,
so the new generation starts beside the old one. Start() now sweeps
first: it finds each older generation of the app in the cluster,
deletes it, and waits until the object and its pods are gone. The
sweep reads the cluster and does not need the old counter, so it
survives the reboot. If it cannot confirm that a generation is gone,
Start() fails. A failed start is safer than two generations that
share MACs, veth names and one RWO disk.
3. zedmanager waits for ever for a volume-ref removal.
On a purge, doInstall parks the old VolumeRefStatus and waits for
volumemgr to confirm the delete. If volumemgr has no live status for
that reference in this boot, the confirmation never comes. The app
stays in DownloadAndVerify and never asks for the new volume.
zedmanager now looks at volumemgr's live status first, and drops the
reference if it is already absent.
Each Kubernetes request that this change adds now has a deadline of
kubeapi.KubeAPITimeout, with the apiCtx helper. domainmgr calls Info on a
timer of 9 to 30 seconds and calls Start directly, and the watchdog of
zedbox restarts the device if that handler stops to report. A request
without a deadline on those paths can therefore stop the node. With a
deadline it fails, and Info reports UNKNOWN and keeps the id of the caller,
which is the contract on types.DomainStatus.DomainId. getVmirs already used
this same limit, so the new calls now match it.
Also in this change:
- StopReplicaVMI had an inverted IsNotFound test, so each successful
delete logged "Stop VMI Replicaset error <nil>" at error level. This
made a good teardown look like a bad one in the field. The return
values do not change.
- The kubevirt and k8s client constructors are now package-level vars.
The tests can then inject a fake client.
- Info() and sweepStaleGenerations() now call getConfig() themselves.
The receiver is a value, so a getConfig() call in a method they call
fills in a copy and leaves kubeConfig nil. A nil kubeConfig made
newKubevirtClient panic, which stopped zedbox and rebooted the node.
The client stubs in the tests now reject a nil config.
- docs/zedkube.md records what domainID means, what the sweep does, and
two gaps that stay open: the sweep does not delete the stale
generation's PVC, and it cannot run if a purge stops before Start().
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Andrew Durbin <andrewd@zededa.com>
07d6926 to
b594693
Compare
On EVE-k a purge deletes the stale generation's VMIRS and pod but leaves its PVC behind, so the Longhorn volume underneath is never reclaimed and the space stays consumed for the life of the device. Extend volumemgr's periodic garbage-collection pass to cover PVC-backed volumes: a PVC with no currently-published VolumeStatus is collected, mirroring what the pass already does for file-backed volumes. Runs only on EVE-k. Originally from lf-edge#6257; the test is written against this branch's initStatusCtx, which returns a pointer. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
On EVE-k a purge deletes the stale generation's VMIRS and pod but leaves its PVC behind, so the Longhorn volume underneath is never reclaimed and the space stays consumed for the life of the device. Extend volumemgr's periodic garbage-collection pass to cover PVC-backed volumes: a PVC with no currently-published VolumeStatus is collected, mirroring what the pass already does for file-backed volumes. Runs only on EVE-k. Originally from lf-edge#6257; the test is written against this branch's initStatusCtx, which returns a pointer. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
lf-edge#6240 changed initStatusCtx to return *volumemgrContext so the subscriptions it registers and the caller share one context; lf-edge#6257's new test was written against master, where the helper still returns a value, so it takes the address at every call site and no longer compiles here. Drop the & at those call sites. Integration-branch only: the fix belongs in lf-edge#6257 once it rebases onto lf-edge#6240. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Signed-off-by: eriknordmark <erik@zededa.com>
lf-edge#6240 changed initStatusCtx to return *volumemgrContext so the subscriptions it registers and the caller share one context; lf-edge#6257's new test was written against master, where the helper still returns a value, so it takes the address at every call site and no longer compiles here. Drop the & at those call sites. Integration-branch only: the fix belongs in lf-edge#6257 once it rebases onto lf-edge#6240. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Signed-off-by: eriknordmark <erik@zededa.com>
lf-edge#6240 changed initStatusCtx to return *volumemgrContext so the subscriptions it registers and the caller share one context; lf-edge#6257's new test was written against master, where the helper still returns a value, so it takes the address at every call site and no longer compiles here. Drop the & at those call sites. Integration-branch only: the fix belongs in lf-edge#6257 once it rebases onto lf-edge#6240. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Signed-off-by: eriknordmark <erik@zededa.com>
lf-edge#6240 changed initStatusCtx to return *volumemgrContext so the subscriptions it registers and the caller share one context; lf-edge#6257's new test was written against master, where the helper still returns a value, so it takes the address at every call site and no longer compiles here. Drop the & at those call sites. Integration-branch only: the fix belongs in lf-edge#6257 once it rebases onto lf-edge#6240. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Signed-off-by: eriknordmark <erik@zededa.com>
lf-edge#6240 changed initStatusCtx to return *volumemgrContext so the subscriptions it registers and the caller share one context; lf-edge#6257's new test was written against master, where the helper still returns a value, so it takes the address at every call site and no longer compiles here. Drop the & at those call sites. Integration-branch only: the fix belongs in lf-edge#6257 once it rebases onto lf-edge#6240. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Signed-off-by: eriknordmark <erik@zededa.com>
lf-edge#6240 changed initStatusCtx to return *volumemgrContext so the subscriptions it registers and the caller share one context; lf-edge#6257's new test was written against master, where the helper still returns a value, so it takes the address at every call site and no longer compiles here. Drop the & at those call sites. Integration-branch only: the fix belongs in lf-edge#6257 once it rebases onto lf-edge#6240. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Signed-off-by: eriknordmark <erik@zededa.com>
A purge must not gate its teardown on the app's designated node, nor on wherever a replica happens to be scheduled: neither signal is both durable and liveness-aware, so either one deadlocks a purge issued while the designated node is down. Add a three-node cluster test for that case. The app is deployed with a preferred designated node, that node is powered off so KubeVirt reschedules the replica elsewhere, and the purge is issued while it is still down; the surviving workload must be exactly one VMIRS, named for the new generation. Originally part of lf-edge#6257, which merged without it. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
A purge must not gate its teardown on the app's designated node, nor on wherever a replica happens to be scheduled: neither signal is both durable and liveness-aware, so either one deadlocks a purge issued while the designated node is down. Add a three-node cluster test for that case. The app is deployed with a preferred designated node, that node is powered off so KubeVirt reschedules the replica elsewhere, and the purge is issued while it is still down; the surviving workload must be exactly one VMIRS, named for the new generation. Originally part of lf-edge#6257, which merged without it. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Description
Purge leaves the old app generation running on the kube path
A purge must delete the app's previous generation before it creates the
new one. On the kube path it does not: the old VMIRS keeps running, and
EVE reports the purge complete anyway.
Root cause (three defects, all in
pkg/pillar)Info()reports "gone" when it only can't see the domain. Itreturned domain ID 0 whenever it found no replica on this node.
domainmgrcopies that 0 intoDomainStatus;zedmanagerreads 0 as"no domain," skips the teardown, and releases the purge anyway.
Info()now gets identity and existence from the cluster instead ofa random ID, and returns 0 only when the VMIRS is confirmed absent —
never when it merely can't confirm one way or the other.
Nothing deletes the old generation after a reboot.
/runistmpfs, so a reboot drops the purge state pillar was tracking, but the
VMIRS survives in etcd.
zedmanagerfinds no local domain to halt,advances the counter anyway, and a new generation starts beside the
old one.
Start()now sweeps the cluster first: it finds every oldergeneration, deletes it, and confirms the object and its pods are
gone before proceeding. A failed sweep fails the start — safer than
two generations sharing MACs, veth names, and one RWO disk.
zedmanagercan wait forever for a volume-ref removal. A purgeparks the old
VolumeRefStatusand waits forvolumemgrto confirmthe delete. If
volumemgrhas no live status for that reference inthe current boot, the confirmation never arrives, and the app is
stuck in
DownloadAndVerifyforever.zedmanagernow checksvolumemgr's live status first and drops the reference if it'salready gone.
Info()'s new cluster-based existence check andsweepStaleGenerations()are both value-receiver methods, so each populates its own copy of the
KubeVirt config directly via
getConfig()rather than relying on acaller's copy.
Every new Kubernetes call this change adds carries an explicit deadline
(
kubeapi.KubeAPITimeout).domainmgrcallsInfo()on a 9–30s timerand calls
Start()directly; a call with no deadline on either pathcan stall the node until the watchdog reboots it.
✅ pass · ❌ fail · ⬜ not run
TestVMAppPurgeBaselineTestVMAppPurgeAfterPowerCycleTestVMAppPurgeAfterPowerCyclePR dependencies
None.
How to test and validate this PR
Two evetest scenarios, purging a container app (which runs in a VMIRS
via a shim VM on eve-k):
TestVMAppPurgeBaseline— purge a healthy, undisturbed app.Exactly one VMIRS and one volume must exist before and after, and the
survivor must be named for the new generation.
TestVMAppPurgeAfterPowerCycle— purge while the device ispowered off, then power it back on. This reproduces the failure
customers saw. Runs twice, once per hypervisor:
cluster-side object to lose track of, so the duplicate-generation
defect is structurally impossible there. This run must pass on its
own, and a pass keeps the defect isolated to the kube path.
Both variants share one test body; only the end-state assertions differ
(VMIRS/PVC on kubevirt, qemu domain state + disk file on kvm).
Changelog notes
Fixes a bug on eve-k (kubevirt hypervisor) where purging an application around a
device reboot could leave a duplicate/stale VM instance running alongside the new
one, or leave the purge stuck indefinitely instead of completing. Also adds
automated purge tests to evetest and fixes
EdgeCluster.FindDeviceHostingApp, which could return a device that no longerhosts the app. No other user-facing changes.
PR Backports
Checklist
And the last but not least:
check them.
Please, check the boxes above after submitting the PR in interactive mode.