Skip to content

Commit 7d16fab

Browse files
author
Valeriy Khorunzhin
committed
resolve
Signed-off-by: Valeriy Khorunzhin <valeriy.khorunzhin@flant.com>
1 parent cf6a275 commit 7d16fab

3 files changed

Lines changed: 34 additions & 45 deletions

File tree

test/e2e/internal/util/vm.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ func RebootVirtualMachineByVMOP(f *framework.Framework, vm *v1alpha2.VirtualMach
308308
func RebootVirtualMachineByPodDeletion(f *framework.Framework, vm *v1alpha2.VirtualMachine) {
309309
GinkgoHelper()
310310

311-
activePodName, err := getActivePodName(vm)
311+
activePodName, err := GetActivePodName(vm)
312312
Expect(err).NotTo(HaveOccurred())
313313
Expect(activePodName).NotTo(BeEmpty())
314314

@@ -323,7 +323,34 @@ func RebootVirtualMachineByPodDeletion(f *framework.Framework, vm *v1alpha2.Virt
323323
Expect(err).NotTo(HaveOccurred())
324324
}
325325

326-
func getActivePodName(vm *v1alpha2.VirtualMachine) (string, error) {
326+
func GetVirtualMachineAndActivePod(ctx context.Context, f *framework.Framework, vm *v1alpha2.VirtualMachine) (*v1alpha2.VirtualMachine, *corev1.Pod, error) {
327+
var currentVM v1alpha2.VirtualMachine
328+
err := f.GenericClient().Get(ctx, client.ObjectKey{
329+
Namespace: vm.Namespace,
330+
Name: vm.Name,
331+
}, &currentVM)
332+
if err != nil {
333+
return nil, nil, err
334+
}
335+
336+
activePodName, err := GetActivePodName(&currentVM)
337+
if err != nil {
338+
return nil, nil, err
339+
}
340+
341+
var activePod corev1.Pod
342+
err = f.GenericClient().Get(ctx, client.ObjectKey{
343+
Namespace: vm.Namespace,
344+
Name: activePodName,
345+
}, &activePod)
346+
if err != nil {
347+
return nil, nil, err
348+
}
349+
350+
return &currentVM, &activePod, nil
351+
}
352+
353+
func GetActivePodName(vm *v1alpha2.VirtualMachine) (string, error) {
327354
for _, pod := range vm.Status.VirtualMachinePods {
328355
if pod.Active {
329356
return pod.Name, nil

test/e2e/vm/evacuation.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,10 @@ func evacuateVirtualMachines(ctx context.Context, f *framework.Framework, vms ..
154154
Eventually(func(g Gomega) {
155155
pods = []corev1.Pod{}
156156
for _, vm := range vms {
157-
var currentVM v1alpha2.VirtualMachine
158-
err := f.GenericClient().Get(ctx, crclient.ObjectKeyFromObject(vm), &currentVM)
157+
_, pod, err := util.GetVirtualMachineAndActivePod(ctx, f, vm)
159158
g.Expect(err).NotTo(HaveOccurred())
160-
161-
activePodName, err := getActiveVirtualMachinePodName(&currentVM)
162-
g.Expect(err).NotTo(HaveOccurred())
163-
164-
var pod corev1.Pod
165-
err = f.GenericClient().Get(ctx, crclient.ObjectKey{Namespace: vm.Namespace, Name: activePodName}, &pod)
166-
g.Expect(err).NotTo(HaveOccurred())
167-
pods = append(pods, pod)
159+
g.Expect(pod).NotTo(BeNil())
160+
pods = append(pods, *pod)
168161
}
169162
}).WithTimeout(framework.MiddleTimeout).WithPolling(framework.PollingInterval).Should(Succeed())
170163

test/e2e/vm/label_annotation.go

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ import (
2222

2323
. "github.com/onsi/ginkgo/v2"
2424
. "github.com/onsi/gomega"
25-
corev1 "k8s.io/api/core/v1"
26-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2725
crclient "sigs.k8s.io/controller-runtime/pkg/client"
2826

2927
vmbuilder "github.com/deckhouse/virtualization-controller/pkg/builder/vm"
@@ -124,7 +122,7 @@ func expectLabelState(ctx context.Context, f *framework.Framework, vm *v1alpha2.
124122
GinkgoHelper()
125123

126124
Eventually(func(g Gomega) {
127-
currentVM, activePod, err := getVirtualMachineAndActivePod(ctx, f, vm)
125+
currentVM, activePod, err := util.GetVirtualMachineAndActivePod(ctx, f, vm)
128126
g.Expect(err).NotTo(HaveOccurred())
129127

130128
if isPresent {
@@ -142,7 +140,7 @@ func expectAnnotationState(ctx context.Context, f *framework.Framework, vm *v1al
142140
GinkgoHelper()
143141

144142
Eventually(func(g Gomega) {
145-
currentVM, activePod, err := getVirtualMachineAndActivePod(ctx, f, vm)
143+
currentVM, activePod, err := util.GetVirtualMachineAndActivePod(ctx, f, vm)
146144
g.Expect(err).NotTo(HaveOccurred())
147145

148146
if isPresent {
@@ -155,32 +153,3 @@ func expectAnnotationState(ctx context.Context, f *framework.Framework, vm *v1al
155153
g.Expect(activePod.Annotations).NotTo(HaveKey(metadataSpecialKey))
156154
}).WithTimeout(framework.LongTimeout).WithPolling(framework.PollingInterval).Should(Succeed())
157155
}
158-
159-
func getVirtualMachineAndActivePod(ctx context.Context, f *framework.Framework, vm *v1alpha2.VirtualMachine) (*v1alpha2.VirtualMachine, *corev1.Pod, error) {
160-
currentVM, err := f.VirtClient().VirtualMachines(vm.Namespace).Get(ctx, vm.Name, metav1.GetOptions{})
161-
if err != nil {
162-
return nil, nil, err
163-
}
164-
165-
activePodName, err := getActiveVirtualMachinePodName(currentVM)
166-
if err != nil {
167-
return nil, nil, err
168-
}
169-
170-
activePod, err := f.KubeClient().CoreV1().Pods(vm.Namespace).Get(ctx, activePodName, metav1.GetOptions{})
171-
if err != nil {
172-
return nil, nil, err
173-
}
174-
175-
return currentVM, activePod, nil
176-
}
177-
178-
func getActiveVirtualMachinePodName(vm *v1alpha2.VirtualMachine) (string, error) {
179-
for _, pod := range vm.Status.VirtualMachinePods {
180-
if pod.Active {
181-
return pod.Name, nil
182-
}
183-
}
184-
185-
return "", fmt.Errorf("active pod was not found for vm %s/%s", vm.Namespace, vm.Name)
186-
}

0 commit comments

Comments
 (0)