Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly handle live migration of VMs with hotplugged volumes #1400

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Properly handle live migration of VMs with hotplugged volumes
It was treating the hotplugged volumes as if they
were not part of the VM and would attempt to migrate
them offline. This fixes the check that matches the volumes
with the VM.

Signed-off-by: Alexander Wels <awels@redhat.com>
awels committed Jan 29, 2025
commit 49ff200475ae3de47658b4545f23d084e4d5feaa
21 changes: 19 additions & 2 deletions pkg/controller/directvolumemigration/vm.go
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@ const (
prometheusRoute = "prometheus-k8s"
progressQuery = "kubevirt_vmi_migration_data_processed_bytes{name=\"%s\"} / (kubevirt_vmi_migration_data_processed_bytes{name=\"%s\"} + kubevirt_vmi_migration_data_remaining_bytes{name=\"%s\"}) * 100"
VMIKind = "VirtualMachineInstance"
PodKind = "Pod"
)

var (
@@ -164,9 +165,14 @@ func getRunningVmVolumeMap(client k8sclient.Client, namespace string) (map[strin
if err != nil {
return nil, err
}
podList := corev1.PodList{}
podNameMap := make(map[string]*corev1.Pod)
client.List(context.TODO(), &podList, k8sclient.InNamespace(namespace))
for _, pod := range podList.Items {
podNameMap[pod.Name] = &pod
}

for vmName := range vmMap {
podList := corev1.PodList{}
client.List(context.TODO(), &podList, k8sclient.InNamespace(namespace))
for _, pod := range podList.Items {
for _, owner := range pod.OwnerReferences {
if owner.Name == vmName && owner.Kind == VMIKind {
@@ -176,6 +182,17 @@ func getRunningVmVolumeMap(client k8sclient.Client, namespace string) (map[strin
}
}
}
if owner.Kind == PodKind && strings.HasPrefix(owner.Name, "hp-") {
if ownerPod, ok := podNameMap[owner.Name]; ok {
if ownerPod.Name == owner.Name {
for _, volume := range pod.Spec.Volumes {
if volume.PersistentVolumeClaim != nil {
volumesVmMap[volume.PersistentVolumeClaim.ClaimName] = vmName
}
}
}
}
}
}
}
}