Skip to content

Commit 58b1aed

Browse files
committed
++ add feature gate with hotplug fatures to "AwaitingRestart Condition for NonMigratable VM" test
Signed-off-by: Ivan Mikheykin <ivan.mikheykin@flant.com>
1 parent 7c6e399 commit 58b1aed

1 file changed

Lines changed: 37 additions & 4 deletions

File tree

images/virtualization-artifact/pkg/controller/vm/internal/sync_kvvm_test.go

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
. "github.com/onsi/gomega"
2525
"k8s.io/apimachinery/pkg/api/resource"
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27+
"k8s.io/component-base/featuregate"
2728
"k8s.io/utils/ptr"
2829
virtv1 "kubevirt.io/api/core/v1"
2930
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -54,13 +55,15 @@ var _ = Describe("SyncKvvmHandler", func() {
5455
reconcileObj *reconciler.Resource[*v1alpha2.VirtualMachine, v1alpha2.VirtualMachineStatus]
5556
vmState state.VirtualMachineState
5657
recorder *eventrecord.EventRecorderLoggerMock
58+
featureGates featuregate.FeatureGate
5759
)
5860

5961
BeforeEach(func() {
6062
ctx = testutil.ContextBackgroundWithNoOpLogger()
6163
fakeClient = nil
6264
reconcileObj = nil
6365
vmState = nil
66+
featureGates = nil
6467
recorder = &eventrecord.EventRecorderLoggerMock{
6568
EventFunc: func(_ client.Object, _, _, _ string) {},
6669
EventfFunc: func(_ client.Object, _, _, _ string, _ ...interface{}) {},
@@ -201,7 +204,10 @@ var _ = Describe("SyncKvvmHandler", func() {
201204
}
202205

203206
reconcile := func() {
204-
h := NewSyncKvvmHandler(nil, fakeClient, recorder, featuregates.Default(), vmservice.NewMigrationVolumesService(fakeClient, MakeKVVMFromVMSpec, 10*time.Second))
207+
if featureGates == nil {
208+
featureGates = featuregates.Default()
209+
}
210+
h := NewSyncKvvmHandler(nil, fakeClient, recorder, featureGates, vmservice.NewMigrationVolumesService(fakeClient, MakeKVVMFromVMSpec, 10*time.Second))
205211
_, err := h.Handle(ctx, vmState)
206212
Expect(err).NotTo(HaveOccurred())
207213
err = reconcileObj.Update(context.Background())
@@ -298,7 +304,7 @@ var _ = Describe("SyncKvvmHandler", func() {
298304
)
299305

300306
DescribeTable("AwaitingRestart Condition for NonMigratable VM",
301-
func(phase v1alpha2.MachinePhase, mutateFn func(fakeClient client.WithWatch, vm *v1alpha2.VirtualMachine, kvvm *virtv1.VirtualMachine), expectedStatus metav1.ConditionStatus, expectedExistence bool) {
307+
func(phase v1alpha2.MachinePhase, featureGate featuregate.FeatureGate, mutateFn func(fakeClient client.WithWatch, vm *v1alpha2.VirtualMachine, kvvm *virtv1.VirtualMachine), expectedStatus metav1.ConditionStatus, expectedExistence bool) {
302308
ip := makeVMIP()
303309
vmClass := makeVMClass()
304310

@@ -317,6 +323,8 @@ var _ = Describe("SyncKvvmHandler", func() {
317323

318324
fakeClient, reconcileObj, vmState = setupEnvironment(vm, kvvm, kvvmi, ip, vmClass)
319325

326+
featureGates = featureGate
327+
320328
reconcile()
321329

322330
newVM := &v1alpha2.VirtualMachine{}
@@ -329,8 +337,10 @@ var _ = Describe("SyncKvvmHandler", func() {
329337
Expect(awaitCond.Status).To(Equal(expectedStatus))
330338
}
331339
},
332-
Entry("should present on hotplugging cpu.cores", v1alpha2.MachineRunning, mutateCPUCores(3), metav1.ConditionTrue, true),
333-
Entry("should present on hotplugging memory.size", v1alpha2.MachineRunning, mutateMemorySize("4Gi"), metav1.ConditionTrue, true),
340+
Entry("should present on cpu.cores change", v1alpha2.MachineRunning, nil, mutateCPUCores(3), metav1.ConditionTrue, true),
341+
Entry("should present on cpu.cores change when hotplug enabled", v1alpha2.MachineRunning, newFeatureGateEnableCPUHotplug(), mutateCPUCores(3), metav1.ConditionTrue, true),
342+
Entry("should present on memory.size change", v1alpha2.MachineRunning, nil, mutateMemorySize("4Gi"), metav1.ConditionTrue, true),
343+
Entry("should present on memory.size change when hotplug enabled", v1alpha2.MachineRunning, newFeatureGateEnableMemoryHotplug(), mutateMemorySize("4Gi"), metav1.ConditionTrue, true),
334344
)
335345

336346
DescribeTable("ConfigurationApplied Condition Tests",
@@ -396,3 +406,26 @@ var _ = Describe("SyncKvvmHandler", func() {
396406
Entry("cpu change is not a placement policy", "cpu.cores", false),
397407
)
398408
})
409+
410+
func newFeatureGate(enabled ...featuregate.Feature) featuregate.FeatureGate {
411+
GinkgoHelper()
412+
413+
gate, setFromMap, err := featuregates.NewUnlocked()
414+
Expect(err).NotTo(HaveOccurred())
415+
featureMap := map[string]bool{}
416+
for _, feature := range enabled {
417+
featureMap[string(feature)] = true
418+
}
419+
err = setFromMap(featureMap)
420+
Expect(err).NotTo(HaveOccurred())
421+
422+
return gate
423+
}
424+
425+
func newFeatureGateEnableCPUHotplug() featuregate.FeatureGate {
426+
return newFeatureGate(featuregates.HotplugCPUWithLiveMigration)
427+
}
428+
429+
func newFeatureGateEnableMemoryHotplug() featuregate.FeatureGate {
430+
return newFeatureGate(featuregates.HotplugMemoryWithLiveMigration)
431+
}

0 commit comments

Comments
 (0)