Skip to content

Commit

Permalink
minor changes to reconcile kubevirtCR based on feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrokethecloud committed Apr 13, 2023
1 parent fea5ff3 commit 7cfa4f2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
9 changes: 5 additions & 4 deletions pkg/controller/pcideviceclaim/pcideviceclaim_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,17 +336,17 @@ func (h *Handler) permitHostDeviceInKubeVirt(pd *v1beta1.PCIDevice) error {
return errors.New(msg)
}

kvCopy := kv.DeepCopy()
reconcileKubevirtCR(kvCopy, pd)
if !reflect.DeepEqual(kv, kvCopy) {
kvCopy := reconcileKubevirtCR(kv, pd)
if !reflect.DeepEqual(kv.Spec.Configuration.PermittedHostDevices, kvCopy.Spec.Configuration.PermittedHostDevices) {
_, err := h.virtClient.KubeVirt(DefaultNS).Update(kvCopy)
return err
}

return nil
}

func reconcileKubevirtCR(kv *kubevirtv1.KubeVirt, pd *v1beta1.PCIDevice) {
func reconcileKubevirtCR(kvObj *kubevirtv1.KubeVirt, pd *v1beta1.PCIDevice) *kubevirtv1.KubeVirt {
kv := kvObj.DeepCopy()
if kv.Spec.Configuration.PermittedHostDevices == nil {
kv.Spec.Configuration.PermittedHostDevices = &kubevirtv1.PermittedHostDevices{
PciHostDevices: []kubevirtv1.PciHostDevice{},
Expand Down Expand Up @@ -377,6 +377,7 @@ func reconcileKubevirtCR(kv *kubevirtv1.KubeVirt, pd *v1beta1.PCIDevice) {
}
kv.Spec.Configuration.PermittedHostDevices.PciHostDevices = append(permittedPCIDevices, devToPermit)
}
return kv
}

func (h *Handler) getPCIDeviceForClaim(pdc *v1beta1.PCIDeviceClaim) (*v1beta1.PCIDevice, error) {
Expand Down
14 changes: 6 additions & 8 deletions pkg/controller/pcideviceclaim/pcideviceclaim_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,15 @@ var (

func Test_permitHostDeviceInKubevirtWithNoDevices(t *testing.T) {
assert := require.New(t)
reconcileKubevirtCR(kubevirtCR, pd)
assert.Len(kubevirtCR.Spec.Configuration.PermittedHostDevices.PciHostDevices, 1, "expected to find one device added")
kvCopy := reconcileKubevirtCR(kubevirtCR, pd)
assert.Len(kvCopy.Spec.Configuration.PermittedHostDevices.PciHostDevices, 1, "expected to find one device added")
}

func Test_permitHostDeviceInKubevirtWithoutExternalResourceDevices(t *testing.T) {
assert := require.New(t)
kubevirtCR.Spec.Configuration.PermittedHostDevices = permittedHostDevices
kvCopy := kubevirtCR.DeepCopy()
reconcileKubevirtCR(kvCopy, pd)
assert.False(reflect.DeepEqual(kvCopy, kubevirtCR), "expected to find changes in the kubevirt CR")
kvCopy := reconcileKubevirtCR(kubevirtCR, pd)
assert.False(reflect.DeepEqual(kvCopy.Spec.Configuration.PermittedHostDevices, kubevirtCR.Spec.Configuration.PermittedHostDevices), "expected to find changes in the kubevirt CR")
assert.Len(kvCopy.Spec.Configuration.PermittedHostDevices.PciHostDevices, 1, "expected to find one device added")
assert.True(kvCopy.Spec.Configuration.PermittedHostDevices.PciHostDevices[0].ExternalResourceProvider, "expected external resource provider to be updated")
}
Expand All @@ -160,9 +159,8 @@ func Test_permitHostDeviceInKubevirtWithExternalResourceDevices(t *testing.T) {
assert := require.New(t)
permittedHostDevices.PciHostDevices[0].ExternalResourceProvider = true
kubevirtCR.Spec.Configuration.PermittedHostDevices = permittedHostDevices
kvCopy := kubevirtCR.DeepCopy()
reconcileKubevirtCR(kvCopy, pd)
assert.True(reflect.DeepEqual(kvCopy, kubevirtCR), "expected to find no changes in the kubevirt CR")
kvCopy := reconcileKubevirtCR(kubevirtCR, pd)
assert.True(reflect.DeepEqual(kvCopy.Spec.Configuration.PermittedHostDevices, kubevirtCR.Spec.Configuration.PermittedHostDevices), "expected to find no changes in the kubevirt CR")
assert.Len(kvCopy.Spec.Configuration.PermittedHostDevices.PciHostDevices, 1, "expected to find one device added")
assert.True(kvCopy.Spec.Configuration.PermittedHostDevices.PciHostDevices[0].ExternalResourceProvider, "expected external resource provider to be updated")
}

0 comments on commit 7cfa4f2

Please sign in to comment.