Skip to content

Commit 18f3786

Browse files
authored
Merge pull request #61 from sp-yduck/feature/vmoptions
Feature/vmoptions
2 parents 56fead8 + f0104c2 commit 18f3786

14 files changed

+834
-71
lines changed

api/v1beta1/options_types.go

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
package v1beta1
2+
3+
import "strconv"
4+
5+
// import "encoding/json"
6+
7+
// +kubebuilder:validation:Enum:=x86_64;aarch64
8+
type Arch string
9+
10+
// +kubebuilder:validation:Enum:=seabios;ovmf
11+
type BIOS string
12+
13+
// +kubebuilder:validation:Enum:=0;2;1024
14+
type HugePages int
15+
16+
// +kubebuilder:validation:Enum:=backup;clone;create;migrate;rollback;snapshot;snapshot-delete;suspending;suspended
17+
type Lock string
18+
19+
// +kubebuilder:validation:Enum:=other;wxp;w2k;w2k3;w2k8;wvista;win7;win8;win10;win11;l24;l26;solaris
20+
type OSType string
21+
22+
// +kubebuilder:validation:Pattern:="[a-zA-Z0-9-_.;]+"
23+
type Tag string
24+
25+
type Tags []Tag
26+
27+
func (h *HugePages) String() string {
28+
if h == nil {
29+
return ""
30+
} else if *h == 0 {
31+
return "any"
32+
}
33+
return strconv.Itoa(int(*h))
34+
}
35+
36+
func (t *Tags) String() string {
37+
var tags string
38+
for _, tag := range *t {
39+
tags += string(tag) + ";"
40+
}
41+
return tags
42+
}
43+
44+
// Options
45+
type Options struct {
46+
// Enable/Disable ACPI. Defaults to true.
47+
ACPI bool `json:"acpi,omitempty"`
48+
49+
// Virtual processor architecture. Defaults to the host. x86_64 or aarch64.
50+
Arch Arch `json:"arch,omitempty"`
51+
52+
// +kubebuilder:validation:Minimum:=0
53+
// Amount of target RAM for the VM in MiB. Using zero disables the ballon driver.
54+
Balloon int `json:"balloon,omitempty"`
55+
56+
// Description for the VM. Shown in the web-interface VM's summary.
57+
// This is saved as comment inside the configuration file.
58+
Description string `json:"description,omitempty"`
59+
60+
// Script that will be executed during various steps in the vms lifetime.
61+
// HookScripts []Hookscript `json:"hookScripts,omitempty"`
62+
63+
// enable hotplug feature. list og devices.
64+
// network, disk, cpu, memory, usb. Defaults to [network, disk, usb].
65+
// HotPlug []HotPlugDevice `json:"hotPlug,omitempty"`
66+
67+
// enable/disable hugepages memory. 0 or 2 or 1024. 0 indicated 'any'
68+
HugePages *HugePages `json:"hugePages,omitempty"`
69+
70+
// Use together with hugepages. If enabled, hugepages will not not be deleted
71+
// after VM shutdown and can be used for subsequent starts. Defaults to false.
72+
KeepHugePages bool `json:"keepHugePages,omitempty"`
73+
74+
// Enable/disable KVM hardware virtualization. Defaults to true.
75+
KVM bool `json:"kvm,omitempty"`
76+
77+
// Set the real time clock (RTC) to local time.
78+
// This is enabled by default if the `ostype` indicates a Microsoft Windows OS.
79+
LocalTime bool `json:"localTime,omitempty"`
80+
81+
// Lock/unlock the VM.
82+
Lock Lock `json:"lock,omitempty"`
83+
84+
// Set maximum tolerated downtime (in seconds) for migrations.
85+
// MigrateDowntime json.Number `json:"migrateDowntime,omitempty"`
86+
87+
// Set maximum speed (in MB/s) for migrations. Value 0 is no limit.
88+
// MigrateSpeed `json:"migrateSpeed,omitempty"`
89+
90+
// Enable/disable NUMA.
91+
NUMA bool `json:"numa,omitempty"`
92+
93+
// Specifies whether a VM will be started during system bootup.
94+
OnBoot bool `json:"onBoot,omitempty"`
95+
96+
// Specify guest operating system. This is used to enable special
97+
// optimization/features for specific operating systems.
98+
OSType OSType `json:"osType,omitempty"`
99+
100+
// Sets the protection flag of the VM.
101+
// This will disable the remove VM and remove disk operations.
102+
// Defaults to false.
103+
Protection bool `json:"protection,omitempty"`
104+
105+
// Allow reboot. If set to 'false' the VM exit on reboot.
106+
// Defaults to true.
107+
Reboot bool `json:"reboot,omitempty"`
108+
109+
// +kubebuilder:validation:Minimum:=0
110+
// +kubebuilder:validation:Maximum:=5000
111+
// Amount of memory shares for auto-ballooning. The larger the number is, the more memory this VM gets.
112+
// Number is relative to weights of all other running VMs. Using zero disables auto-ballooning.
113+
// Auto-ballooning is done by pvestatd. 0 ~ 5000. Defaults to 1000.
114+
Shares int `json:"shares,omitempty"`
115+
116+
// Set the initial date of the real time clock.
117+
// Valid format for date are:'now' or '2006-06-17T16:01:21' or '2006-06-17'.
118+
// Defaults to 'now'.
119+
// StartDate string `json:"startDate,omitempty"`
120+
121+
// StartUp string `json:"startUp,omitempty`
122+
123+
// Enable/disable the USB tablet device. This device is usually needed to allow
124+
// absolute mouse positioning with VNC. Else the mouse runs out of sync with normal VNC clients.
125+
// If you're running lots of console-only guests on one host,
126+
// you may consider disabling this to save some context switches.
127+
// This is turned off by default if you use spice (`qm set <vmid> --vga qxl`).
128+
// Defaults to true.
129+
Tablet bool `json:"tablet,omitempty"`
130+
131+
// Tags of the VM. This is only meta information.
132+
Tags Tags `json:"tags,omitempty"`
133+
134+
// Enable/disable time drift fix. Defaults to false.
135+
TimeDriftFix bool `json:"timeDriftFix,omitempty"`
136+
137+
// Enable/disable Template. Defaults to false.
138+
Template bool `json:"template,omitempty"`
139+
140+
// TPMState string `json:"tpmState,omitempty"`
141+
142+
// +kubebuilder:validation:Minimum:=0
143+
// Number of hotplugged vcpus. Defaults to 0.
144+
VCPUs int `json:"vcpus,omitempty"`
145+
146+
// VGA string `json:"vga,omitempty"`
147+
148+
// +kubebuilder:validation:Pattern:="(?:[a-fA-F0-9]{8}(?:-[a-fA-F0-9]{4}){3}-[a-fA-F0-9]{12}|[01])"
149+
// The VM generation ID (vmgenid) device exposes a 128-bit integer value identifier to the guest OS.
150+
// This allows to notify the guest operating system when the virtual machine is executed with a different configuration
151+
// (e.g. snapshot execution or creation from a template).
152+
// The guest operating system notices the change, and is then able to react as appropriate by marking its copies of distributed databases as dirty,
153+
// re-initializing its random number generator, etc.
154+
// Note that auto-creation only works when done through API/CLI create or update methods, but not when manually editing the config file.
155+
// regex: (?:[a-fA-F0-9]{8}(?:-[a-fA-F0-9]{4}){3}-[a-fA-F0-9]{12}|[01]). Defaults to 1 (autogenerated)
156+
VMGenerationID string `json:"vmGenerationID,omitempty"`
157+
158+
// Default storage for VM state volumes/files.
159+
// VMStateStorage string `json:"vmStateStorage,omitempty"`
160+
161+
// Create a virtual hardware watchdog device. Once enabled (by a guest action),
162+
// the watchdog must be periodically polled by an agent inside the guest or else
163+
// the watchdog will reset the guest (or execute the respective action specified)
164+
// WatchDog string `json:"watchDog,omitempty"`
165+
}

api/v1beta1/proxmoxcluster_types.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ import (
2121
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2222
)
2323

24-
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
25-
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
26-
2724
const (
2825
// ClusterFinalizer
2926
ClusterFinalizer = "proxmoxcluster.infrastructure.cluster.x-k8s.io"

api/v1beta1/proxmoxmachine_types.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,19 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20+
"github.com/sp-yduck/proxmox-go/api"
2021
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2122
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2223
"sigs.k8s.io/cluster-api/errors"
2324
)
2425

25-
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
26-
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
27-
2826
const (
2927
// MachineFinalizer
3028
MachineFinalizer = "proxmoxmachine.infrastructure.cluster.x-k8s.io"
3129
)
3230

3331
// ProxmoxMachineSpec defines the desired state of ProxmoxMachine
3432
type ProxmoxMachineSpec struct {
35-
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
36-
// Important: Run "make" to regenerate code after modifying this file
37-
3833
// ProviderID
3934
ProviderID *string `json:"providerID,omitempty"`
4035

@@ -60,9 +55,11 @@ type ProxmoxMachineSpec struct {
6055
// Network
6156
Network Network `json:"network,omitempty"`
6257

58+
// Options
59+
// +optional
60+
Options Options `json:"options,omitempty"`
61+
6362
// FailureDomain is the failure domain unique identifier this Machine should be attached to, as defined in Cluster API.
64-
// For this infrastructure provider, the ID is equivalent to an AWS Availability Zone.
65-
// If multiple subnets are matched for the availability zone, the first one returned is picked.
6663
FailureDomain *string `json:"failureDomain,omitempty"`
6764
}
6865

@@ -84,7 +81,10 @@ type ProxmoxMachineStatus struct {
8481
// Conditions
8582
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
8683

87-
// InstanceStatus is the status of the GCP instance for this machine.
84+
// Configuration
85+
Config api.VirtualMachineConfig `json:"config,omitempty"`
86+
87+
// InstanceStatus is the status of the proxmox instance for this machine.
8888
// +optional
8989
InstanceStatus *InstanceStatus `json:"instanceStatus,omitempty"` // InstanceStatus
9090
}

api/v1beta1/type.go

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,12 @@ type ServerRef struct {
2222
SecretRef *ObjectReference `json:"secretRef"`
2323
}
2424

25-
// NodeRef
26-
type NodeRef struct {
27-
Name string `json:"name"`
28-
SecretRef *ObjectReference `json:"secretRef"`
29-
}
30-
3125
// ObjectReference is a reference to another Kubernetes object instance.
3226
type ObjectReference struct {
3327
// Namespace of the referent.
3428
// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/
3529
Namespace string `json:"namespace,omitempty"`
30+
3631
// Name of the referent.
3732
// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
3833
// +kubebuilder:validation:Required
@@ -53,15 +48,38 @@ type Image struct {
5348

5449
// Hardware
5550
type Hardware struct {
51+
// amount of RAM for the VM in MiB : 16 ~
52+
// +kubebuilder:validation:Minimum:=16
53+
// +kubebuilder:default:=4096
54+
Memory int `json:"memory,omitempty"`
55+
5656
// number of CPU cores : 1 ~
5757
// +kubebuilder:validation:Mimimum:=1
5858
// +kubebuilder:default:=2
5959
CPU int `json:"cpu,omitempty"`
6060

61-
// amount of RAM for the VM in MiB : 16 ~
62-
// +kubebuilder:validation:Minimum:=16
63-
// +kubebuilder:default:=4096
64-
Memory int `json:"memory,omitempty"`
61+
// emulated cpu type
62+
// CPUType string `json:"cpuType,omitempty"`
63+
64+
// +kubebuilder:validation:Minimum:=1
65+
// The number of CPU sockets. Defaults to 1.
66+
Sockets int `json:"sockets,omitempty"`
67+
68+
// +kubebuilder:validation:Minimum:=0
69+
// Limit of CPU usage. If the computer has 2 CPUs, it has total of '2' CPU time.
70+
// Value '0' indicates no CPU limit. Defaults to 0.
71+
CPULimit int `json:"cpuLimit,omitempty"`
72+
73+
// Select BIOS implementation. Defaults to seabios. seabios or ovmf.
74+
// Defaults to seabios.
75+
BIOS BIOS `json:"bios,omitempty"`
76+
77+
// Specifies the QEMU machine type.
78+
// regex: (pc|pc(-i440fx)?-\d+(\.\d+)+(\+pve\d+)?(\.pxe)?|q35|pc-q35-\d+(\.\d+)+(\+pve\d+)?(\.pxe)?|virt(?:-\d+(\.\d+)+)?(\+pve\d+)?)
79+
// Machine string `json:"machine,omitempty"`
80+
81+
// SCSI controller model
82+
// SCSIHardWare SCSIHardWare `json:"scsiHardWare,omitempty"`
6583

6684
// hard disk size
6785
// +kubebuilder:default:="50G"
@@ -86,10 +104,13 @@ type Network struct {
86104
type IPConfig struct {
87105
// IPv4 with CIDR
88106
IP string `json:"ip,omitempty"`
107+
89108
// gateway IPv4
90109
Gateway string `json:"gateway,omitempty"`
110+
91111
// IPv6 with CIDR
92112
IP6 string `json:"ip6,omitempty"`
113+
93114
// gateway IPv6
94115
Gateway6 string `json:"gateway6,omitempty"`
95116
}

0 commit comments

Comments
 (0)