From a1b9beb6ff8df340faea8bff2466583fe2b34ac3 Mon Sep 17 00:00:00 2001 From: Jack Yu Date: Wed, 22 May 2024 17:04:45 +0800 Subject: [PATCH] refactor: rename pcifactory to devicefactory Signed-off-by: Jack Yu --- pkg/controller/setup.go | 20 +++++++++---------- .../usbdevice/usbdevice_claim_controller.go | 10 +++++----- .../usbdevice/usbdevice_controller.go | 8 ++++---- pkg/webhook/client.go | 8 ++++---- pkg/webhook/indexer.go | 4 ++-- pkg/webhook/mutation.go | 13 ++++++------ pkg/webhook/validation.go | 8 ++++---- 7 files changed, 36 insertions(+), 35 deletions(-) diff --git a/pkg/controller/setup.go b/pkg/controller/setup.go index acc86624..180501ca 100644 --- a/pkg/controller/setup.go +++ b/pkg/controller/setup.go @@ -54,7 +54,7 @@ func Setup(ctx context.Context, cfg *rest.Config, _ *runtime.Scheme) error { return err } - pciFactory, err := ctl.NewFactoryFromConfigWithOptions(cfg, &generic.FactoryOptions{ + deviceFactory, err := ctl.NewFactoryFromConfigWithOptions(cfg, &generic.FactoryOptions{ SharedControllerFactory: factory, }) @@ -78,17 +78,17 @@ func Setup(ctx context.Context, cfg *rest.Config, _ *runtime.Scheme) error { return fmt.Errorf("error building network controllers: %v", err) } - pdCtl := pciFactory.Devices().V1beta1().PCIDevice() - pdcCtl := pciFactory.Devices().V1beta1().PCIDeviceClaim() - usbDeviceCtrl := pciFactory.Devices().V1beta1().USBDevice() - usbDeviceClaimCtrl := pciFactory.Devices().V1beta1().USBDeviceClaim() - sriovCtl := pciFactory.Devices().V1beta1().SRIOVNetworkDevice() - nodeCtl := pciFactory.Devices().V1beta1().Node() + pdCtl := deviceFactory.Devices().V1beta1().PCIDevice() + pdcCtl := deviceFactory.Devices().V1beta1().PCIDeviceClaim() + usbDeviceCtrl := deviceFactory.Devices().V1beta1().USBDevice() + usbDeviceClaimCtrl := deviceFactory.Devices().V1beta1().USBDeviceClaim() + sriovCtl := deviceFactory.Devices().V1beta1().SRIOVNetworkDevice() + nodeCtl := deviceFactory.Devices().V1beta1().Node() coreNodeCtl := coreFactory.Core().V1().Node() vlanCtl := networkFactory.Network().V1beta1().VlanConfig() sriovNetworkDeviceCache := sriovCtl.Cache() - sriovGPUCtl := pciFactory.Devices().V1beta1().SRIOVGPUDevice() - vGPUCtl := pciFactory.Devices().V1beta1().VGPUDevice() + sriovGPUCtl := deviceFactory.Devices().V1beta1().SRIOVGPUDevice() + vGPUCtl := deviceFactory.Devices().V1beta1().VGPUDevice() podCtl := coreFactory.Core().V1().Pod() clientConfig := kubecli.DefaultClientConfig(&pflag.FlagSet{}) virtClient, err := kubecli.GetKubevirtClientFromClientConfig(clientConfig) @@ -118,7 +118,7 @@ func Setup(ctx context.Context, cfg *rest.Config, _ *runtime.Scheme) error { if err := gpudevice.Register(ctx, sriovGPUCtl, vGPUCtl, pdcCtl, podCtl, cfg); err != nil { return fmt.Errorf("error registering gpudevice controller :%v", err) } - if err := start.All(ctx, 2, coreFactory, networkFactory, pciFactory); err != nil { + if err := start.All(ctx, 2, coreFactory, networkFactory, deviceFactory); err != nil { return fmt.Errorf("error starting controllers :%v", err) } diff --git a/pkg/controller/usbdevice/usbdevice_claim_controller.go b/pkg/controller/usbdevice/usbdevice_claim_controller.go index 88cd9386..8d4c81a7 100644 --- a/pkg/controller/usbdevice/usbdevice_claim_controller.go +++ b/pkg/controller/usbdevice/usbdevice_claim_controller.go @@ -13,19 +13,19 @@ import ( "github.com/harvester/pcidevices/pkg/apis/devices.harvesterhci.io/v1beta1" "github.com/harvester/pcidevices/pkg/deviceplugins" - ctlpcidevicerv1 "github.com/harvester/pcidevices/pkg/generated/controllers/devices.harvesterhci.io/v1beta1" + ctldevicerv1beta1 "github.com/harvester/pcidevices/pkg/generated/controllers/devices.harvesterhci.io/v1beta1" ) type ClaimHandler struct { - usbClaimClient ctlpcidevicerv1.USBDeviceClaimController - usbClient ctlpcidevicerv1.USBDeviceController + usbClaimClient ctldevicerv1beta1.USBDeviceClaimController + usbClient ctldevicerv1beta1.USBDeviceController virtClient kubecli.KubevirtClient lock *sync.Mutex - usbDeviceCache ctlpcidevicerv1.USBDeviceCache + usbDeviceCache ctldevicerv1beta1.USBDeviceCache devicePlugin map[string]*deviceplugins.USBDevicePlugin } -func NewClaimHandler(usbDeviceCache ctlpcidevicerv1.USBDeviceCache, usbClaimClient ctlpcidevicerv1.USBDeviceClaimController, usbClient ctlpcidevicerv1.USBDeviceController, virtClient kubecli.KubevirtClient) *ClaimHandler { +func NewClaimHandler(usbDeviceCache ctldevicerv1beta1.USBDeviceCache, usbClaimClient ctldevicerv1beta1.USBDeviceClaimController, usbClient ctldevicerv1beta1.USBDeviceController, virtClient kubecli.KubevirtClient) *ClaimHandler { return &ClaimHandler{ usbDeviceCache: usbDeviceCache, usbClaimClient: usbClaimClient, diff --git a/pkg/controller/usbdevice/usbdevice_controller.go b/pkg/controller/usbdevice/usbdevice_controller.go index 51c4dcdd..fe62ebd7 100644 --- a/pkg/controller/usbdevice/usbdevice_controller.go +++ b/pkg/controller/usbdevice/usbdevice_controller.go @@ -12,14 +12,14 @@ import ( "github.com/harvester/pcidevices/pkg/apis/devices.harvesterhci.io/v1beta1" "github.com/harvester/pcidevices/pkg/deviceplugins" - ctlpcidevicerv1 "github.com/harvester/pcidevices/pkg/generated/controllers/devices.harvesterhci.io/v1beta1" + ctldevicerv1vbeta1 "github.com/harvester/pcidevices/pkg/generated/controllers/devices.harvesterhci.io/v1beta1" "github.com/harvester/pcidevices/pkg/util/gousb" "github.com/harvester/pcidevices/pkg/util/gousb/usbid" ) type Handler struct { - usbClient ctlpcidevicerv1.USBDeviceController - usbClaimClient ctlpcidevicerv1.USBDeviceClaimController + usbClient ctldevicerv1vbeta1.USBDeviceController + usbClaimClient ctldevicerv1vbeta1.USBDeviceClaimController virtClient kubecli.KubevirtClient } @@ -39,7 +39,7 @@ func (dev *USBDevice) GetID() string { return fmt.Sprintf("%04x:%04x-%02d:%02d", dev.Vendor, dev.Product, dev.Bus, dev.DeviceNumber) } -func NewHandler(usbClient ctlpcidevicerv1.USBDeviceController, usbClaimClient ctlpcidevicerv1.USBDeviceClaimController, virtClient kubecli.KubevirtClient) *Handler { +func NewHandler(usbClient ctldevicerv1vbeta1.USBDeviceController, usbClaimClient ctldevicerv1vbeta1.USBDeviceClaimController, virtClient kubecli.KubevirtClient) *Handler { return &Handler{ usbClient: usbClient, usbClaimClient: usbClaimClient, diff --git a/pkg/webhook/client.go b/pkg/webhook/client.go index dd7df52d..9467fd31 100644 --- a/pkg/webhook/client.go +++ b/pkg/webhook/client.go @@ -12,7 +12,7 @@ import ( ctlharvesterv1 "github.com/harvester/harvester/pkg/generated/controllers/harvesterhci.io" ctlkubevirtv1 "github.com/harvester/harvester/pkg/generated/controllers/kubevirt.io" - ctlpcidevices "github.com/harvester/pcidevices/pkg/generated/controllers/devices.harvesterhci.io" + ctldevices "github.com/harvester/pcidevices/pkg/generated/controllers/devices.harvesterhci.io" ) type Clients struct { @@ -20,7 +20,7 @@ type Clients struct { CoreFactory *ctlcore.Factory HarvesterFactory *ctlharvesterv1.Factory KubevirtFactory *ctlkubevirtv1.Factory - PCIFactory *ctlpcidevices.Factory + DeviceFactory *ctldevices.Factory } func NewClient(ctx context.Context, rest *rest.Config, threadiness int) (*Clients, error) { @@ -56,7 +56,7 @@ func NewClient(ctx context.Context, rest *rest.Config, threadiness int) (*Client return nil, err } - pciFactory, err := ctlpcidevices.NewFactoryFromConfigWithOptions(rest, clients.FactoryOptions) + deviceFactory, err := ctldevices.NewFactoryFromConfigWithOptions(rest, clients.FactoryOptions) if err != nil { return nil, err } @@ -70,6 +70,6 @@ func NewClient(ctx context.Context, rest *rest.Config, threadiness int) (*Client HarvesterFactory: harvesterFactory, KubevirtFactory: kubevirtFactory, CoreFactory: coreFactory, - PCIFactory: pciFactory, + DeviceFactory: deviceFactory, }, nil } diff --git a/pkg/webhook/indexer.go b/pkg/webhook/indexer.go index 009ed7ef..97ee5c91 100644 --- a/pkg/webhook/indexer.go +++ b/pkg/webhook/indexer.go @@ -24,10 +24,10 @@ func RegisterIndexers(clients *Clients) { vmCache.AddIndexer(VMByPCIDeviceClaim, vmByHostDeviceName) vmCache.AddIndexer(VMByUSBDeviceClaim, vmByHostDeviceName) vmCache.AddIndexer(VMByVGPU, vmByVGPUDevice) - deviceCache := clients.PCIFactory.Devices().V1beta1().PCIDevice().Cache() + deviceCache := clients.DeviceFactory.Devices().V1beta1().PCIDevice().Cache() deviceCache.AddIndexer(PCIDeviceByResourceName, pciDeviceByResourceName) deviceCache.AddIndexer(IommuGroupByNode, iommuGroupByNodeName) - usbDeviceClaimCache := clients.PCIFactory.Devices().V1beta1().USBDeviceClaim().Cache() + usbDeviceClaimCache := clients.DeviceFactory.Devices().V1beta1().USBDeviceClaim().Cache() usbDeviceClaimCache.AddIndexer(USBDeviceByAddress, usbDeviceClaimByAddress) } diff --git a/pkg/webhook/mutation.go b/pkg/webhook/mutation.go index 17c2318c..32a8765b 100644 --- a/pkg/webhook/mutation.go +++ b/pkg/webhook/mutation.go @@ -4,19 +4,20 @@ import ( "net/http" "reflect" - "github.com/harvester/harvester/pkg/webhook/types" "github.com/rancher/wrangler/pkg/webhook" "github.com/sirupsen/logrus" + + "github.com/harvester/harvester/pkg/webhook/types" ) func Mutation(clients *Clients) (http.Handler, []types.Resource, error) { mutators := []types.Mutator{ - NewPodMutator(clients.PCIFactory.Devices().V1beta1().PCIDevice().Cache(), + NewPodMutator(clients.DeviceFactory.Devices().V1beta1().PCIDevice().Cache(), clients.KubevirtFactory.Kubevirt().V1().VirtualMachine().Cache(), - clients.PCIFactory.Devices().V1beta1().VGPUDevice().Cache()), - NewPCIVMMutator(clients.PCIFactory.Devices().V1beta1().PCIDevice().Cache(), - clients.PCIFactory.Devices().V1beta1().PCIDeviceClaim().Cache(), - clients.PCIFactory.Devices().V1beta1().PCIDeviceClaim()), + clients.DeviceFactory.Devices().V1beta1().VGPUDevice().Cache()), + NewPCIVMMutator(clients.DeviceFactory.Devices().V1beta1().PCIDevice().Cache(), + clients.DeviceFactory.Devices().V1beta1().PCIDeviceClaim().Cache(), + clients.DeviceFactory.Devices().V1beta1().PCIDeviceClaim()), } router := webhook.NewRouter() diff --git a/pkg/webhook/validation.go b/pkg/webhook/validation.go index 6d686309..71c9e2af 100644 --- a/pkg/webhook/validation.go +++ b/pkg/webhook/validation.go @@ -10,16 +10,16 @@ import ( func Validation(clients *Clients) (http.Handler, []types.Resource, error) { validators := []types.Validator{ - NewSriovNetworkDeviceValidator(clients.PCIFactory.Devices().V1beta1().PCIDeviceClaim().Cache()), + NewSriovNetworkDeviceValidator(clients.DeviceFactory.Devices().V1beta1().PCIDeviceClaim().Cache()), NewPCIDeviceClaimValidator( - clients.PCIFactory.Devices().V1beta1().PCIDevice().Cache(), + clients.DeviceFactory.Devices().V1beta1().PCIDevice().Cache(), clients.KubevirtFactory.Kubevirt().V1().VirtualMachine().Cache(), - clients.PCIFactory.Devices().V1beta1().USBDeviceClaim().Cache(), + clients.DeviceFactory.Devices().V1beta1().USBDeviceClaim().Cache(), ), NewVGPUValidator(clients.KubevirtFactory.Kubevirt().V1().VirtualMachine().Cache()), NewSRIOVGPUValidator(clients.KubevirtFactory.Kubevirt().V1().VirtualMachine().Cache()), NewUSBDeviceClaimValidator(clients.KubevirtFactory.Kubevirt().V1().VirtualMachine().Cache()), - NewDeviceHostValidation(clients.PCIFactory.Devices().V1beta1().USBDevice().Cache()), + NewDeviceHostValidation(clients.DeviceFactory.Devices().V1beta1().USBDevice().Cache()), NewUSBDeviceValidator(), }