Skip to content

[17.0-stable] kubevirt: keep domain bookkeeping until Cleanup - #6812

Merged
rene merged 4 commits into
lf-edge:17.0-stablefrom
eriknordmark:kubevirt-graceful-stop-17.0-stable
Oct 16, 2026
Merged

rene merged 4 commits into
lf-edge:17.0-stablefrom
eriknordmark:kubevirt-graceful-stop-17.0-stable

Conversation

@eriknordmark

Copy link
Copy Markdown
Contributor

Description

Backport of #6271 to 17.0-stable, needed as a dependency for the
17.0-stable backport of #6505.

On EVE-k, kubevirtContext.Stop() dropped the domain's bookkeeping entry, so
domainmgr's graceful-shutdown poll saw the domain as gone on its first tick
and created the replacement VMIRS while KubeVirt was still shutting the old
VMI down. The entry now lives until Cleanup. The set also stops Delete
from ignoring a failed scheduling lookup, names the replicaset in the delete
error, and treats a NotFound between Info's two lookups as gone.

All four commits cherry-picked with -x, no adaptations: the picks applied
clean and the diff is identical to master's apart from hunk-header line
numbers.

PR dependencies

None.

How to test and validate this PR

Under pkg/pillar: go build -tags k ./hypervisor/, go vet -tags k ./hypervisor/ and go test -tags k ./hypervisor/ (the k tag is required;
hypervisor/kubevirt.go is behind //go:build k). As on master,
TestCreateReplicaPodConfig fails in a non-root host run because it writes
/run/.kube/k3s/k3s.yaml; it fails the same way on the unpatched branch, and
CI runs as root.

On an EVE-k device, restart an app instance and watch waitForDomainGone: it
should back off on state still RUNNING rather than ending after one
waiting for 1s, and kubectl get pods -n eve-kube-app should not show two
virt-launcher pods for the same app.

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

  • 17.0-stable: this PR.
  • 16.0-stable: Not requested.
  • 14.5-stable: Not requested.
  • 13.4-stable: Not requested.

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
  • I've checked the boxes above, or I've provided a good reason why I didn't
    check them.

No documentation change. The source PR was run on an amd64 EVE-k device; this
clean pick was build-, vet-, test- and gofmt-checked on the branch, not re-run
on a device.

eriknordmark and others added 4 commits October 15, 2026 23:34
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>
(cherry picked from commit 6b6adca)
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>
(cherry picked from commit e320223)
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>
(cherry picked from commit 512a8a8)
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>
(cherry picked from commit 551d449)
@eriknordmark

Copy link
Copy Markdown
Contributor Author

@rene @andrewd-zededa please review: this is a dependency for the 17.0-stable backport of #6505.

@codecov

codecov Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 29.41176% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 23.04%. Comparing base (4749201) to head (02d2b1b).
⚠️ Report is 10 commits behind head on 17.0-stable.

Files with missing lines Patch % Lines
pkg/pillar/hypervisor/kubevirt.go 29.41% 12 Missing ⚠️
Additional details and impacted files
@@               Coverage Diff               @@
##           17.0-stable    #6812      +/-   ##
===============================================
+ Coverage        22.66%   23.04%   +0.38%     
===============================================
  Files              512      522      +10     
  Lines            94634    96423    +1789     
===============================================
+ Hits             21449    22224     +775     
- Misses           71358    72186     +828     
- Partials          1827     2013     +186     

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

@rene
rene merged commit 85e787c into lf-edge:17.0-stable Oct 16, 2026
47 of 49 checks passed
@eriknordmark
eriknordmark deleted the kubevirt-graceful-stop-17.0-stable branch October 16, 2026 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants