Skip to content

Commit

Permalink
This patch does three things:
Browse files Browse the repository at this point in the history
1. The VM object's namespace and name are stored in
   ExtraConfig as the keys vmservice.namespace and
   vmservice.name.

2. The VM's vSphere property config.managedBy is
   always set to reflect the VM is managed by VM
   Service if it is not set to this value.

3. There is now support for always ensuring certain
   properties are set during each reconcile, regardless
   of the VM's power state or whether or not the VM is
   paused by the admin. For example, the
   aforementioned namespace/name ExtraConfig keys are
   included, as well as the VM's config.managedBy
   property.
  • Loading branch information
akutz committed Aug 8, 2024
1 parent 2a23d28 commit 58204bf
Show file tree
Hide file tree
Showing 12 changed files with 668 additions and 298 deletions.
12 changes: 7 additions & 5 deletions pkg/providers/vsphere/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import (
)

const (
ExtraConfigTrue = "TRUE"
ExtraConfigFalse = "FALSE"
ExtraConfigUnset = ""
ExtraConfigGuestInfoPrefix = "guestinfo."
ExtraConfigRunContainerKey = "RUN.container"
ExtraConfigTrue = "TRUE"
ExtraConfigFalse = "FALSE"
ExtraConfigUnset = ""
ExtraConfigGuestInfoPrefix = "guestinfo."
ExtraConfigRunContainerKey = "RUN.container"
ExtraConfigVMServiceName = "vmservice.name"
ExtraConfigVMServiceNamespace = "vmservice.namespace"

// VCVMAnnotation Annotation placed on the VM.
VCVMAnnotation = "Virtual Machine managed by the vSphere Virtual Machine service"
Expand Down
17 changes: 15 additions & 2 deletions pkg/providers/vsphere/resources/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package resources

import (
"bytes"
"context"
"fmt"

Expand Down Expand Up @@ -75,8 +76,20 @@ func (vm *VirtualMachine) Clone(ctx context.Context, folder *object.Folder, clon
return &ref, nil
}

func (vm *VirtualMachine) Reconfigure(ctx context.Context, configSpec *vimtypes.VirtualMachineConfigSpec) (*vimtypes.TaskInfo, error) {
vm.logger.V(5).Info("Reconfiguring VM", "configSpec", configSpec)
func (vm *VirtualMachine) Reconfigure(
ctx context.Context,
configSpec *vimtypes.VirtualMachineConfigSpec) (*vimtypes.TaskInfo, error) {

logger := logr.FromContextOrDiscard(ctx)

var w bytes.Buffer
enc := vimtypes.NewJSONEncoder(&w)
if err := enc.Encode(configSpec); err != nil {
logger.Error(err, "Failed to marshal ConfigSpec to JSON")
logger.Info("Reconfiguring VM", "configSpec", configSpec)
} else {
logger.Info("Reconfiguring VM", "configSpec", w.String())
}

reconfigureTask, err := vm.vcVirtualMachine.Reconfigure(ctx, *configSpec)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions pkg/providers/vsphere/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package session

import (
"fmt"

"github.com/vmware/govmomi/find"
"github.com/vmware/govmomi/object"
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -28,13 +30,11 @@ func (s *Session) invokeFsrVirtualMachine(vmCtx pkgctx.VirtualMachineContext, re

task, err := internal.VirtualMachineFSR(vmCtx, resVM.MoRef(), s.Client.VimClient())
if err != nil {
vmCtx.Logger.Error(err, "InvokeFSR call failed")
return err
return fmt.Errorf("failed to invoke FSR: %w", err)
}

if err = task.Wait(vmCtx); err != nil {
vmCtx.Logger.Error(err, "InvokeFSR task failed")
return err
return fmt.Errorf("failed to wait on FSR task: %w", err)
}

return nil
Expand Down
Loading

0 comments on commit 58204bf

Please sign in to comment.