Repository navigation
kubeapi: bound zedkube's Kubernetes API calls during failover - #7202
Draft
andrewd-zededa wants to merge 3 commits into
Draft
andrewd-zededa wants to merge 3 commits into
andrewd-zededa wants to merge 3 commits into
Conversation
pillar changed Longhorn volumes, engines and the EVE recurring snapshot job by reading the object, changing a field and writing the whole object back with Update. The object goes through pillar's vendored Longhorn types on the way, so any field those types do not know is sent back as absent and cleared. With the Longhorn EVE ships today the types match and nothing is lost, but newer Longhorn releases add spec fields to these objects. This prepares for upgrading the Longhorn version in use. Send JSON merge patches that name only the fields pillar changes: - volume: spec.nodeID, plus spec.backupTargetName when it is empty, since Longhorn's webhook rejects any update to a volume without one; - engine: spec.nodeID, for each engine of the volume; - recurring job: spec.cron. The volume update also set status.ownerID and status.currentNodeID. The volume CRD has a status subresource, so the API server already ignored those in a plain Update; they are dropped. Status belongs to longhorn-manager. Listing the engines failed silently before; it now returns the error. The Longhorn node and setting writes are left as they are. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Andrew Durbin <andrewd@zededa.com>
Kubernetes API calls on two paths that run on zedkube's main loop used context.Background() or context.TODO(), and GetKubeConfig sets no client timeout, so a stalled API server held the loop until zedkube's watchdog rebooted the node. One path is DetachOldWorkload, which a node runs while it takes over the apps of a node that just failed: the stall it waits out is likely then, and a watchdog reboot there takes down a second node. The other is the Longhorn storage info collectKubeStats gathers. DetachOldWorkload: give each call kubeAPITimeout, as the neighbouring code already does. That covers the volume and engine hand-over and the replica delete in longhorninfo.go, DeleteControlPlanePodsOnNode (node Get and Update, the kubevirt and longhorn-system pod List and Delete) and the VolumeAttachment List and Delete. Bounded calls can still add up, so kick the watchdog after each pod delete, replica delete, VolumeAttachment delete, volume hand-over and attach check. DeleteControlPlanePodsOnNode takes the watchdog function for that. collectKubeStats already bounds its calls with one kubeAPITimeout context. PopulateKSI now takes that context and uses it for every call, the snapshot List included, instead of a timeout per call: one per DaemonSet and PVC could add up past the watchdog. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Andrew Durbin <andrewd@zededa.com>
DetachUtilVmirsReplicaReset retries on zedkube's main loop for up to two minutes while virt-api is unreachable, which is common when the failed node was hosting it. Nothing kicked the watchdog meanwhile, so a failover left zedkube 121s past its last kick: over the warning threshold and about a minute short of the error threshold, on the node that is taking over the workload. Pass the caller's wdFunc in and kick it on each try. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Andrew Durbin <andrewd@zededa.com>
github-actions
Bot
requested review from
eriknordmark,
milan-zededa and
naiming-zededa
November 24, 2026 01:12
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #7202 +/- ##
==========================================
+ Coverage 30.99% 31.46% +0.46%
==========================================
Files 562 573 +11
Lines 101231 102882 +1651
==========================================
+ Hits 31380 32371 +991
- Misses 67412 68115 +703
+ Partials 2439 2396 -43 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
Author
|
Will pull out of draft once #7182 merges |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When a node in an eve-k cluster fails, a surviving node runs
DetachOldWorkloadon zedkube's main loop to take over its apps. SeveralKubernetes API calls on that path used
context.Background()orcontext.TODO(), andGetKubeConfigsets no client timeout, so astalled API server held the loop until zedkube's watchdog rebooted the
node. A stall is likely just then, with one cluster member gone, and a
watchdog reboot at that point takes down a second node.
This PR bounds those calls and keeps the watchdog kicked while they run:
DetachOldWorkloadgetskubeAPITimeout, asthe neighbouring code already does: the Longhorn volume and engine
hand-over and replica delete,
DeleteControlPlanePodsOnNode(node Getand Update, kubevirt and longhorn-system pod List and Delete) and the
VolumeAttachment List and Delete.
pod, replica and VolumeAttachment delete, volume hand-over and attach
check.
DeleteControlPlanePodsOnNodetakes the watchdog function forthat.
DetachUtilVmirsReplicaResetretries for up to two minutes whilevirt-api or the API server is unreachable, with nothing kicking the
watchdog. It now takes the caller's watchdog function and kicks it on
each try.
collectKubeStatsalready bounds its calls with onekubeAPITimeoutcontext.
PopulateKSInow takes that context and uses it for everycall, the Longhorn snapshot List included, instead of a timeout per
call that could add up past the watchdog across DaemonSets and PVCs.
PR dependencies
Depends on #7182, which rewrites the Longhorn writes in
longhorninfo.gothat this PR bounds. Until #7182 merges, its commitalso shows in this PR's diff; review only the last two commits.
How to test and validate this PR
Automated:
make -C pkg/pillar test. No new tests; the existingTestPopulateKVIInnerruns with the context-taking snapshot function.On a 3-node eve-k cluster with a VM app on a 2-replica Longhorn volume,
power off the node running the app. On the node that takes it over:
checkAppsFailover: failover start, thenDetachOldWorkload: set lhVol:<vol> to node:<node> err:<nil>,volumeattachment list empty finally,DetachOldWorkload Completed failover ... duration:andcheckAppsFailover: failover complete.StillRunning(zedkube) took a long timeline appears, even when thevmirs scale reset runs its full two minutes. Without this PR that reset
left zedkube 121 s past its last watchdog kick.
can't get KSIerrors before or after the failure.Tested on an amd64 3-node cluster with two failovers of the same app.
Each time
DetachOldWorkloadcompleted in under 10 s and the app cameup on the surviving node. The first run, without the vmirs reset kick,
logged the 121 s watchdog warning; the second, with it, did not.
Changelog notes
eve-k: a node taking over apps from a failed cluster node no longer
risks a watchdog reboot when the Kubernetes API server is slow to
respond.
PR Backports
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.
🤖 Generated with Claude Code