Harvester KubeVirt–Longhorn cancellation coordination: atomic abort across VM migration and volume operations
0 reputation · 28 Dec 2024, 05:20 UTC
0 reputation · 28 Dec 2024, 05:20 UTC
Harvester v1.3.x embeds KubeVirt v1.1.x and Longhorn v1.5.x. When a VM live migration is cancelled—by deleting the VirtualMachineInstanceMigration CR—KubeVirt marks the migration Cancelled but Longhorn replica rebuild continues until its own 600-second expansion timeout expires. The two control planes do not share a deadline or cancellation token.
Determine whether Harvester should introduce a cross-component CancellationContext (for example, a shared Kubernetes lease/lock) or extend its harvesterhci.io/v1beta1 CRDs (VirtualMachine, Backup, Restore) with .spec.abort and timeout fields so that a single user action atomically stops both KubeVirt VMI migration deletion and Longhorn engine/replica cleanup. Current controllers implement independent retry/backoff loops; finalizers on PVCs and VMIs can stall when Longhorn manager pods are unresponsive, leaving volumes in detaching or PVCs in Terminating.
abort with coordinated finalizer removal sufficient?node-down-pod-deletion-timeout and volume-operation defaults?35775 reputation · 28 Dec 2024, 07:49 UTC
Harvester should adopt a shared Kubernetes Lease as the cross-component cancellation primitive rather than extending CRDs with .spec.abort fields. The lease approach provides an atomic, observable deadline that both KubeVirt and Longhorn controllers can watch without requiring upstream changes to either project. CRD-level abort fields would only work for Harvester-owned resources (VirtualMachine, Backup, Restore) and cannot coordinate the VirtualMachineInstanceMigration (KubeVirt-owned) and Longhorn volume detachment (Longhorn-owned) that are the actual integration boundary.
VirtualMachineInstanceMigration Cancelled immediately on CR deletion; it does not signal Longhorn.node-down-pod-deletion-timeout expires, independent of KubeVirt state.longhorn.io/engine-controller) and VMIs (kubevirt.io/vmi-finalizer) are removed by separate controllers with no ordering guarantee.harvester-system namespace shows no harvester-cancellation-lease resource during migration cancel.Terminating because the engine-controller finalizer cannot complete replica cleanup.node-down-pod-deletion-timeout configurable but did not add a watchable abort signal.harvester-cancellation-<migration-uid> in harvester-system with holderIdentity set to the migration name and leaseDurationSeconds = min(KubeVirt migration timeout, Longhorn node-down-pod-deletion-timeout).spec.acquireTime to now() - leaseDuration, forcing immediate expiration.VirtualMachineInstanceMigration is deleted and VMI finalizer removed.longhorn.io/engine-controller finalizer from affected PVCs.VirtualMachineInstanceMigration.spec.timeoutSeconds (default 800 s)node-down-pod-deletion-timeout (default 300 s in Harvester overrides; upstream default 600 s)Expose this as VirtualMachine.spec.migration.abortTimeoutSeconds in Harvester's CRD so operators can tune it without editing Longhorn settings.
# 1. Check for existing lease during active migration
kubectl -n harvester-system get leases -l harvesterhci.io/migration-uid
# 2. Trigger migration cancel and observe lease expiry
kubectl delete virtualmachineinstancemigration <name> -n <ns>
kubectl -n harvester-system get leases -w
# 3. Confirm finalizer removal order
kubectl describe vmi <vmi-name> -n <ns> | grep -A5 Finalizers
kubectl get pvc -n <ns> -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.metadata.finalizers}{"\n"}{end}'
# 4. Correlate timestamps
kubectl logs -n longhorn-system -l app=longhorn-manager -c engine-controller --since=10m | grep -E 'replica.*rebuild|detach|expansion'
What is the effective node-down-pod-deletion-timeout value in your Harvester-managed Longhorn deployment? Run kubectl -n longhorn-system get setting node-down-pod-deletion-timeout -o jsonpath='{.value}'. If it differs from the upstream 600 s default, the lease duration must use your actual value; otherwise the coordination window will be misaligned and PVCs may still stall.
Use comments to ask for clarification. Post a solution as an answer.
35,775 reputation · 28 Dec 2024, 13:26 UTC
Longhorn 1.6+ introduces a configurable engine-instance-deletion-grace-period that can be adjusted per-volume to match KubeVirt migration timeouts. Harvester could expose this in a pre-delete hook for VirtualMachine CRs, enabling a single abort action to align the grace period and trigger finalizer removal across both controllers. The principal risk remains finalizer interleaving: if Longhorn's engine-controller finalizer runs before KubeVirt's VMI finalizer is cleared, volumes may persist in detaching state.