Skip to content

Commit 1c37856

Browse files
author
Ricardo Katz
committed
Make vcsim work with moid
1 parent 3005d40 commit 1c37856

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

test/infrastructure/vcsim/controllers/vmip_controller.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121

2222
"github.com/pkg/errors"
23+
"github.com/vmware/govmomi/object"
2324
"github.com/vmware/govmomi/vim25/types"
2425
ctrl "sigs.k8s.io/controller-runtime"
2526
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -52,9 +53,16 @@ func (r *vmIPReconciler) ReconcileIP(ctx context.Context) (ctrl.Result, error) {
5253
return reconcile.Result{}, errors.Wrapf(err, "failed to get vcenter session")
5354
}
5455

55-
vm, err := authSession.Finder.VirtualMachine(ctx, r.GetVMPath())
56-
if err != nil {
57-
return reconcile.Result{}, errors.Wrapf(err, "failed to find vm")
56+
vmPath := r.GetVMPath()
57+
var vm *object.VirtualMachine
58+
vmRef := object.ReferenceFromString(vmPath)
59+
if vmRef != nil {
60+
vm = object.NewVirtualMachine(authSession.Client.Client, *vmRef)
61+
} else {
62+
vm, err = authSession.Finder.VirtualMachine(ctx, r.GetVMPath())
63+
if err != nil {
64+
return reconcile.Result{}, errors.Wrapf(err, "failed to find vm")
65+
}
5866
}
5967

6068
// Check if the VM already has network status (but it is not yet surfaced in conditions)

test/infrastructure/vcsim/controllers/vspherevm_controller.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package controllers
1919
import (
2020
"context"
2121
"fmt"
22-
"path"
2322

2423
"github.com/pkg/errors"
2524
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -264,8 +263,8 @@ func (r *VSphereVMReconciler) getVMIpReconciler(vSphereCluster *infrav1.VSphereC
264263
return !vSphereVM.Status.Ready && conditions.IsFalse(vSphereVM, infrav1.VMProvisionedCondition) && conditions.GetReason(vSphereVM, infrav1.VMProvisionedCondition) == infrav1.WaitingForIPAllocationReason
265264
},
266265
GetVMPath: func() string {
267-
// Return the path where the VM is stored.
268-
return path.Join(vSphereVM.Spec.Folder, vSphereVM.Name)
266+
// Return vmref of the VM as it is populated already by CAPV
267+
return vSphereVM.Status.VMRef
269268
},
270269
}
271270
}

0 commit comments

Comments
 (0)