@@ -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