Skip to content

Commit

Permalink
feat: Add PCI device support for virtual machine
Browse files Browse the repository at this point in the history
  • Loading branch information
alperencelik committed Nov 19, 2024
1 parent 4880f68 commit 83b2c99
Show file tree
Hide file tree
Showing 9 changed files with 349 additions and 99 deletions.
18 changes: 18 additions & 0 deletions api/proxmox/v1alpha1/virtualmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,24 @@ type VirtualMachineSpecTemplate struct {
Disk []VirtualMachineSpecTemplateDisk `json:"disk,omitempty"`
// Networks is the list of networks
Network []VirtualMachineSpecTemplateNetwork `json:"network,omitempty"`
// PCI is the list of PCI devices
PciDevices []PciDevice `json:"pciDevices,omitempty"`
}

type PciDevice struct {
// DeviceID is the ID hex id of the device
DeviceID string `json:"deviceID,omitempty"`
// PrimaryGPU is the flag that indicates whether the device is the primary GPU ==> x-vga=1
// +kubebuilder:default:=false
PrimaryGPU bool `json:"primaryGPU,omitempty"`
// PCIE is the flag that indicates whether the device is a PCIE device ==> pcie=1
// +kubebuilder:default:=false
PCIE bool `json:"pcie,omitempty"`
// TODO: Add more fields
// MappingID is the ID of the mapping ==> mapping
// MappingID string `json:"mappingID,omitempty"`
// // MDevType is the type of the mapping device ==> mdev
// MDevType string `json:"mDevType,omitempty"`
}

type VirtualMachineSpecTemplateDisk struct {
Expand Down
20 changes: 20 additions & 0 deletions api/proxmox/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ func main() {
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
opts := zap.Options{
Development: true,
}

opts := zap.Options{}
opts.BindFlags(flag.CommandLine)
flag.Parse()

Expand Down
19 changes: 19 additions & 0 deletions config/crd/bases/proxmox.alperen.cloud_virtualmachines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,25 @@ spec:
- model
type: object
type: array
pciDevices:
description: PCI is the list of PCI devices
items:
properties:
deviceID:
description: DeviceID is the ID hex id of the device
type: string
pcie:
default: false
description: PCIE is the flag that indicates whether the
device is a PCIE device ==> pcie=1
type: boolean
primaryGPU:
default: false
description: PrimaryGPU is the flag that indicates whether
the device is the primary GPU ==> x-vga=1
type: boolean
type: object
type: array
socket:
description: Socket is the number of CPU sockets
type: integer
Expand Down
19 changes: 19 additions & 0 deletions config/crd/bases/proxmox.alperen.cloud_virtualmachinesets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,25 @@ spec:
- model
type: object
type: array
pciDevices:
description: PCI is the list of PCI devices
items:
properties:
deviceID:
description: DeviceID is the ID hex id of the device
type: string
pcie:
default: false
description: PCIE is the flag that indicates whether the
device is a PCIE device ==> pcie=1
type: boolean
primaryGPU:
default: false
description: PrimaryGPU is the flag that indicates whether
the device is the primary GPU ==> x-vga=1
type: boolean
type: object
type: array
socket:
description: Socket is the number of CPU sockets
type: integer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,16 @@ func (r *ManagedVirtualMachineReconciler) handleManagedVMCreation(ctx context.Co
logger.Info(fmt.Sprintf("ManagedVM %v does not exist so creating it", managedVM))
managedVM := proxmox.CreateManagedVM(managedVM)
err := r.Create(context.Background(), managedVM)
r.Recorder.Event(managedVM, "Normal", "Creating", fmt.Sprintf("Creating ManagedVirtualMachine %s", managedVM.Name))
if err != nil {
logger.Info(fmt.Sprintf("ManagedVM %v could not be created", managedVM.Name))
return err
}
// Add metrics
// Add metrics and events
metrics.SetManagedVirtualMachineCPUCores(managedVM.Name, managedVM.Namespace, float64(managedVM.Spec.Cores))
metrics.SetManagedVirtualMachineMemory(managedVM.Name, managedVM.Namespace, float64(managedVM.Spec.Memory))
metrics.IncManagedVirtualMachineCount()
r.Recorder.Event(managedVM, "Normal", "Created", fmt.Sprintf("ManagedVirtualMachine %s created", managedVM.Name))
} else {
logger.Info(fmt.Sprintf("ManagedVM %v already exists", managedVM))
}
Expand Down
1 change: 0 additions & 1 deletion pkg/kubernetes/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func ClientConfig() any {
} else {
kubeconfig = flag.String("kubeconfig", "", "absolute path to the kubeconfig file")
}
flag.Parse()
config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)
if err != nil {
panic(err.Error())
Expand Down
1 change: 0 additions & 1 deletion pkg/proxmox/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ func DeleteStorageContent(storageName string, spec *proxmoxv1alpha1.StorageDownl
}
storage, _ := Node.Storage(ctx, storageName)
// Delete storage content
// local:iso/talos-amd64.iso
objectName := fmt.Sprintf("%s:%s/%s", storageName, spec.Content, spec.Filename)
task, err := storage.DeleteContent(ctx, objectName)
if err != nil {
Expand Down
Loading

0 comments on commit 83b2c99

Please sign in to comment.