Skip to content

Commit 1cbdb16

Browse files
authored
Merge pull request #3351 from chrischdi/pr-vcsim-remove-template-networkinterface
🌱 vcsim: wait for powered on VM and use mac address reference to set IP
2 parents 357565e + 2cdd008 commit 1cbdb16

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

controllers/vspherevm_controller.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,9 @@ func (r vmReconciler) reconcileNormal(ctx context.Context, vmCtx *capvcontext.VM
437437
// Do not proceed until the backend VM is marked ready.
438438
if vm.State != infrav1.VirtualMachineStateReady {
439439
log.Info(fmt.Sprintf("VM state is %q, waiting for %q", vm.State, infrav1.VirtualMachineStateReady))
440+
if !vmCtx.VSphereVM.Status.RetryAfter.IsZero() {
441+
return reconcile.Result{RequeueAfter: time.Until(vmCtx.VSphereVM.Status.RetryAfter.Time)}, nil
442+
}
440443
return reconcile.Result{}, nil
441444
}
442445

test/infrastructure/vcsim/controllers/vmip_controller.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package controllers
1818

1919
import (
2020
"context"
21+
"time"
2122

2223
"github.com/pkg/errors"
2324
"github.com/vmware/govmomi/vim25/types"
@@ -71,6 +72,30 @@ func (r *vmIPReconciler) ReconcileIP(ctx context.Context) (ctrl.Result, error) {
7172
return reconcile.Result{}, nil
7273
}
7374

75+
var macAddress string
76+
devices, err := vm.Device(ctx)
77+
if err != nil {
78+
return reconcile.Result{}, errors.Wrapf(err, "failed to get devices for vm")
79+
}
80+
for _, device := range devices {
81+
if ethernetCard, ok := device.(types.BaseVirtualEthernetCard); ok {
82+
macAddress = ethernetCard.GetVirtualEthernetCard().MacAddress
83+
}
84+
}
85+
if macAddress == "" {
86+
return reconcile.Result{}, errors.Wrapf(err, "failed to find mac address")
87+
}
88+
89+
powerState, err := vm.PowerState(ctx)
90+
if err != nil {
91+
return reconcile.Result{}, errors.Wrapf(err, "failed to check Power State of vm")
92+
}
93+
94+
if powerState != types.VirtualMachinePowerStatePoweredOn {
95+
// Requeue to wait for the VM to get powered on by CAPV or Supervisor first.
96+
return reconcile.Result{RequeueAfter: time.Second}, nil
97+
}
98+
7499
log.Info("Powering Off the VM before applying an IP")
75100
task, err := vm.PowerOff(ctx)
76101
if err != nil {
@@ -84,6 +109,7 @@ func (r *vmIPReconciler) ReconcileIP(ctx context.Context) (ctrl.Result, error) {
84109
spec := types.CustomizationSpec{
85110
NicSettingMap: []types.CustomizationAdapterMapping{
86111
{
112+
MacAddress: macAddress,
87113
Adapter: types.CustomizationIPSettings{
88114
Ip: &types.CustomizationFixedIp{
89115
IpAddress: "192.168.1.100",

0 commit comments

Comments
 (0)