@@ -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"
@@ -55,13 +56,15 @@ var _ = Describe("SyncKvvmHandler", func() {
5556 reconcileObj * reconciler.Resource [* v1alpha2.VirtualMachine , v1alpha2.VirtualMachineStatus ]
5657 vmState state.VirtualMachineState
5758 recorder * eventrecord.EventRecorderLoggerMock
59+ featureGates featuregate.FeatureGate
5860 )
5961
6062 BeforeEach (func () {
6163 ctx = testutil .ContextBackgroundWithNoOpLogger ()
6264 fakeClient = nil
6365 reconcileObj = nil
6466 vmState = nil
67+ featureGates = nil
6568 recorder = & eventrecord.EventRecorderLoggerMock {
6669 EventFunc : func (_ client.Object , _ , _ , _ string ) {},
6770 EventfFunc : func (_ client.Object , _ , _ , _ string , _ ... interface {}) {},
@@ -205,7 +208,10 @@ var _ = Describe("SyncKvvmHandler", func() {
205208 }
206209
207210 reconcile := func () {
208- h := NewSyncKvvmHandler (nil , fakeClient , recorder , featuregates .Default (), vmservice .NewMigrationVolumesService (fakeClient , MakeKVVMFromVMSpec , 10 * time .Second ))
211+ if featureGates == nil {
212+ featureGates = featuregates .Default ()
213+ }
214+ h := NewSyncKvvmHandler (nil , fakeClient , recorder , featureGates , vmservice .NewMigrationVolumesService (fakeClient , MakeKVVMFromVMSpec , 10 * time .Second ))
209215 _ , err := h .Handle (ctx , vmState )
210216 Expect (err ).NotTo (HaveOccurred ())
211217 err = reconcileObj .Update (context .Background ())
@@ -302,7 +308,7 @@ var _ = Describe("SyncKvvmHandler", func() {
302308 )
303309
304310 DescribeTable ("AwaitingRestart Condition for NonMigratable VM" ,
305- func (phase v1alpha2.MachinePhase , mutateFn func (fakeClient client.WithWatch , vm * v1alpha2.VirtualMachine , kvvm * virtv1.VirtualMachine ), expectedStatus metav1.ConditionStatus , expectedExistence bool ) {
311+ func (phase v1alpha2.MachinePhase , featureGate featuregate. FeatureGate , mutateFn func (fakeClient client.WithWatch , vm * v1alpha2.VirtualMachine , kvvm * virtv1.VirtualMachine ), expectedStatus metav1.ConditionStatus , expectedExistence bool ) {
306312 ip := makeVMIP ()
307313 vmClass := makeVMClass ()
308314
@@ -321,6 +327,8 @@ var _ = Describe("SyncKvvmHandler", func() {
321327
322328 fakeClient , reconcileObj , vmState = setupEnvironment (vm , kvvm , kvvmi , ip , vmClass )
323329
330+ featureGates = featureGate
331+
324332 reconcile ()
325333
326334 newVM := & v1alpha2.VirtualMachine {}
@@ -333,8 +341,10 @@ var _ = Describe("SyncKvvmHandler", func() {
333341 Expect (awaitCond .Status ).To (Equal (expectedStatus ))
334342 }
335343 },
336- Entry ("should present on hotplugging cpu.cores" , v1alpha2 .MachineRunning , mutateCPUCores (3 ), metav1 .ConditionTrue , true ),
337- Entry ("should present on hotplugging memory.size" , v1alpha2 .MachineRunning , mutateMemorySize ("4Gi" ), metav1 .ConditionTrue , true ),
344+ Entry ("should present on cpu.cores change" , v1alpha2 .MachineRunning , nil , mutateCPUCores (3 ), metav1 .ConditionTrue , true ),
345+ Entry ("should present on cpu.cores change when hotplug enabled" , v1alpha2 .MachineRunning , newFeatureGateEnableCPUHotplug (), mutateCPUCores (3 ), metav1 .ConditionTrue , true ),
346+ Entry ("should present on memory.size change" , v1alpha2 .MachineRunning , nil , mutateMemorySize ("4Gi" ), metav1 .ConditionTrue , true ),
347+ Entry ("should present on memory.size change when hotplug enabled" , v1alpha2 .MachineRunning , newFeatureGateEnableMemoryHotplug (), mutateMemorySize ("4Gi" ), metav1 .ConditionTrue , true ),
338348 )
339349
340350 DescribeTable ("ConfigurationApplied Condition Tests" ,
@@ -436,3 +446,26 @@ var _ = Describe("SyncKvvmHandler", func() {
436446 Entry ("cpu change is not a placement policy" , "cpu.cores" , false ),
437447 )
438448})
449+
450+ func newFeatureGate (enabled ... featuregate.Feature ) featuregate.FeatureGate {
451+ GinkgoHelper ()
452+
453+ gate , setFromMap , err := featuregates .NewUnlocked ()
454+ Expect (err ).NotTo (HaveOccurred ())
455+ featureMap := map [string ]bool {}
456+ for _ , feature := range enabled {
457+ featureMap [string (feature )] = true
458+ }
459+ err = setFromMap (featureMap )
460+ Expect (err ).NotTo (HaveOccurred ())
461+
462+ return gate
463+ }
464+
465+ func newFeatureGateEnableCPUHotplug () featuregate.FeatureGate {
466+ return newFeatureGate (featuregates .HotplugCPUWithLiveMigration )
467+ }
468+
469+ func newFeatureGateEnableMemoryHotplug () featuregate.FeatureGate {
470+ return newFeatureGate (featuregates .HotplugMemoryWithLiveMigration )
471+ }
0 commit comments