Skip to content

Commit

Permalink
Set more useful interface name in v1a2 VM Status
Browse files Browse the repository at this point in the history
We have a long ways to go before we actually support multiple
interfaces, both in bootstrap and in reconcile. The exceedingly
common case is just one interface so special case that to provide
the interface name in the Status.
  • Loading branch information
bryanv committed Dec 14, 2023
1 parent 70d22b9 commit 71aff91
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
23 changes: 20 additions & 3 deletions pkg/vmprovider/providers/vsphere2/vmlifecycle/update_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,14 @@ func UpdateStatus(
vm.Status.UniqueID = vcVM.Reference().Value
vm.Status.BiosUUID = summary.Config.Uuid
vm.Status.InstanceUUID = summary.Config.InstanceUuid
vm.Status.Network = getGuestNetworkStatus(vmMO.Guest)
vm.Status.HardwareVersion = util.ParseVirtualHardwareVersion(summary.Config.HwVersion)

var networkInterfaces []vmopv1.VirtualMachineNetworkInterfaceSpec
if vmCtx.VM.Spec.Network != nil {
networkInterfaces = vmCtx.VM.Spec.Network.Interfaces
}
vm.Status.Network = getGuestNetworkStatus(networkInterfaces, vmMO.Guest)

vm.Status.Host, err = getRuntimeHostHostname(vmCtx, vcVM, summary.Runtime.Host)
if err != nil {
errs = append(errs, err)
Expand Down Expand Up @@ -136,7 +141,11 @@ func getRuntimeHostHostname(
return "", nil
}

func getGuestNetworkStatus(guestInfo *types.GuestInfo) *vmopv1.VirtualMachineNetworkStatus {
func getGuestNetworkStatus(
networkInterfaces []vmopv1.VirtualMachineNetworkInterfaceSpec,
guestInfo *types.GuestInfo,
) *vmopv1.VirtualMachineNetworkStatus {

if guestInfo == nil {
return nil
}
Expand All @@ -159,6 +168,14 @@ func getGuestNetworkStatus(guestInfo *types.GuestInfo) *vmopv1.VirtualMachineNet
}
}

// Hack: the exceedingly common case is just one nic - our boostrap effectively only works with one -
// so do the best effort here and apply the name in that common case. We have a long ways to go until
// we can always line up interfaces in the Spec with what both is observed in the VM hardware config
// and what the GuestNicInfo provides.
if len(networkInterfaces) == 1 && len(status.Interfaces) == 1 {
status.Interfaces[0].Name = networkInterfaces[0].Name
}

if len(guestInfo.IpStack) > 0 {
status.VirtualMachineNetworkIPStackStatus = guestIPStackInfoToIPStackStatus(&guestInfo.IpStack[0])
}
Expand All @@ -169,7 +186,7 @@ func getGuestNetworkStatus(guestInfo *types.GuestInfo) *vmopv1.VirtualMachineNet
func guestNicInfoToInterfaceStatus(idx int, guestNicInfo *types.GuestNicInfo) vmopv1.VirtualMachineNetworkInterfaceStatus {
status := vmopv1.VirtualMachineNetworkInterfaceStatus{}

// TODO: What name exactly? The CRD name may be the most useful here but hard to line that up.
// Try to provide some default, useful name that can otherwise help identify the interface.
status.Name = fmt.Sprintf("nic-%d-%d", idx, guestNicInfo.DeviceConfigId)
status.IP.MACAddr = guestNicInfo.MacAddress

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,20 @@ var _ = Describe("UpdateStatus", func() {
},
},
}

vmCtx.VM.Spec.Network.Interfaces = []vmopv1.VirtualMachineNetworkInterfaceSpec{
{
Name: "eth42",
},
}
})

It("Skips pseudo devices", func() {
network := vmCtx.VM.Status.Network

Expect(network.Interfaces).To(HaveLen(1))
Expect(network.Interfaces[0].IP.MACAddr).To(Equal("mac-4000"))
Expect(network.Interfaces[0].Name).To(Equal("eth42"))
})
})

Expand Down

0 comments on commit 71aff91

Please sign in to comment.