Skip to content

Commit

Permalink
Merge pull request #633 from bryanv/bryanv/resize-just-cpu-memory
Browse files Browse the repository at this point in the history
✨ resize: VM resize of just CPU and Memory
  • Loading branch information
bryanv authored Jul 25, 2024
2 parents 8d587db + 6f31a70 commit b5d1a3d
Show file tree
Hide file tree
Showing 5 changed files with 245 additions and 175 deletions.
32 changes: 19 additions & 13 deletions pkg/providers/vsphere/session/session_vm_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,10 @@ func updateConfigSpec(
UpdateConfigSpecFirmware(config, configSpec, vmCtx.VM)
UpdateConfigSpecGuestID(config, configSpec, vmCtx.VM.Spec.GuestID)

if pkgcfg.FromContext(vmCtx).Features.VMResizeCPUMemory {
UpdateHardwareConfigSpec(config, configSpec, &vmClassSpec)
}

return configSpec
}

Expand Down Expand Up @@ -604,8 +608,8 @@ func (s *Session) prePowerOnVMReconfigure(
var configSpec *vimtypes.VirtualMachineConfigSpec
var err error

vmResizeEnabled := pkgcfg.FromContext(vmCtx).Features.VMResize
if vmResizeEnabled {
features := pkgcfg.FromContext(vmCtx).Features
if features.VMResize {
configSpec, err = s.prePowerOnVMResizeConfigSpec(vmCtx, config, updateArgs)
} else {
configSpec, err = s.prePowerOnVMConfigSpec(vmCtx, config, updateArgs)
Expand All @@ -631,15 +635,15 @@ func (s *Session) prePowerOnVMReconfigure(
vmCtx.Logger.Error(err, "pre power on reconfigure failed")
return err
}
}

if vmResizeEnabled {
vmopv1util.MustSetLastResizedAnnotation(vmCtx.VM, updateArgs.VMClass)
if features.VMResize || features.VMResizeCPUMemory {
vmopv1util.MustSetLastResizedAnnotation(vmCtx.VM, updateArgs.VMClass)

vmCtx.VM.Status.Class = &vmopv1common.LocalObjectRef{
APIVersion: vmopv1.GroupVersion.String(),
Kind: "VirtualMachineClass",
Name: updateArgs.VMClass.Name,
}
vmCtx.VM.Status.Class = &vmopv1common.LocalObjectRef{
APIVersion: vmopv1.GroupVersion.String(),
Kind: "VirtualMachineClass",
Name: updateArgs.VMClass.Name,
}
}

Expand Down Expand Up @@ -919,12 +923,14 @@ func (s *Session) resizeVMWhenPoweredStateOff(
if resizeArgs.VMClass != nil {
needsResize = vmopv1util.ResizeNeeded(*vmCtx.VM, *resizeArgs.VMClass)
if needsResize {
cs, err := resize.CreateResizeConfigSpec(vmCtx, *moVM.Config, resizeArgs.ConfigSpec)
if pkgcfg.FromContext(vmCtx).Features.VMResize {
configSpec, err = resize.CreateResizeConfigSpec(vmCtx, *moVM.Config, resizeArgs.ConfigSpec)
} else {
configSpec, err = resize.CreateResizeCPUMemoryConfigSpec(vmCtx, *moVM.Config, resizeArgs.ConfigSpec)
}
if err != nil {
return false, err
}

configSpec = cs
}
}

Expand Down Expand Up @@ -1022,7 +1028,7 @@ func (s *Session) updateVMDesiredPowerStateOff(
refetchProps = true
}

if pkgcfg.FromContext(vmCtx).Features.VMResize {
if f := pkgcfg.FromContext(vmCtx).Features; f.VMResize || f.VMResizeCPUMemory {
refetchProps, err = s.resizeVMWhenPoweredStateOff(
vmCtx,
vcVM,
Expand Down
2 changes: 1 addition & 1 deletion pkg/providers/vsphere/vmprovider_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ func (vs *vSphereVMProvider) vmCreateGetPrereqs(

if !vmopv1util.IsClasslessVM(*vmCtx.VM) {
// Only set VM Class field for non-synthesized classes.
if pkgcfg.FromContext(vmCtx).Features.VMResize {
if f := pkgcfg.FromContext(vmCtx).Features; f.VMResize || f.VMResizeCPUMemory {
vmopv1util.MustSetLastResizedAnnotation(vmCtx.VM, createArgs.VMClass)
}
vmCtx.VM.Status.Class = &common.LocalObjectRef{
Expand Down
Loading

0 comments on commit b5d1a3d

Please sign in to comment.