Skip to content

Commit 7831d06

Browse files
committed
add cpu/memory option to proxmoxmachine spec
1 parent 6c01769 commit 7831d06

File tree

9 files changed

+75
-8
lines changed

9 files changed

+75
-8
lines changed

api/v1beta1/proxmoxmachine_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ type ProxmoxMachineSpec struct {
4646
// +optional
4747
CloudInit CloudInit `json:"cloudInit,omitempty"`
4848

49+
// Hardware
50+
Hardware Hardware `json:"hardware,omitempty"`
51+
4952
// Network
5053
Network Network `json:"network,omitempty"`
5154

api/v1beta1/type.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,19 @@ type ObjectReference struct {
3030
// ChecksumType *string `json:"checksumType,omitempty"`
3131
// }
3232

33+
// Hardware
34+
type Hardware struct {
35+
// number of CPU cores : 1 ~
36+
// +kubebuilder:validation:Mimimum:=1
37+
// +kubebuilder:default:=2
38+
CPU int `json:"cpu,omitempty"`
39+
40+
// amount of RAM for the VM in MiB : 16 ~
41+
// +kubebuilder:validation:Minimum:=16
42+
// +kubebuilder:default:=4096
43+
Memory int `json:"memoty,omitempty"`
44+
}
45+
3346
// Network
3447
// cloud-init network configuration is configured through Proxmox API
3548
// it may be migrated to raw yaml way from Proxmox API way in the future
@@ -71,7 +84,7 @@ func (i *IPConfig) String() string {
7184

7285
// Storage for image and snippets
7386
type Storage struct {
74-
Name string `json:"name"`
87+
Name string `json:"name,omitempty"`
7588
Path string `json:"path,omitempty"`
7689
}
7790

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cloud/interfaces.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ type MachineGetter interface {
6161
GetStorage() infrav1.Storage
6262
GetCloudInit() infrav1.CloudInit
6363
GetNetwork() infrav1.Network
64+
GetHardware() infrav1.Hardware
6465
}
6566

6667
// MachineSetter is an interface which can set machine information.

cloud/scope/machine.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,17 @@ func (m *MachineScope) GetNetwork() infrav1.Network {
159159
return m.ProxmoxMachine.Spec.Network
160160
}
161161

162+
func (m *MachineScope) GetHardware() infrav1.Hardware {
163+
// set default value if empty
164+
if m.ProxmoxMachine.Spec.Hardware.CPU == 0 {
165+
m.ProxmoxMachine.Spec.Hardware.CPU = 2
166+
}
167+
if m.ProxmoxMachine.Spec.Hardware.Memory == 0 {
168+
m.ProxmoxMachine.Spec.Hardware.Memory = 4096
169+
}
170+
return m.ProxmoxMachine.Spec.Hardware
171+
}
172+
162173
// SetProviderID sets the ProxmoxMachine providerID in spec.
163174
func (m *MachineScope) SetProviderID(instance *vm.VirtualMachine) error {
164175
providerid, err := providerid.New(instance.Node.Name(), instance.VMID)

cloud/services/compute/instance/reconcile.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (s *Service) CreateInstance(ctx context.Context, bootstrap string) (*vm.Vir
114114
}
115115

116116
// create vm
117-
vmoption := generateVMOptions(s.scope.Name(), s.scope.GetStorage().Name, s.scope.GetNetwork())
117+
vmoption := generateVMOptions(s.scope.Name(), s.scope.GetStorage().Name, s.scope.GetNetwork(), s.scope.GetHardware())
118118
vm, err := node.CreateVirtualMachine(vmid, vmoption)
119119
if err != nil {
120120
log.Error(err, "failed to create virtual machine")
@@ -210,12 +210,11 @@ func SetCloudImage(ctx context.Context, vmid int, storageName string, ssh scope.
210210
return nil
211211
}
212212

213-
func generateVMOptions(vmName, storageName string, network infrav1.Network) vm.VirtualMachineCreateOptions {
214-
213+
func generateVMOptions(vmName, storageName string, network infrav1.Network, hardware infrav1.Hardware) vm.VirtualMachineCreateOptions {
215214
vmoptions := vm.VirtualMachineCreateOptions{
216215
Agent: "enabled=1",
217-
Cores: 2,
218-
Memory: 1024 * 4,
216+
Cores: hardware.CPU,
217+
Memory: hardware.Memory,
219218
Name: vmName,
220219
NameServer: network.NameServer,
221220
Boot: "order=scsi0",

config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxclusters.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ spec:
7878
type: string
7979
path:
8080
type: string
81-
required:
82-
- name
8381
type: object
8482
required:
8583
- credentialsRef

config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxmachines.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,19 @@ spec:
6464
Zone. If multiple subnets are matched for the availability zone,
6565
the first one returned is picked.
6666
type: string
67+
hardware:
68+
description: Hardware
69+
properties:
70+
cpu:
71+
default: 2
72+
description: 'number of CPU cores : 1 ~'
73+
type: integer
74+
memoty:
75+
default: 4096
76+
description: 'amount of RAM for the VM in MiB : 16 ~'
77+
minimum: 16
78+
type: integer
79+
type: object
6780
network:
6881
description: Network
6982
properties:

config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxmachinetemplates.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,19 @@ spec:
102102
to an AWS Availability Zone. If multiple subnets are matched
103103
for the availability zone, the first one returned is picked.
104104
type: string
105+
hardware:
106+
description: Hardware
107+
properties:
108+
cpu:
109+
default: 2
110+
description: 'number of CPU cores : 1 ~'
111+
type: integer
112+
memoty:
113+
default: 4096
114+
description: 'amount of RAM for the VM in MiB : 16 ~'
115+
minimum: 16
116+
type: integer
117+
type: object
105118
network:
106119
description: Network
107120
properties:

0 commit comments

Comments
 (0)