Skip to content

Commit f5f00b0

Browse files
author
Valeriy Khorunzhin
committed
refactoring
Signed-off-by: Valeriy Khorunzhin <[email protected]>
1 parent fcc5c40 commit f5f00b0

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

test/e2e/internal/util/vm.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
. "github.com/onsi/gomega"
2727
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2828
"sigs.k8s.io/controller-runtime/pkg/client"
29+
crclient "sigs.k8s.io/controller-runtime/pkg/client"
2930

3031
vmopbuilder "github.com/deckhouse/virtualization-controller/pkg/builder/vmop"
3132
"github.com/deckhouse/virtualization-controller/pkg/controller/conditions"
@@ -148,3 +149,21 @@ func IsVDAttached(vm *v1alpha2.VirtualMachine, vd *v1alpha2.VirtualDisk) bool {
148149
}
149150
return false
150151
}
152+
153+
func IsRestartRequired(vm *v1alpha2.VirtualMachine, timeout time.Duration) bool {
154+
GinkgoHelper()
155+
156+
if vm.Spec.Disruptions.RestartApprovalMode != v1alpha2.Manual {
157+
return false
158+
}
159+
160+
Eventually(func(g Gomega) {
161+
err := framework.GetClients().GenericClient().Get(context.Background(), crclient.ObjectKeyFromObject(vm), vm)
162+
g.Expect(err).NotTo(HaveOccurred())
163+
needRestart, _ := conditions.GetCondition(vmcondition.TypeAwaitingRestartToApplyConfiguration, vm.Status.Conditions)
164+
g.Expect(needRestart.Status).To(Equal(metav1.ConditionTrue))
165+
g.Expect(vm.Status.RestartAwaitingChanges).NotTo(BeNil())
166+
}).WithTimeout(timeout).WithPolling(time.Second).Should(Succeed())
167+
168+
return true
169+
}

test/e2e/vm/configuration.go

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
. "github.com/onsi/ginkgo/v2"
2626
. "github.com/onsi/gomega"
2727
"k8s.io/apimachinery/pkg/api/resource"
28-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2928
"k8s.io/utils/ptr"
3029
crclient "sigs.k8s.io/controller-runtime/pkg/client"
3130

@@ -88,9 +87,7 @@ var _ = Describe("VirtualMachineConfiguration", func() {
8887
err = f.Clients.GenericClient().Update(context.Background(), t.VM)
8988
Expect(err).NotTo(HaveOccurred())
9089

91-
t.CheckRestartAwaitingChanges(t.VM)
92-
93-
if t.VM.Spec.Disruptions.RestartApprovalMode == v1alpha2.Manual {
90+
if util.IsRestartRequired(t.VM, 3*time.Second) {
9491
util.RebootVirtualMachineBySSH(f, t.VM)
9592
}
9693

@@ -157,18 +154,3 @@ func (t *configurationTest) GenerateResources(restartApprovalMode v1alpha2.Resta
157154
vmbuilder.WithRestartApprovalMode(restartApprovalMode),
158155
)
159156
}
160-
161-
func (t *configurationTest) CheckRestartAwaitingChanges(vm *v1alpha2.VirtualMachine) {
162-
if vm.Spec.Disruptions.RestartApprovalMode != v1alpha2.Manual {
163-
return
164-
}
165-
166-
// Avoid race conditions during the calculation of the "need restart" condition.
167-
Eventually(func(g Gomega) {
168-
err := t.Framework.Clients.GenericClient().Get(context.Background(), crclient.ObjectKeyFromObject(t.VM), t.VM)
169-
g.Expect(err).NotTo(HaveOccurred())
170-
needRestart, _ := conditions.GetCondition(vmcondition.TypeAwaitingRestartToApplyConfiguration, t.VM.Status.Conditions)
171-
g.Expect(needRestart.Status).To(Equal(metav1.ConditionTrue))
172-
g.Expect(t.VM.Status.RestartAwaitingChanges).NotTo(BeNil())
173-
}).WithTimeout(3 * time.Second).WithPolling(time.Second).Should(Succeed())
174-
}

0 commit comments

Comments
 (0)