Skip to content

Commit

Permalink
refactor: rename pcifactory to devicefactory
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 May 22, 2024
1 parent ec0faa1 commit a1b9beb
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 35 deletions.
20 changes: 10 additions & 10 deletions pkg/controller/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})

Expand All @@ -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)
Expand Down Expand Up @@ -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)
}

Expand Down
10 changes: 5 additions & 5 deletions pkg/controller/usbdevice/usbdevice_claim_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions pkg/controller/usbdevice/usbdevice_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions pkg/webhook/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ 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 {
clients.Clients
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) {
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
4 changes: 2 additions & 2 deletions pkg/webhook/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
13 changes: 7 additions & 6 deletions pkg/webhook/mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions pkg/webhook/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}

Expand Down

0 comments on commit a1b9beb

Please sign in to comment.