Skip to content

Commit 64df85a

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 64df85a

File tree

8 files changed

+329
-0
lines changed

8 files changed

+329
-0
lines changed

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/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: 33 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,10 @@ type VirtualMachineCloneSpec struct {
167168
// virtual machine is cloned.
168169
// +optional
169170
NumCoresPerSocket int32 `json:"numCoresPerSocket,omitempty"`
171+
// resources is the definition of the VM's cpu and memory
172+
// reservations, limits and shares.
173+
// +optional
174+
Resources VirtualMachineResources `json:"resources,omitempty,omitzero"`
170175
// MemoryMiB is the size of a virtual machine's memory, in MiB.
171176
// Defaults to the eponymous property value in the template from which the
172177
// virtual machine is cloned.
@@ -211,6 +216,34 @@ type VirtualMachineCloneSpec struct {
211216
DataDisks []VSphereDisk `json:"dataDisks,omitempty"`
212217
}
213218

219+
// VirtualMachineResources is the definition of the VM's cpu and memory
220+
// reservations, limits and shares.
221+
// +kubebuilder:validation:MinProperties=1
222+
type VirtualMachineResources struct {
223+
// requests is the definition of the VM's cpu (in hertz) and memory (in bytes) reservations
224+
// +optional
225+
Requests VirtualMachineResourceSpec `json:"requests,omitempty,omitzero"`
226+
// limits is the definition of the VM's cpu (in hertz) and memory (in bytes) limits
227+
// +optional
228+
Limits VirtualMachineResourceSpec `json:"limits,omitempty,omitzero"`
229+
// shares is the definition of the VM's cpu and memory shares
230+
// +optional
231+
Shares VirtualMachineResourceSpec `json:"shares,omitempty,omitzero"`
232+
}
233+
234+
// VirtualMachineResourceSpec is the numerical definition of memory and cpu quantity for the
235+
// given VM hardware policy.
236+
// +kubebuilder:validation:MinProperties=1
237+
type VirtualMachineResourceSpec struct {
238+
// cpu is the definition of the cpu quantity for the given VM hardware policy
239+
// +optional
240+
Cpu resource.Quantity `json:"cpu,omitempty"` //nolint:revive
241+
242+
// memory is the definition of the memory quantity for the given VM hardware policy
243+
// +optional
244+
Memory resource.Quantity `json:"memory,omitempty"`
245+
}
246+
214247
// VSphereDisk is an additional disk to add to the VM that is not part of the VM OVA template.
215248
type VSphereDisk struct {
216249
// 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: 36 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: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,79 @@ 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: limits is the definition of the VM's cpu (in hertz)
1470+
and memory (in bytes) limits
1471+
minProperties: 1
1472+
properties:
1473+
cpu:
1474+
anyOf:
1475+
- type: integer
1476+
- type: string
1477+
description: cpu is the definition of the cpu quantity for
1478+
the given VM hardware policy
1479+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
1480+
x-kubernetes-int-or-string: true
1481+
memory:
1482+
anyOf:
1483+
- type: integer
1484+
- type: string
1485+
description: memory is the definition of the memory quantity
1486+
for the given VM hardware policy
1487+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
1488+
x-kubernetes-int-or-string: true
1489+
type: object
1490+
requests:
1491+
description: requests is the definition of the VM's cpu (in hertz)
1492+
and memory (in bytes) reservations
1493+
minProperties: 1
1494+
properties:
1495+
cpu:
1496+
anyOf:
1497+
- type: integer
1498+
- type: string
1499+
description: cpu is the definition of the cpu quantity for
1500+
the given VM hardware policy
1501+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
1502+
x-kubernetes-int-or-string: true
1503+
memory:
1504+
anyOf:
1505+
- type: integer
1506+
- type: string
1507+
description: memory is the definition of the memory quantity
1508+
for the given VM hardware policy
1509+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
1510+
x-kubernetes-int-or-string: true
1511+
type: object
1512+
shares:
1513+
description: shares is the definition of the VM's cpu and memory
1514+
shares
1515+
minProperties: 1
1516+
properties:
1517+
cpu:
1518+
anyOf:
1519+
- type: integer
1520+
- type: string
1521+
description: cpu is the definition of the cpu quantity for
1522+
the given VM hardware policy
1523+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
1524+
x-kubernetes-int-or-string: true
1525+
memory:
1526+
anyOf:
1527+
- type: integer
1528+
- type: string
1529+
description: memory is the definition of the memory quantity
1530+
for the given VM hardware policy
1531+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
1532+
x-kubernetes-int-or-string: true
1533+
type: object
1534+
type: object
14621535
server:
14631536
description: |-
14641537
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: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,79 @@ 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: limits is the definition of the VM's cpu
1346+
(in hertz) and memory (in bytes) limits
1347+
minProperties: 1
1348+
properties:
1349+
cpu:
1350+
anyOf:
1351+
- type: integer
1352+
- type: string
1353+
description: cpu is the definition of the cpu quantity
1354+
for the given VM hardware policy
1355+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
1356+
x-kubernetes-int-or-string: true
1357+
memory:
1358+
anyOf:
1359+
- type: integer
1360+
- type: string
1361+
description: memory is the definition of the memory
1362+
quantity for the given VM hardware policy
1363+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
1364+
x-kubernetes-int-or-string: true
1365+
type: object
1366+
requests:
1367+
description: requests is the definition of the VM's cpu
1368+
(in hertz) and memory (in bytes) reservations
1369+
minProperties: 1
1370+
properties:
1371+
cpu:
1372+
anyOf:
1373+
- type: integer
1374+
- type: string
1375+
description: cpu is the definition of the cpu quantity
1376+
for the given VM hardware policy
1377+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
1378+
x-kubernetes-int-or-string: true
1379+
memory:
1380+
anyOf:
1381+
- type: integer
1382+
- type: string
1383+
description: memory is the definition of the memory
1384+
quantity for the given VM hardware policy
1385+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
1386+
x-kubernetes-int-or-string: true
1387+
type: object
1388+
shares:
1389+
description: shares is the definition of the VM's cpu
1390+
and memory shares
1391+
minProperties: 1
1392+
properties:
1393+
cpu:
1394+
anyOf:
1395+
- type: integer
1396+
- type: string
1397+
description: cpu is the definition of the cpu quantity
1398+
for the given VM hardware policy
1399+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
1400+
x-kubernetes-int-or-string: true
1401+
memory:
1402+
anyOf:
1403+
- type: integer
1404+
- type: string
1405+
description: memory is the definition of the memory
1406+
quantity for the given VM hardware policy
1407+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
1408+
x-kubernetes-int-or-string: true
1409+
type: object
1410+
type: object
13381411
server:
13391412
description: |-
13401413
Server is the IP address or FQDN of the vSphere server on which

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

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,6 +1517,79 @@ spec:
15171517
ResourcePool is the name, inventory path, managed object reference or the managed
15181518
object ID in which the virtual machine is created/located.
15191519
type: string
1520+
resources:
1521+
description: |-
1522+
resources is the definition of the VM's cpu and memory
1523+
reservations, limits and shares.
1524+
minProperties: 1
1525+
properties:
1526+
limits:
1527+
description: limits is the definition of the VM's cpu (in hertz)
1528+
and memory (in bytes) limits
1529+
minProperties: 1
1530+
properties:
1531+
cpu:
1532+
anyOf:
1533+
- type: integer
1534+
- type: string
1535+
description: cpu is the definition of the cpu quantity for
1536+
the given VM hardware policy
1537+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
1538+
x-kubernetes-int-or-string: true
1539+
memory:
1540+
anyOf:
1541+
- type: integer
1542+
- type: string
1543+
description: memory is the definition of the memory quantity
1544+
for the given VM hardware policy
1545+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
1546+
x-kubernetes-int-or-string: true
1547+
type: object
1548+
requests:
1549+
description: requests is the definition of the VM's cpu (in hertz)
1550+
and memory (in bytes) reservations
1551+
minProperties: 1
1552+
properties:
1553+
cpu:
1554+
anyOf:
1555+
- type: integer
1556+
- type: string
1557+
description: cpu is the definition of the cpu quantity for
1558+
the given VM hardware policy
1559+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
1560+
x-kubernetes-int-or-string: true
1561+
memory:
1562+
anyOf:
1563+
- type: integer
1564+
- type: string
1565+
description: memory is the definition of the memory quantity
1566+
for the given VM hardware policy
1567+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
1568+
x-kubernetes-int-or-string: true
1569+
type: object
1570+
shares:
1571+
description: shares is the definition of the VM's cpu and memory
1572+
shares
1573+
minProperties: 1
1574+
properties:
1575+
cpu:
1576+
anyOf:
1577+
- type: integer
1578+
- type: string
1579+
description: cpu is the definition of the cpu quantity for
1580+
the given VM hardware policy
1581+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
1582+
x-kubernetes-int-or-string: true
1583+
memory:
1584+
anyOf:
1585+
- type: integer
1586+
- type: string
1587+
description: memory is the definition of the memory quantity
1588+
for the given VM hardware policy
1589+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
1590+
x-kubernetes-int-or-string: true
1591+
type: object
1592+
type: object
15201593
server:
15211594
description: |-
15221595
Server is the IP address or FQDN of the vSphere server on which

0 commit comments

Comments
 (0)