Skip to content

Commit 89944f7

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 89944f7

14 files changed

+378
-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/vspheremachinetemplate_conversion.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func (src *VSphereMachineTemplate) ConvertTo(dstRaw conversion.Hub) error {
3939
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
4040
return err
4141
}
42+
dst.Spec.Template.Spec.Resources = restored.Spec.Template.Spec.Resources
4243
dst.Spec.Template.Spec.TagIDs = restored.Spec.Template.Spec.TagIDs
4344
dst.Spec.Template.Spec.AdditionalDisksGiB = restored.Spec.Template.Spec.AdditionalDisksGiB
4445
dst.Spec.Template.Spec.PowerOffMode = restored.Spec.Template.Spec.PowerOffMode

apis/v1alpha3/vspherevm_conversion.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func (src *VSphereVM) ConvertTo(dstRaw conversion.Hub) error {
3535
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
3636
return err
3737
}
38+
dst.Spec.Resources = restored.Spec.Resources
3839
dst.Spec.TagIDs = restored.Spec.TagIDs
3940
dst.Spec.AdditionalDisksGiB = restored.Spec.AdditionalDisksGiB
4041
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/vspheremachinetemplate_conversion.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func (src *VSphereMachineTemplate) ConvertTo(dstRaw conversion.Hub) error {
3939
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
4040
return err
4141
}
42+
dst.Spec.Template.Spec.Resources = restored.Spec.Template.Spec.Resources
4243
dst.Spec.Template.Spec.TagIDs = restored.Spec.Template.Spec.TagIDs
4344
dst.Spec.Template.Spec.AdditionalDisksGiB = restored.Spec.Template.Spec.AdditionalDisksGiB
4445
dst.Spec.Template.Spec.PowerOffMode = restored.Spec.Template.Spec.PowerOffMode

apis/v1alpha4/vspherevm_conversion.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func (src *VSphereVM) ConvertTo(dstRaw conversion.Hub) error {
3535
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
3636
return err
3737
}
38+
dst.Spec.Resources = restored.Spec.Resources
3839
dst.Spec.TagIDs = restored.Spec.TagIDs
3940
dst.Spec.AdditionalDisksGiB = restored.Spec.AdditionalDisksGiB
4041
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"` //nolint:revive
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.

0 commit comments

Comments
 (0)