Skip to content

eve-k: fix purge leaving stale VMIRS generations and volume refs - #6257

Merged
eriknordmark merged 3 commits into
lf-edge:masterfrom
andrewd-zededa:eve-k-purge-lost-delete
Aug 14, 2026
Merged

eriknordmark merged 3 commits into
lf-edge:masterfrom
andrewd-zededa:eve-k-purge-lost-delete

Conversation

@andrewd-zededa

@andrewd-zededa andrewd-zededa commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

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)

  1. Info() reports "gone" when it only can't see the domain. It
    returned domain ID 0 whenever it found no replica on this node.
    domainmgr copies that 0 into DomainStatus; zedmanager reads 0 as
    "no domain," skips the teardown, and releases the purge anyway.
    Info() now gets identity and existence from the cluster instead of
    a random ID, and returns 0 only when the VMIRS is confirmed absent —
    never when it merely can't confirm one way or the other.

  2. Nothing deletes the old generation after a reboot. /run is
    tmpfs, so a reboot drops the purge state pillar was tracking, but the
    VMIRS survives in etcd. zedmanager finds 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 older
    generation, 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.

  3. zedmanager can wait forever for a volume-ref removal. A purge
    parks the old VolumeRefStatus and waits for volumemgr to confirm
    the delete. If volumemgr has no live status for that reference in
    the current boot, the confirmation never arrives, and the app is
    stuck in DownloadAndVerify forever. zedmanager now checks
    volumemgr's live status first and drops the reference if it's
    already gone.

Info()'s new cluster-based existence check and sweepStaleGenerations()
are both value-receiver methods, so each populates its own copy of the
KubeVirt config directly via getConfig() rather than relying on a
caller's copy.

Every new Kubernetes call this change adds carries an explicit deadline
(kubeapi.KubeAPITimeout). domainmgr calls Info() on a 9–30s timer
and calls Start() directly; a call with no deadline on either path
can stall the node until the watchdog reboots it.

✅ pass · ❌ fail · ⬜ not run

Test HV master this PR Notes
TestVMAppPurgeBaseline kubevirt ✅ ⬜
TestVMAppPurgeAfterPowerCycle kubevirt ❌ ⬜
TestVMAppPurgeAfterPowerCycle kvm ❌ ⬜ control; see below

PR 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 is
    powered off, then power it back on. This reproduces the failure
    customers saw. Runs twice, once per hypervisor:
    • Kubevirt is where the defect lives.
    • kvm is the control: a kvm domain is a local qemu process with no
      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 longer
hosts the app. No other user-facing changes.

PR Backports

  • 17.0-stable: To be backported.
  • 16.0-stable: No, as the feature is not available there.
  • 14.5-stable: No, as the feature is not available there.
  • 13.4-stable: No, as the feature is not available there.

Checklist

  • I've provided a proper description
  • I've added the proper documentation
  • I've tested my PR on amd64 device
  • I've tested my PR on arm64 device
  • I've written the test verification instructions
  • I've set the proper labels to this PR

And the last but not least:

  • I've checked the boxes above, or I've provided a good reason why I didn't
    check them.

Please, check the boxes above after submitting the PR in interactive mode.

@andrewd-zededa

Copy link
Copy Markdown
Contributor Author

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.

@andrewd-zededa andrewd-zededa added stable Should be backported to stable release(s) next-17.0.x-rc PR must be present in the next 17.0.x-lts release labels Jul 31, 2026
@codecov

codecov Bot commented Aug 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 47.28916% with 175 lines in your changes missing coverage. Please review.
✅ Project coverage is 24.96%. Comparing base (0a4bdce) to head (b594693).
⚠️ Report is 14 commits behind head on master.

Files with missing lines Patch % Lines
pkg/pillar/hypervisor/kubevirt.go 36.90% 157 Missing and 14 partials ⚠️
pkg/pillar/hypervisor/kubevirt_identity.go 80.00% 1 Missing and 1 partial ⚠️
pkg/pillar/hypervisor/kubevirt_staleness.go 95.45% 1 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread evetest/tests/apps/helpers_test.go Resolved
Comment thread evetest/tests/apps/helpers_test.go Outdated
// 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this can be useful for other (e.g. cluster/failover) tests, maybe we should make this a method of EdgeCluster

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread evetest/edgedevice.go Resolved
@milan-zededa milan-zededa mentioned this pull request Aug 3, 2026
4 of 7 tasks
@andrewd-zededa
andrewd-zededa force-pushed the eve-k-purge-lost-delete branch from 4312474 to 6903be4 Compare August 4, 2026 21:35
@andrewd-zededa

Copy link
Copy Markdown
Contributor Author

Rebased on latest master

@andrewd-zededa
andrewd-zededa force-pushed the eve-k-purge-lost-delete branch from 6903be4 to 73111d4 Compare August 5, 2026 21:27
@github-actions
github-actions Bot requested a review from eriknordmark August 5, 2026 21:28
@andrewd-zededa
andrewd-zededa force-pushed the eve-k-purge-lost-delete branch from 73111d4 to df8ae7c Compare August 5, 2026 23:27
@eriknordmark

Copy link
Copy Markdown
Contributor

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:
Two findings, one of each sign:

  • Symptom 1 (app never recovers after a purge submitted during an outage) —
    confirmed, 2/2.
  • Symptom 2 (a reboot adds a second purge copy) — did not occur. Both runs
    converged to exactly one generation-1 copy, and the reboot recovered the app
    in 14 s.

@andrewd-zededa

Copy link
Copy Markdown
Contributor Author

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: Two findings, one of each sign:

  • Symptom 1 (app never recovers after a purge submitted during an outage) —
    confirmed, 2/2.
  • Symptom 2 (a reboot adds a second purge copy) — did not occur. Both runs
    converged to exactly one generation-1 copy, and the reboot recovered the app
    in 14 s.

My evetest runs just completed on kvm:

  • I agree on the "app never recovers after a purge submitted during an outage". Reproduces on HV=kvm or HV=k
  • "a reboot adds a second purge copy": this is an HV=k specific behavior I can reproduce

@andrewd-zededa
andrewd-zededa force-pushed the eve-k-purge-lost-delete branch 3 times, most recently from eb094a6 to 825635f Compare August 7, 2026 01:37
@andrewd-zededa
andrewd-zededa force-pushed the eve-k-purge-lost-delete branch from 825635f to 1aa70b6 Compare August 7, 2026 15:56
@eriknordmark

Copy link
Copy Markdown
Contributor

Independent reproduction and validation of the volume-ref half of this change
(defect 3), on both hypervisors. I hit this failure in the field report — VM app
running, power cut to the node, purge submitted while it is down, power restored
— and wrote an evetest for it before I found this PR:
evetest/tests/storage/purge_across_power_loss_test.go.

Defect 3 reproduces on EVE-kvm as readily as on EVE-k.

image base carries defect-3 hunk runs result
17.0.0-lts kvm 17.0 line no 3 FAIL
master ca1b11f73 kvm (control) master no 1 FAIL
master + 73111d49f kvm master yes 2 PASS
17.0.0-lts EVE-k 17.0 line no 2 FAIL
master + 73111d49f EVE-k master yes 2 PASS

The signature is identical in all six failures, on both hypervisors:

zedmanager AppInstanceStatus: state=INITIAL purgeInprogress=1 activated=false error=
zedmanager VolumeRefStatus:   key=<vol>#0#<app> state=INITIAL pendingAdd=true verifyOnly=true error=
volumemgr:                    only <vol>#1 (LOADED)

No error is recorded anywhere — the app waits on an event no agent will send. A
single extra reboot always clears it, and the volume is never damaged.

All four passing runs log the new branch exactly once, on the key the failures
leave parked:

zedmanager doInstall  No volumemgr VolumeRefStatus for <vol>#0#<app>; dropping immediately

The control's device log contains that line zero times. It shares the base
commit and the test source with the passing image and differs only by this
commit, so the recovery is attributable to the change rather than to master
drift.

Worth a look: the results table lists TestVMAppPurgeAfterPowerCycle / kvm
as ❌ on both master and this PR. My kvm runs pass 2/2 with the defect-3 hunk
applied, so if that ❌ is still current, the cause is likely one of the
kvm-specific assertions (files on disk, qemu domain state directory) rather than
the zedmanager hang — which the commit message lists as something the kvm run
covers, and which does now pass. Might be worth separating those two so a kvm
red does not mask the part that is fixed.

Scope of what I ran: defects 1 and 2 are untested here — my test inspects
volumemgr volume status and files on disk, not VMIRS or pods, so it cannot see a
duplicated VM beside a single volume. The "a second purge copy is made on the
next boot" symptom from the field report did not reproduce in any of the 10 runs,
fixed or unfixed. I tested 73111d49f; head is now 825635fe2, whose
cmd/zedmanager/updatestatus.go change is byte-identical, though kubevirt.go
has moved since.

One practical note: my branch also adds EdgeDevice.PowerOff/PowerOn to the
harness, the same addition as in your evetest commit. Only one of them should
land — happy to drop mine and fold the volume-level assertions into your test
instead.

@andrewd-zededa

Copy link
Copy Markdown
Contributor Author

@eriknordmark I have another evetest fix coming to make the tests in this more reliable. Thanks for the independent repros.

@claude

claude Bot commented Aug 13, 2026 •

Copy link
Copy Markdown

Claude finished @eriknordmark's task in 5m 18s —— View job


Code review

  • Gather PR diff & context
  • Review hypervisor/kubevirt.go + new kubevirt files (core fix)
  • Review cmd/zedmanager/updatestatus.go (volume-ref fix)
  • Review evetest changes
  • Post inline findings

I reviewed the three-defect fix (Info existence check, sweepStaleGenerations, and the volume-ref drop) plus the supporting kubevirt/identity/staleness helpers and the evetest additions. The design is sound and well-documented, and the DomainId == 0 ⇔ confirmed-absent invariant is upheld correctly in Info (only errors.IsNotFound yields the zero token; every "unknown" path preserves t.status.DomainId). I verified trailingCounter is unambiguous against the GetAppKubeNameWithPurge name format, that vmiList is a pointer map so the domainID write-back in Start/StartReplicaPodContiner persists, and that the zedmanager lookupVolumeRefStatus drop is correctly gated on PurgeInprogress == DownloadAndVerify.

Two non-blocking items posted inline:

  1. hypervisor/kubevirt.go:1039 — sweepStaleGenerations runs synchronously in Start on the domainmgr handler goroutine with no ps.StillRunning() kick; each stale generation can block ~50s (confirm-gone) before Start's own 50s Create-retry. Safe for one stale generation (the normal case, ~100s < 3-min errorTime), but multiple stale generations could approach the watchdog window. Worth a bound or a StillRunning kick between iterations.
  2. hypervisor/kubevirt.go:875-877 — confirmVMIRSGone short-circuits the pod-teardown wait when the domainName label is empty; latent edge only (current code always sets the selector), but worth logging.

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.
· branch eve-k-purge-lost-delete

Comment thread evetest/tests/apps/testsuite_test.go Resolved
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 {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +875 to +877
return fmt.Errorf("confirmVMIRSGone(%s): %w", name, listErr)
}
podsGone = len(pods.Items) == 0

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

andrewd-zededa and others added 3 commits August 13, 2026 11:18
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>
@andrewd-zededa
andrewd-zededa force-pushed the eve-k-purge-lost-delete branch from 07d6926 to b594693 Compare August 13, 2026 17:20
eriknordmark pushed a commit to eriknordmark/eve that referenced this pull request Aug 13, 2026
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>
eriknordmark pushed a commit to eriknordmark/eve that referenced this pull request Aug 13, 2026
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>
@eriknordmark
eriknordmark merged commit 9c2eecf into lf-edge:master Aug 14, 2026
55 checks passed
eriknordmark added a commit to eriknordmark/eve that referenced this pull request Aug 31, 2026
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>
eriknordmark added a commit to eriknordmark/eve that referenced this pull request Aug 31, 2026
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>
eriknordmark added a commit to eriknordmark/eve that referenced this pull request Aug 31, 2026
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>
eriknordmark added a commit to eriknordmark/eve that referenced this pull request Aug 31, 2026
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>
eriknordmark added a commit to eriknordmark/eve that referenced this pull request Aug 31, 2026
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>
eriknordmark added a commit to eriknordmark/eve that referenced this pull request Aug 31, 2026
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>
eriknordmark pushed a commit to eriknordmark/eve that referenced this pull request Sep 3, 2026
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>
eriknordmark pushed a commit to eriknordmark/eve that referenced this pull request Sep 3, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

next-17.0.x-rc PR must be present in the next 17.0.x-lts release stable Should be backported to stable release(s)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants