diff --git a/api/v1alpha1/proxmoxmachine_types.go b/api/v1alpha1/proxmoxmachine_types.go index 0c26c8a5..74e8426f 100644 --- a/api/v1alpha1/proxmoxmachine_types.go +++ b/api/v1alpha1/proxmoxmachine_types.go @@ -140,15 +140,17 @@ type Storage struct { // to change the size of the boot volume. // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable" // +optional - BootVolume *DiskSize `json:"bootVolume,omitempty"` + BootVolume *DiskSpec `json:"bootVolume,omitempty"` // TODO Intended to add handling for additional volumes, // which will be added to the node. - // e.g. AdditionalVolumes []DiskSize. + // AdditionalVolumes defines additional volumes to be added to the virtual machine. + // +optional + AdditionalVolumes []DiskSpec `json:"additionalVolumes,omitempty"` } -// DiskSize is contains values for the disk device and size. -type DiskSize struct { +// DiskSpec is contains values for the disk device and size. +type DiskSpec struct { // Disk is the name of the disk device, that should be resized. // Example values are: ide[0-3], scsi[0-30], sata[0-5]. Disk string `json:"disk"` @@ -583,7 +585,7 @@ type ProxmoxMachine struct { Status ProxmoxMachineStatus `json:"status,omitempty"` } -//+kubebuilder:object:root=true +// +kubebuilder:object:root=true // ProxmoxMachineList contains a list of ProxmoxMachine. type ProxmoxMachineList struct { @@ -632,7 +634,7 @@ func (r *ProxmoxMachine) GetNode() string { } // FormatSize returns the format required for the Proxmox API. -func (d *DiskSize) FormatSize() string { +func (d *DiskSpec) FormatSize() string { return fmt.Sprintf("%dG", d.SizeGB) } diff --git a/api/v1alpha1/proxmoxmachine_types_test.go b/api/v1alpha1/proxmoxmachine_types_test.go index e6f14fb5..a741ad74 100644 --- a/api/v1alpha1/proxmoxmachine_types_test.go +++ b/api/v1alpha1/proxmoxmachine_types_test.go @@ -44,7 +44,7 @@ func defaultMachine() *ProxmoxMachine { }, }, Disks: &Storage{ - BootVolume: &DiskSize{ + BootVolume: &DiskSpec{ Disk: "scsi0", SizeGB: 100, }, diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index c1951100..d67de886 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -29,16 +29,16 @@ func (in *AdditionalNetworkDevice) DeepCopy() *AdditionalNetworkDevice { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DiskSize) DeepCopyInto(out *DiskSize) { +func (in *DiskSpec) DeepCopyInto(out *DiskSpec) { *out = *in } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DiskSize. -func (in *DiskSize) DeepCopy() *DiskSize { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DiskSpec. +func (in *DiskSpec) DeepCopy() *DiskSpec { if in == nil { return nil } - out := new(DiskSize) + out := new(DiskSpec) in.DeepCopyInto(out) return out } @@ -933,9 +933,14 @@ func (in *Storage) DeepCopyInto(out *Storage) { *out = *in if in.BootVolume != nil { in, out := &in.BootVolume, &out.BootVolume - *out = new(DiskSize) + *out = new(DiskSpec) **out = **in } + if in.AdditionalVolumes != nil { + in, out := &in.AdditionalVolumes, &out.AdditionalVolumes + *out = make([]DiskSpec, len(*in)) + copy(*out, *in) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Storage. diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxclusters.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxclusters.yaml index c9b8cd25..5f1ef9b2 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxclusters.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxclusters.yaml @@ -105,6 +105,34 @@ spec: Disks contains a set of disk configuration options, which will be applied before the first startup. properties: + additionalVolumes: + description: |- + which will be added to the node. + AdditionalVolumes defines additional volumes to be added to the virtual machine. + items: + description: DiskSpec is contains values for the disk + device and size. + properties: + disk: + description: |- + Disk is the name of the disk device, that should be resized. + Example values are: ide[0-3], scsi[0-30], sata[0-5]. + type: string + sizeGb: + description: |- + Size defines the size in gigabyte. + + As Proxmox does not support shrinking, the size + must be bigger than the already configured size in the + template. + format: int32 + minimum: 5 + type: integer + required: + - disk + - sizeGb + type: object + type: array bootVolume: description: |- BootVolume defines the storage size for the boot volume. diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxclustertemplates.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxclustertemplates.yaml index 544e59d3..87ba398f 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxclustertemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxclustertemplates.yaml @@ -129,6 +129,34 @@ spec: Disks contains a set of disk configuration options, which will be applied before the first startup. properties: + additionalVolumes: + description: |- + which will be added to the node. + AdditionalVolumes defines additional volumes to be added to the virtual machine. + items: + description: DiskSpec is contains values for + the disk device and size. + properties: + disk: + description: |- + Disk is the name of the disk device, that should be resized. + Example values are: ide[0-3], scsi[0-30], sata[0-5]. + type: string + sizeGb: + description: |- + Size defines the size in gigabyte. + + As Proxmox does not support shrinking, the size + must be bigger than the already configured size in the + template. + format: int32 + minimum: 5 + type: integer + required: + - disk + - sizeGb + type: object + type: array bootVolume: description: |- BootVolume defines the storage size for the boot volume. diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxmachines.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxmachines.yaml index ced008b4..4bd9536b 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxmachines.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxmachines.yaml @@ -97,6 +97,34 @@ spec: Disks contains a set of disk configuration options, which will be applied before the first startup. properties: + additionalVolumes: + description: |- + which will be added to the node. + AdditionalVolumes defines additional volumes to be added to the virtual machine. + items: + description: DiskSpec is contains values for the disk device + and size. + properties: + disk: + description: |- + Disk is the name of the disk device, that should be resized. + Example values are: ide[0-3], scsi[0-30], sata[0-5]. + type: string + sizeGb: + description: |- + Size defines the size in gigabyte. + + As Proxmox does not support shrinking, the size + must be bigger than the already configured size in the + template. + format: int32 + minimum: 5 + type: integer + required: + - disk + - sizeGb + type: object + type: array bootVolume: description: |- BootVolume defines the storage size for the boot volume. diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxmachinetemplates.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxmachinetemplates.yaml index baad08fa..aba8017d 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxmachinetemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxmachinetemplates.yaml @@ -109,6 +109,34 @@ spec: Disks contains a set of disk configuration options, which will be applied before the first startup. properties: + additionalVolumes: + description: |- + which will be added to the node. + AdditionalVolumes defines additional volumes to be added to the virtual machine. + items: + description: DiskSpec is contains values for the disk + device and size. + properties: + disk: + description: |- + Disk is the name of the disk device, that should be resized. + Example values are: ide[0-3], scsi[0-30], sata[0-5]. + type: string + sizeGb: + description: |- + Size defines the size in gigabyte. + + As Proxmox does not support shrinking, the size + must be bigger than the already configured size in the + template. + format: int32 + minimum: 5 + type: integer + required: + - disk + - sizeGb + type: object + type: array bootVolume: description: |- BootVolume defines the storage size for the boot volume. diff --git a/internal/service/vmservice/vm_test.go b/internal/service/vmservice/vm_test.go index 18c3baa7..dcb43c37 100644 --- a/internal/service/vmservice/vm_test.go +++ b/internal/service/vmservice/vm_test.go @@ -496,7 +496,7 @@ func TestReconcileVirtualMachineConfigTags(t *testing.T) { func TestReconcileDisks_RunningVM(t *testing.T) { machineScope, _, _ := setupReconcilerTest(t) machineScope.ProxmoxMachine.Spec.Disks = &infrav1alpha1.Storage{ - BootVolume: &infrav1alpha1.DiskSize{Disk: "ide0", SizeGB: 100}, + BootVolume: &infrav1alpha1.DiskSpec{Disk: "ide0", SizeGB: 100}, } machineScope.SetVirtualMachine(newRunningVM()) @@ -506,7 +506,7 @@ func TestReconcileDisks_RunningVM(t *testing.T) { func TestReconcileDisks_ResizeDisk(t *testing.T) { machineScope, proxmoxClient, _ := setupReconcilerTest(t) machineScope.ProxmoxMachine.Spec.Disks = &infrav1alpha1.Storage{ - BootVolume: &infrav1alpha1.DiskSize{Disk: "ide0", SizeGB: 100}, + BootVolume: &infrav1alpha1.DiskSpec{Disk: "ide0", SizeGB: 100}, } vm := newStoppedVM() machineScope.SetVirtualMachine(vm) diff --git a/internal/webhook/proxmoxmachine_webhook_test.go b/internal/webhook/proxmoxmachine_webhook_test.go index c39bf0fa..b1ec8f6c 100644 --- a/internal/webhook/proxmoxmachine_webhook_test.go +++ b/internal/webhook/proxmoxmachine_webhook_test.go @@ -151,7 +151,7 @@ func validProxmoxMachine(name string) infrav1.ProxmoxMachine { NumCores: 1, MemoryMiB: 1024, Disks: &infrav1.Storage{ - BootVolume: &infrav1.DiskSize{ + BootVolume: &infrav1.DiskSpec{ Disk: "scsi[0]", SizeGB: 10, },