Repository navigation
kubeapi: patch Longhorn objects instead of replacing them - #7182
andrewd-zededa wants to merge 1 commit into
Conversation
|
Claude finished @rene's task in 2m 31s —— View job Review: kubeapi: patch Longhorn objects instead of replacing them
Verdict: looks correct, no blocking issues. The switch from full-object Checks I ran against the vendored types (
So a wrong field name silently pruned by the CRD schema — the main risk with merge patches — is not a concern. Other points confirmed:
Minor (non-blocking) observation: Nothing to fix. |
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>
fc3a4a4 to
8926dfa
Compare
|
Latest push is a rebase onto current master only, no code changes, to clear the previous CI failures. |
Description
pillar changes three kinds of Longhorn object: a volume and its engines
when a workload fails over to another node (
longhornVolumeSetNode,called from
DetachOldWorkload), and the EVE recurring snapshot job whenstorage.longhorn.snapshot.cronchanges (SetLonghornRecurringSnapshot).Each one read the object, changed a field and wrote the whole object back
with
Update.The object passes through pillar's vendored Longhorn types on the way, so
any field those types do not know is sent back as absent and the API
server clears it. With the Longhorn EVE ships today the types match and
nothing is lost, but newer Longhorn releases add spec fields to volumes,
engines and recurring jobs. Once the cluster runs a newer Longhorn than
the vendored client, these writes would reset those fields. This PR
removes that hazard in preparation for upgrading the Longhorn version in
use, and keeps it removed independent of when the vendored client is
bumped.
The writes are now JSON merge patches that name only the fields pillar
changes:
spec.nodeID, plusspec.backupTargetName: defaultwhen it isempty (Longhorn's webhook rejects any update to a volume without one);
spec.nodeID, for each engine of the volume;spec.cron.Two related changes in the same function:
status.ownerIDandstatus.currentNodeID.The volume CRD has a status subresource, so the API server already
ignored those in a plain
Update; they are dropped. Status belongs tolonghorn-manager.
nil, so failover reported successwithout moving the engines. It now returns the error.
The Longhorn node and setting writes are unchanged.
How to test and validate this PR
Automated:
make -C pkg/pillar testruns the newpkg/pillar/kubeapi/longhornpatch_test.go, which checks the exact patchbodies (node only, and node plus default backup target).
On a 3-node eve-k cluster, exercise the two actions that write Longhorn
objects. In each, first set by hand a spec field pillar does not write,
and check it survives:
a VM app with a replicated volume. The app should restart on another
node, with the Longhorn volume and its engine moved to that node.
zedkube's
DetachOldWorkload: set lhVol:<vol> to node:<node> err:logline should end in
err:<nil>; a failed write shows there aspatch volume ...,patch engine ...orlist engines ....storage.longhorn.snapshot.cronfrom the controller. Thedefault-eve-kube-app-snapshotRecurringJob should take the new cronand keep its other settings.
Both passed on an amd64 cluster.
Changelog notes
None. Internal change to how eve-k updates Longhorn objects; no
behaviour change with the Longhorn version EVE ships today.
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.