Skip to content

Commit

Permalink
Feat: add USB Passthrough (#78)
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Yu <jack.yu@suse.com>
Co-authored-by: Gaurav Mehta <gaurav.mehta@suse.com>
  • Loading branch information
Yu-Jack and ibrokethecloud authored Jul 12, 2024
1 parent 0bf39cf commit 0145a9f
Show file tree
Hide file tree
Showing 90 changed files with 33,479 additions and 114 deletions.
2 changes: 1 addition & 1 deletion Dockerfile.dapper
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ENV ARCH $DAPPER_HOST_ARCH

RUN zypper -n ar https://download.opensuse.org/repositories/hardware/15.5/hardware.repo && \
zypper -n --gpg-auto-import-keys refresh && \
zypper -n install bash git gcc docker vim less file curl wget ca-certificates pciutils umockdev
zypper -n install bash git gcc docker vim less file curl wget ca-certificates pciutils umockdev awk jq
RUN go install golang.org/x/lint/golint@latest
RUN go install golang.org/x/tools/cmd/goimports@latest
RUN go install github.com/incu6us/goimports-reviser/v3@latest
Expand Down
238 changes: 238 additions & 0 deletions charts/templates/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,124 @@ spec:
storage: true
subresources:
status: {}

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: usbdevices.devices.harvesterhci.io
spec:
group: devices.harvesterhci.io
names:
kind: USBDevice
plural: usbdevices
singular: usbdevice
preserveUnknownFields: false
scope: Cluster
versions:
- additionalPrinterColumns:
- jsonPath: .status.vendorID
name: Vendor ID
type: string
- jsonPath: .status.productID
name: Product ID
type: string
- jsonPath: .status.nodeName
name: Node Name
type: string
- jsonPath: .status.description
name: Description
type: string
- jsonPath: .status.resourceName
name: Resource Name
type: string
- jsonPath: .status.pciAddress
name: PCI Address
type: string
- jsonPath: .status.enabled
name: Enabled
type: string
name: v1beta1
schema:
openAPIV3Schema:
properties:
status:
properties:
description:
nullable: true
type: string
devicePath:
nullable: true
type: string
enabled:
type: boolean
nodeName:
nullable: true
type: string
pciAddress:
nullable: true
type: string
productID:
nullable: true
type: string
resourceName:
nullable: true
type: string
vendorID:
nullable: true
type: string
type: object
type: object
served: true
storage: true
subresources:
status: {}

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: usbdeviceclaims.devices.harvesterhci.io
spec:
group: devices.harvesterhci.io
names:
kind: USBDeviceClaim
plural: usbdeviceclaims
singular: usbdeviceclaim
preserveUnknownFields: false
scope: Cluster
versions:
- additionalPrinterColumns:
- jsonPath: .status.nodeName
name: Node Name
type: string
- jsonPath: .status.pciAddress
name: PCI Address
type: string
- jsonPath: .status.userName
name: User Name
type: string
name: v1beta1
schema:
openAPIV3Schema:
properties:
status:
properties:
nodeName:
nullable: true
type: string
pciAddress:
nullable: true
type: string
userName:
nullable: true
type: string
type: object
type: object
served: true
storage: true
subresources:
status: {}
{{- else -}}
---
apiVersion: apiextensions.k8s.io/v1beta1
Expand Down Expand Up @@ -735,4 +853,124 @@ spec:
- name: v1beta1
served: true
storage: true

---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: usbdevices.devices.harvesterhci.io
spec:
additionalPrinterColumns:
- JSONPath: .status.vendorID
name: Vendor ID
type: string
- JSONPath: .status.productID
name: Product ID
type: string
- JSONPath: .status.nodeName
name: Node Name
type: string
- JSONPath: .status.description
name: Description
type: string
- JSONPath: .status.resourceName
name: Resource Name
type: string
- JSONPath: .status.pciAddress
name: PCI Address
type: string
- JSONPath: .status.enabled
name: Enabled
type: string
group: devices.harvesterhci.io
names:
kind: USBDevice
plural: usbdevices
singular: usbdevice
preserveUnknownFields: false
scope: Cluster
subresources:
status: {}
validation:
openAPIV3Schema:
properties:
status:
properties:
description:
nullable: true
type: string
devicePath:
nullable: true
type: string
enabled:
type: boolean
nodeName:
nullable: true
type: string
pciAddress:
nullable: true
type: string
productID:
nullable: true
type: string
resourceName:
nullable: true
type: string
vendorID:
nullable: true
type: string
type: object
type: object
version: v1beta1
versions:
- name: v1beta1
served: true
storage: true

---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: usbdeviceclaims.devices.harvesterhci.io
spec:
additionalPrinterColumns:
- JSONPath: .status.nodeName
name: Node Name
type: string
- JSONPath: .status.pciAddress
name: PCI Address
type: string
- JSONPath: .status.userName
name: User Name
type: string
group: devices.harvesterhci.io
names:
kind: USBDeviceClaim
plural: usbdeviceclaims
singular: usbdeviceclaim
preserveUnknownFields: false
scope: Cluster
subresources:
status: {}
validation:
openAPIV3Schema:
properties:
status:
properties:
nodeName:
nullable: true
type: string
pciAddress:
nullable: true
type: string
userName:
nullable: true
type: string
type: object
type: object
version: v1beta1
versions:
- name: v1beta1
served: true
storage: true
{{- end -}}
1 change: 1 addition & 0 deletions generate.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//go:generate go run pkg/codegen/cleanup/main.go
//go:generate go run pkg/codegen/main.go
//go:generate go run ./pkg/codegen crds ./charts/templates/crds.yaml
//go:generate go run pkg/util/gousb/codegen/main.go -template pkg/util/gousb/codegen/load_data.go.tpl -o pkg/util/gousb/usbid/load_data.go

package main
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"os"

harvesternetworkv1beta1 "github.com/harvester/harvester-network-controller/pkg/apis/network.harvesterhci.io/v1beta1"
"github.com/rancher/wrangler/pkg/kubeconfig"
"github.com/rancher/wrangler/pkg/schemes"
"github.com/rancher/wrangler/pkg/signals"
Expand All @@ -16,6 +15,8 @@ import (
apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1"
kubevirtv1 "kubevirt.io/api/core/v1"

harvesternetworkv1beta1 "github.com/harvester/harvester-network-controller/pkg/apis/network.harvesterhci.io/v1beta1"

"github.com/harvester/pcidevices/pkg/apis/devices.harvesterhci.io/v1beta1"
"github.com/harvester/pcidevices/pkg/controller"
)
Expand Down
26 changes: 26 additions & 0 deletions pkg/apis/devices.harvesterhci.io/v1beta1/usb_device.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package v1beta1

import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

// +genclient
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true

type USBDevice struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Status USBDeviceStatus `json:"status,omitempty"`
}

type USBDeviceStatus struct {
VendorID string `json:"vendorID"`
ProductID string `json:"productID"`
NodeName string `json:"nodeName"`
ResourceName string `json:"resourceName"`
DevicePath string `json:"devicePath"`
Description string `json:"description"`
PCIAddress string `json:"pciAddress"`
Enabled bool `json:"enabled"`
}
25 changes: 25 additions & 0 deletions pkg/apis/devices.harvesterhci.io/v1beta1/usb_device_claim.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package v1beta1

import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

// +genclient
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true

type USBDeviceClaim struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Status USBDeviceClaimStatus `json:"status,omitempty"`
}

type USBDeviceClaimStatus struct {
NodeName string `json:"nodeName"`
PCIAddress string `json:"pciAddress"`
UserName string `json:"userName"`
}

const (
USBDevicePCIAddress = "usb-device-pci-address"
)
Loading

0 comments on commit 0145a9f

Please sign in to comment.