Skip to content

Commit

Permalink
dbg: Check potential bug
Browse files Browse the repository at this point in the history
Signed-off-by: Ram Lavi <[email protected]>
  • Loading branch information
RamLavi committed Dec 18, 2024
1 parent e9259c5 commit 7843da3
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/e2e/persistentips_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ var _ = DescribeTableSubtree("Persistent IPs", func(params testParams) {
vmiIPsBeforeMigration := testenv.GetIPsFromVMIStatus(vmi, params.networkInterfaceName)
Expect(vmiIPsBeforeMigration).NotTo(BeEmpty())

virtLauncherPod, err := testenv.VirtualMachineInstancePod(vmi)
Expect(err).NotTo(HaveOccurred())
fmt.Printf("\nRAM B4 Migration vmi %s virtLauncherPod %s Annotations %+v\n", vmi.Name, virtLauncherPod.Name, virtLauncherPod.Annotations)

testenv.LiveMigrateVirtualMachine(td.Namespace, vm.Name)
testenv.CheckLiveMigrationSucceeded(td.Namespace, vm.Name)

Expand All @@ -129,6 +133,10 @@ var _ = DescribeTableSubtree("Persistent IPs", func(params testParams) {
WithTimeout(5 * time.Minute).
Should(testenv.ContainConditionVMIReady())

virtLauncherPod, err = testenv.VirtualMachineInstancePod(vmi)
Expect(err).NotTo(HaveOccurred())
fmt.Printf("\nRAM After Migration vmi %s virtLauncherPod %s Annotations %+v\n", vmi.Name, virtLauncherPod.Name, virtLauncherPod.Annotations)

Expect(testenv.ThisVMI(vmi)()).Should(testenv.MatchIPsAtInterfaceByName(params.networkInterfaceName, ConsistOf(vmiIPsBeforeMigration)))
})

Expand Down Expand Up @@ -285,9 +293,17 @@ var _ = DescribeTableSubtree("Persistent IPs", func(params testParams) {
vmiIPsBeforeMigration := testenv.GetIPsFromVMIStatus(vmi, params.networkInterfaceName)
Expect(vmiIPsBeforeMigration).NotTo(BeEmpty())

virtLauncherPod, err := testenv.VirtualMachineInstancePod(vmi)
Expect(err).NotTo(HaveOccurred())
fmt.Printf("\nRAM B4 Migration vmi %s virtLauncherPod %s Annotations %+v\n", vmi.Name, virtLauncherPod.Name, virtLauncherPod.Annotations)

testenv.LiveMigrateVirtualMachine(td.Namespace, vmi.Name)
testenv.CheckLiveMigrationSucceeded(td.Namespace, vmi.Name)

virtLauncherPod, err = testenv.VirtualMachineInstancePod(vmi)
Expect(err).NotTo(HaveOccurred())
fmt.Printf("\nRAM After Migration vmi %s virtLauncherPod %s Annotations %+v\n", vmi.Name, virtLauncherPod.Name, virtLauncherPod.Annotations)

Expect(testenv.ThisVMI(vmi)()).Should(testenv.MatchIPsAtInterfaceByName(params.networkInterfaceName, ConsistOf(vmiIPsBeforeMigration)))
})

Expand Down
42 changes: 42 additions & 0 deletions test/env/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package env

import (
"context"
"fmt"

corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand Down Expand Up @@ -46,3 +48,43 @@ func GetIPsFromVMIStatus(vmi *kubevirtv1.VirtualMachineInstance, networkInterfac
}
return ifaceStatus.IPs
}

func VirtualMachineInstancePod(vmi *kubevirtv1.VirtualMachineInstance) (*corev1.Pod, error) {
pod, err := lookupPodBySelector(vmi.Namespace, vmiLabelSelector(vmi), vmiFieldSelector(vmi))
if err != nil {
return nil, fmt.Errorf("failed to find pod for VMI %s (%s)", vmi.Name, string(vmi.GetUID()))
}
return pod, nil
}

func lookupPodBySelector(namespace string, labelSelector, fieldSelector map[string]string) (*corev1.Pod, error) {
pods := &corev1.PodList{}
err := Client.List(
context.Background(),
pods,
client.InNamespace(namespace),
client.MatchingLabels(labelSelector),
client.MatchingFields(fieldSelector))
if err != nil {
return nil, err
}

if len(pods.Items) == 0 {
return nil, fmt.Errorf("failed to lookup pod with labels %v, fields %v in namespace %s", labelSelector, fieldSelector, namespace)
}

return &pods.Items[0], nil
}

func vmiLabelSelector(vmi *kubevirtv1.VirtualMachineInstance) map[string]string {
return map[string]string{kubevirtv1.CreatedByLabel: string(vmi.GetUID())}
}

func vmiFieldSelector(vmi *kubevirtv1.VirtualMachineInstance) map[string]string {
fieldSelectors := map[string]string{}
if vmi.Status.Phase == kubevirtv1.Running {
const podPhase = "status.phase"
fieldSelectors[podPhase] = string(corev1.PodRunning)
}
return fieldSelectors
}

0 comments on commit 7843da3

Please sign in to comment.