Skip to content

[17.0-stable] eve-k: fix purge leaving stale VMIRS generations and volume refs - #6357

Merged
rene merged 1 commit into
lf-edge:17.0-stablefrom
andrewd-zededa:pr6257-17.0-stable
Aug 20, 2026
Merged

rene merged 1 commit into
lf-edge:17.0-stablefrom
andrewd-zededa:pr6257-17.0-stable

Conversation

@andrewd-zededa

Copy link
Copy Markdown
Contributor

Description

Backport of #6257

Partial backport: the pillar fix only. The two evetest commits from the
original PR are not included — see "Scope" below.

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.

Scope of this backport

Only pillar: keep purges from leaving the old app generation behind
(9c2eecf) is backported. It cherry-picks
cleanly onto 17.0-stable with no adaptation.

The original PR's two evetest commits are omitted because they cannot be
cherry-picked to this branch: the evetest framework here is a different
generation (evetest/VERSION v0.0.1 vs 1.4 on master, with 79 evetest
commits on master not present on 17.0-stable). Both commits modify files
that do not exist on this branch — evetest/tests/apps/testsuite_test.go
(the whole tests/apps/ suite is absent) and three
evetest/tests/cluster/ files — and the new tests call harness helpers
this branch's edgedevice.go/harness.go do not have. Porting that
purge coverage to the v0.0.1 harness would be a hand-written change, not
a backport, so it is deliberately left out of this PR.

PR dependencies

None. This does not conflict with #6353 (the #6100 backport); the two
were verified to apply cleanly in either order.

How to test and validate this PR

The automated purge tests are not available on this branch (see Scope),
so validate manually on an eve-k device — purging a container app, which
runs in a VMIRS via a shim VM:

  • Baseline — 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.
  • Purge across a power cycle — purge while the device is powered off,
    then power it back on. This reproduces the failure customers saw. On
    coming back up there must be exactly one VMIRS (the new generation),
    no leftover PVC from the old one, and the app must reach running
    rather than sticking in DownloadAndVerify.

Useful checks on the device:

kubectl -n eve-kube-app get vmirs
kubectl -n eve-kube-app get pvc

A kvm-hypervisor purge across a power cycle is a useful 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.

Unit coverage picked up with the fix: go test -tags k ./cmd/zedmanager/... ./hypervisor/... (includes the new
updatestatus_test.go, kubevirt_staleness_test.go,
kubevirt_identity_test.go, kubevirt_info_test.go and others).

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. No other
user-facing changes.

PR Backports

This is the backport

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

For backport PRs (remove it if it's not a backport):

  • I've added a reference link to the original PR
  • PR's title follows the template

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.

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>
(cherry picked from commit 9c2eecf)
@andrewd-zededa andrewd-zededa added the next-17.0.x-rc PR must be present in the next 17.0.x-lts release label Aug 19, 2026
@github-actions
github-actions Bot requested a review from OhmSpectator August 19, 2026 21:24
@codecov

codecov Bot commented Aug 19, 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 21.37%. Comparing base (4e450bb) to head (29ded98).
⚠️ Report is 6 commits behind head on 17.0-stable.

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               @@
##           17.0-stable    #6357      +/-   ##
===============================================
+ Coverage        20.65%   21.37%   +0.72%     
===============================================
  Files              506      518      +12     
  Lines            93032    94994    +1962     
===============================================
+ Hits             19214    20306    +1092     
- Misses           72219    72862     +643     
- Partials          1599     1826     +227     

☔ 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.

@eriknordmark eriknordmark left a comment

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.

LGTM

@rene
rene merged commit 4cdaf63 into lf-edge:17.0-stable Aug 20, 2026
50 of 51 checks passed
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants