Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Add flag to reserve memory to the virtual machine memory size #2469

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions apis/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ type VirtualMachineCloneSpec struct {
// virtual machine is cloned.
// +optional
MemoryMiB int64 `json:"memoryMiB,omitempty"`
// MemoryReservationLockedToMax is a flag that indicates whether or not the
// memory resource reservation for this virtual machine will always be
// equal to the virtual machine's memory size.
// Defaults to the eponymous property value in the template from which the
// virtual machine is cloned.
// +optional
MemoryReservationLockedToMax *bool `json:"memoryReservationLockedToMax,omitempty"`
// DiskGiB is the size of a virtual machine's disk, in GiB.
// Defaults to the eponymous property value in the template from which the
// virtual machine is cloned.
Expand Down
5 changes: 5 additions & 0 deletions apis/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ spec:
from which the virtual machine is cloned.
format: int64
type: integer
memoryReservationLockedToMax:
description: MemoryReservationLockedToMax is a flag that indicates
whether or not the memory resource reservation for this virtual
machine will always be equal to the virtual machine's memory size.
Defaults to the eponymous property value in the template from which
the virtual machine is cloned.
type: boolean
network:
description: Network is the network configuration for this machine's
VM.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ spec:
in the template from which the virtual machine is cloned.
format: int64
type: integer
memoryReservationLockedToMax:
description: MemoryReservationLockedToMax is a flag that indicates
whether or not the memory resource reservation for this
virtual machine will always be equal to the virtual machine's
memory size. Defaults to the eponymous property value in
the template from which the virtual machine is cloned.
type: boolean
network:
description: Network is the network configuration for this
machine's VM.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ spec:
from which the virtual machine is cloned.
format: int64
type: integer
memoryReservationLockedToMax:
description: MemoryReservationLockedToMax is a flag that indicates
whether or not the memory resource reservation for this virtual
machine will always be equal to the virtual machine's memory size.
Defaults to the eponymous property value in the template from which
the virtual machine is cloned.
type: boolean
network:
description: Network is the network configuration for this machine's
VM.
Expand Down
23 changes: 15 additions & 8 deletions pkg/services/govmomi/vcenter/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@
memMiB = 2048
}

var memLockedToMax *bool
if vmCtx.VSphereVM.Spec.MemoryReservationLockedToMax != nil {
memLockedToMax = new(bool)
chrischdi marked this conversation as resolved.
Show resolved Hide resolved
*memLockedToMax = *vmCtx.VSphereVM.Spec.MemoryReservationLockedToMax
}

Check warning on line 174 in pkg/services/govmomi/vcenter/clone.go

View check run for this annotation

Codecov / codecov/patch

pkg/services/govmomi/vcenter/clone.go#L172-L174

Added lines #L172 - L174 were not covered by tests

Comment on lines +170 to +175
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var memLockedToMax *bool
if vmCtx.VSphereVM.Spec.MemoryReservationLockedToMax != nil {
memLockedToMax = new(bool)
*memLockedToMax = *vmCtx.VSphereVM.Spec.MemoryReservationLockedToMax
}

Should not be required when directly referring below

// Disable the vAppConfig during VM creation to ensure Cloud-Init inside of the guest does not
// activate and prefer the OVF datasource over the VMware datasource.
vappConfigRemoved := true
Expand All @@ -176,14 +182,15 @@
// Assign the clone's InstanceUUID the value of the Kubernetes Machine
// object's UID. This allows lookup of the cloned VM prior to knowing
// the VM's UUID.
InstanceUuid: string(vmCtx.VSphereVM.UID),
Flags: newVMFlagInfo(),
DeviceChange: deviceSpecs,
ExtraConfig: extraConfig,
NumCPUs: numCPUs,
NumCoresPerSocket: numCoresPerSocket,
MemoryMB: memMiB,
VAppConfigRemoved: &vappConfigRemoved,
InstanceUuid: string(vmCtx.VSphereVM.UID),
Flags: newVMFlagInfo(),
DeviceChange: deviceSpecs,
ExtraConfig: extraConfig,
NumCPUs: numCPUs,
NumCoresPerSocket: numCoresPerSocket,
MemoryMB: memMiB,
MemoryReservationLockedToMax: memLockedToMax,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
MemoryReservationLockedToMax: memLockedToMax,
MemoryReservationLockedToMax: vmCtx.VSphereVM.Spec.MemoryReservationLockedToMax,

We can directly reference that setting.

VAppConfigRemoved: &vappConfigRemoved,
},
Location: types.VirtualMachineRelocateSpec{
DiskMoveType: string(diskMoveType),
Expand Down
Loading