From 061fd88d2e0ade698a81e359ed78169953ee469a Mon Sep 17 00:00:00 2001 From: Anoop C S Date: Tue, 25 Jan 2022 11:08:39 +0530 Subject: [PATCH] drivers/kvm: Use ARP for retrieving interface ip addresses On platforms where dhcp lease status is not updated immediately after domain creation it fails to list ip addresses until next refresh happens resulting in the following error: 8<----------8<----------8<----------8<----------8<----------8<---------- Creating kvm2 VM (CPUs=2, Memory=4096MB, Disk=20480MB) ... Failed to start kvm2 VM. Running "minikube delete" may fix it: creating host: create: Error creating machine: Error in driver during machine creation: IP not available after waiting: machine minikube didn't return IP after 1 minute Exiting due to GUEST_PROVISION: Failed to start host: creating host: create: Error creating machine: Error in driver during machine creation: IP not available after waiting: machine minikube didn't return IP after 1 minute 8<----------8<----------8<----------8<----------8<----------8<---------- Using ARP instead of LEASE for ip address query is justifiable as listing is done following the domain creation. In case of failure we fallback to listing via LEASE source. Signed-off-by: Anoop C S --- pkg/drivers/kvm/network.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/pkg/drivers/kvm/network.go b/pkg/drivers/kvm/network.go index b704b55c8097..835c2c6480a9 100644 --- a/pkg/drivers/kvm/network.go +++ b/pkg/drivers/kvm/network.go @@ -478,9 +478,19 @@ func ifListFromAPI(conn *libvirt.Connect, domain string) ([]libvirt.DomainInterf } defer func() { _ = dom.Free() }() - ifs, err := dom.ListAllInterfaceAddresses(libvirt.DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE) - if err != nil { - return nil, fmt.Errorf("failed listing network interface addresses of domain %s: %w", domain, err) + ifs, err := dom.ListAllInterfaceAddresses(libvirt.DOMAIN_INTERFACE_ADDRESSES_SRC_ARP) + if ifs == nil { + if err != nil { + log.Debugf("failed listing network interface addresses of domain %s(source=arp): %w", domain, err) + } else { + log.Debugf("No network interface addresses found for domain %s(source=arp)", domain) + } + log.Debugf("trying to list again with source=lease") + + ifs, err = dom.ListAllInterfaceAddresses(libvirt.DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE) + if err != nil { + return nil, fmt.Errorf("failed listing network interface addresses of domain %s(source=lease): %w", domain, err) + } } return ifs, nil