Skip to content

Commit

Permalink
refactor: just fetch the one being added
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Yu <jack.yu@suse.com>
  • Loading branch information
Yu-Jack committed Jul 3, 2024
1 parent 2418b04 commit 45bfbb0
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions pkg/controller/usbdevice/usbdevice_claim_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ func (h *DevClaimHandler) OnUSBDeviceClaimChanged(_ string, usbDeviceClaim *v1be
return usbDeviceClaim, err
}

newVirt, err := h.updateKubeVirt(virt, usbDevice)
_, err = h.updateKubeVirt(virt, usbDevice)
if err != nil {
logrus.Errorf("failed to update kubevirt: %v", err)
return usbDeviceClaim, err
}

// start device plugin if it's not started yet.
if _, ok := h.devicePlugin[usbDeviceClaim.Name]; !ok {
pluginDevices := discoverAllowedUSBDevices(newVirt.Spec.Configuration.PermittedHostDevices.USB)
pluginDevices := discoverAllowedUSBDevices(convertToKubeVirtUSBFormat(usbDevice))

if pluginDevice := h.findDevicePlugin(pluginDevices, usbDevice); pluginDevice != nil {
usbDevicePlugin := h.devicePluginConvertor(usbDevice.Status.ResourceName, []*deviceplugins.PluginDevices{pluginDevice})
Expand Down Expand Up @@ -286,3 +286,18 @@ func (h *DevClaimHandler) updateKubeVirt(virt *kubevirtv1.KubeVirt, usbDevice *v

return virt, nil
}

func convertToKubeVirtUSBFormat(ub *v1beta1.USBDevice) []kubevirtv1.USBHostDevice {
return []kubevirtv1.USBHostDevice{
{
Selectors: []kubevirtv1.USBSelector{
{
Vendor: ub.Status.VendorID,
Product: ub.Status.ProductID,
},
},
ResourceName: ub.Status.ResourceName,
ExternalResourceProvider: true,
},
}
}

0 comments on commit 45bfbb0

Please sign in to comment.