Skip to content

Commit 4c59fe7

Browse files
Add flags to allow customization of CPU and memory shares, reservations and limits
Signed-off-by: Tommaso <[email protected]>
1 parent 7cac247 commit 4c59fe7

10 files changed

+374
-0
lines changed

apis/v1alpha3/vspheremachine_conversion.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func (src *VSphereMachine) ConvertTo(dstRaw conversion.Hub) error {
3636
return err
3737
}
3838

39+
dst.Spec.Resources = restored.Spec.Resources
3940
dst.Spec.AdditionalDisksGiB = restored.Spec.AdditionalDisksGiB
4041
dst.Spec.TagIDs = restored.Spec.TagIDs
4142
dst.Spec.PowerOffMode = restored.Spec.PowerOffMode

apis/v1alpha3/zz_generated.conversion.go

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

apis/v1alpha4/vspheremachine_conversion.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func (src *VSphereMachine) ConvertTo(dstRaw conversion.Hub) error {
3636
return err
3737
}
3838

39+
dst.Spec.Resources = restored.Spec.Resources
3940
dst.Spec.AdditionalDisksGiB = restored.Spec.AdditionalDisksGiB
4041
dst.Spec.TagIDs = restored.Spec.TagIDs
4142
dst.Spec.PowerOffMode = restored.Spec.PowerOffMode

apis/v1alpha4/zz_generated.conversion.go

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

apis/v1beta1/types.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121

2222
corev1 "k8s.io/api/core/v1"
23+
"k8s.io/apimachinery/pkg/api/resource"
2324
clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
2425
)
2526

@@ -167,6 +168,12 @@ type VirtualMachineCloneSpec struct {
167168
// virtual machine is cloned.
168169
// +optional
169170
NumCoresPerSocket int32 `json:"numCoresPerSocket,omitempty"`
171+
172+
// resources is the definition of the VM's cpu and memory
173+
// reservations, limits and shares.
174+
// +optional
175+
Resources VirtualMachineResources `json:"resources,omitempty,omitzero"`
176+
170177
// MemoryMiB is the size of a virtual machine's memory, in MiB.
171178
// Defaults to the eponymous property value in the template from which the
172179
// virtual machine is cloned.
@@ -211,6 +218,51 @@ type VirtualMachineCloneSpec struct {
211218
DataDisks []VSphereDisk `json:"dataDisks,omitempty"`
212219
}
213220

221+
// VirtualMachineResources is the definition of the VM's cpu and memory
222+
// reservations, limits and shares.
223+
// +kubebuilder:validation:MinProperties=1
224+
type VirtualMachineResources struct {
225+
// requests is the definition of the VM's cpu (in hertz, rounded up to the nearest MHz)
226+
// and memory (in bytes, rounded up to the nearest MiB) reservations
227+
// +optional
228+
Requests VirtualMachineResourceSpec `json:"requests,omitempty,omitzero"`
229+
// limits is the definition of the VM's cpu (in hertz, rounded up to the nearest MHz)
230+
// and memory (in bytes, rounded up to the nearest MiB) limits
231+
// +optional
232+
Limits VirtualMachineResourceSpec `json:"limits,omitempty,omitzero"`
233+
// shares is the definition of the VM's cpu and memory shares
234+
// +optional
235+
Shares VirtualMachineResourceShares `json:"shares,omitempty,omitzero"`
236+
}
237+
238+
// VirtualMachineResourceSpec is the numerical definition of memory and cpu quantity for the
239+
// given VM hardware policy.
240+
// +kubebuilder:validation:MinProperties=1
241+
type VirtualMachineResourceSpec struct {
242+
// cpu is the definition of the cpu quantity for the given VM hardware policy
243+
// +optional
244+
Cpu resource.Quantity `json:"cpu,omitempty"` //nolint:revive
245+
246+
// memory is the definition of the memory quantity for the given VM hardware policy
247+
// +optional
248+
Memory resource.Quantity `json:"memory,omitempty"`
249+
}
250+
251+
// VirtualMachineResourceShares is the numerical definition of memory and cpu shares for the
252+
// given VM
253+
// +kubebuilder:validation:MinProperties=1
254+
type VirtualMachineResourceShares struct {
255+
// cpu is the number of spu shares to assign to the VM
256+
// +kubebuilder:validation:Minimum=1
257+
// +optional
258+
Cpu int32 `json:"cpu,omitempty"`
259+
260+
// memory is the number of memory shares to assign to the VM
261+
// +kubebuilder:validation:Minimum=1
262+
// +optional
263+
Memory int32 `json:"memory,omitempty"`
264+
}
265+
214266
// VSphereDisk is an additional disk to add to the VM that is not part of the VM OVA template.
215267
type VSphereDisk struct {
216268
// Name is used to identify the disk definition. Name is required and needs to be unique so that it can be used to

apis/v1beta1/zz_generated.deepcopy.go

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

config/default/crd/bases/infrastructure.cluster.x-k8s.io_vspheremachines.yaml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,77 @@ spec:
14591459
ResourcePool is the name, inventory path, managed object reference or the managed
14601460
object ID in which the virtual machine is created/located.
14611461
type: string
1462+
resources:
1463+
description: |-
1464+
resources is the definition of the VM's cpu and memory
1465+
reservations, limits and shares.
1466+
minProperties: 1
1467+
properties:
1468+
limits:
1469+
description: |-
1470+
limits is the definition of the VM's cpu (in hertz, rounded up to the nearest MHz)
1471+
and memory (in bytes, rounded up to the nearest MiB) limits
1472+
minProperties: 1
1473+
properties:
1474+
cpu:
1475+
anyOf:
1476+
- type: integer
1477+
- type: string
1478+
description: cpu is the definition of the cpu quantity for
1479+
the given VM hardware policy
1480+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
1481+
x-kubernetes-int-or-string: true
1482+
memory:
1483+
anyOf:
1484+
- type: integer
1485+
- type: string
1486+
description: memory is the definition of the memory quantity
1487+
for the given VM hardware policy
1488+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
1489+
x-kubernetes-int-or-string: true
1490+
type: object
1491+
requests:
1492+
description: |-
1493+
requests is the definition of the VM's cpu (in hertz, rounded up to the nearest MHz)
1494+
and memory (in bytes, rounded up to the nearest MiB) reservations
1495+
minProperties: 1
1496+
properties:
1497+
cpu:
1498+
anyOf:
1499+
- type: integer
1500+
- type: string
1501+
description: cpu is the definition of the cpu quantity for
1502+
the given VM hardware policy
1503+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
1504+
x-kubernetes-int-or-string: true
1505+
memory:
1506+
anyOf:
1507+
- type: integer
1508+
- type: string
1509+
description: memory is the definition of the memory quantity
1510+
for the given VM hardware policy
1511+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
1512+
x-kubernetes-int-or-string: true
1513+
type: object
1514+
shares:
1515+
description: shares is the definition of the VM's cpu and memory
1516+
shares
1517+
minProperties: 1
1518+
properties:
1519+
cpu:
1520+
description: cpu is the number of spu shares to assign to
1521+
the VM
1522+
format: int32
1523+
minimum: 1
1524+
type: integer
1525+
memory:
1526+
description: memory is the number of memory shares to assign
1527+
to the VM
1528+
format: int32
1529+
minimum: 1
1530+
type: integer
1531+
type: object
1532+
type: object
14621533
server:
14631534
description: |-
14641535
Server is the IP address or FQDN of the vSphere server on which

config/default/crd/bases/infrastructure.cluster.x-k8s.io_vspheremachinetemplates.yaml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,77 @@ spec:
13351335
ResourcePool is the name, inventory path, managed object reference or the managed
13361336
object ID in which the virtual machine is created/located.
13371337
type: string
1338+
resources:
1339+
description: |-
1340+
resources is the definition of the VM's cpu and memory
1341+
reservations, limits and shares.
1342+
minProperties: 1
1343+
properties:
1344+
limits:
1345+
description: |-
1346+
limits is the definition of the VM's cpu (in hertz, rounded up to the nearest MHz)
1347+
and memory (in bytes, rounded up to the nearest MiB) limits
1348+
minProperties: 1
1349+
properties:
1350+
cpu:
1351+
anyOf:
1352+
- type: integer
1353+
- type: string
1354+
description: cpu is the definition of the cpu quantity
1355+
for the given VM hardware policy
1356+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
1357+
x-kubernetes-int-or-string: true
1358+
memory:
1359+
anyOf:
1360+
- type: integer
1361+
- type: string
1362+
description: memory is the definition of the memory
1363+
quantity for the given VM hardware policy
1364+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
1365+
x-kubernetes-int-or-string: true
1366+
type: object
1367+
requests:
1368+
description: |-
1369+
requests is the definition of the VM's cpu (in hertz, rounded up to the nearest MHz)
1370+
and memory (in bytes, rounded up to the nearest MiB) reservations
1371+
minProperties: 1
1372+
properties:
1373+
cpu:
1374+
anyOf:
1375+
- type: integer
1376+
- type: string
1377+
description: cpu is the definition of the cpu quantity
1378+
for the given VM hardware policy
1379+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
1380+
x-kubernetes-int-or-string: true
1381+
memory:
1382+
anyOf:
1383+
- type: integer
1384+
- type: string
1385+
description: memory is the definition of the memory
1386+
quantity for the given VM hardware policy
1387+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
1388+
x-kubernetes-int-or-string: true
1389+
type: object
1390+
shares:
1391+
description: shares is the definition of the VM's cpu
1392+
and memory shares
1393+
minProperties: 1
1394+
properties:
1395+
cpu:
1396+
description: cpu is the number of spu shares to assign
1397+
to the VM
1398+
format: int32
1399+
minimum: 1
1400+
type: integer
1401+
memory:
1402+
description: memory is the number of memory shares
1403+
to assign to the VM
1404+
format: int32
1405+
minimum: 1
1406+
type: integer
1407+
type: object
1408+
type: object
13381409
server:
13391410
description: |-
13401411
Server is the IP address or FQDN of the vSphere server on which

0 commit comments

Comments
 (0)