Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Don't fail when there are unsupported net interfaces in the container #146

Merged
merged 2 commits into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pkg/container/firecracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ func ExecuteFirecracker(md *vmmd.VM, dhcpIfaces []DHCPInterface) error {
cmdLine = constants.VM_DEFAULT_KERNEL_ARGS
}

firecrackerSocketPath := path.Join(md.ObjectPath(), FIRECRACKER_API_SOCKET)
logSocketPath := path.Join(md.ObjectPath(), LOG_FIFO)
metricsSocketPath := path.Join(md.ObjectPath(), METRICS_FIFO)
firecrackerSocketPath := path.Join(md.ObjectPath(), constants.FIRECRACKER_API_SOCKET)
logSocketPath := path.Join(md.ObjectPath(), constants.LOG_FIFO)
metricsSocketPath := path.Join(md.ObjectPath(), constants.METRICS_FIFO)
cfg := firecracker.Config{
SocketPath: firecrackerSocketPath,
KernelImagePath: path.Join(constants.KERNEL_DIR, md.GetKernelUID().String(), constants.KERNEL_FILE),
Expand Down
49 changes: 31 additions & 18 deletions pkg/container/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func SetupContainerNetworking() ([]DHCPInterface, error) {
}
if retry {
// we got an error, but let's ignore it and try again
log.Infof("Got an error while trying to set up networking, but retrying: %v", err)
return false, nil
}
// the error was fatal, return it
Expand All @@ -70,31 +71,43 @@ func networkSetup(dhcpIfaces *[]DHCPInterface) (bool, error) {
interfacesCount := 0
for _, iface := range ifaces {
// Skip the interface if it's ignored
if !ignoreInterfaces[iface.Name] {
// This is an interface we care about
interfacesCount++
if ignoreInterfaces[iface.Name] {
continue
}

// Try to transfer the address from the container to the DHCP server
ipNet, _, err := takeAddress(&iface)
if err != nil {
// Log the problem, but don't quit the function here as there might be other good interfaces
log.Errorf("Parsing interface %s failed: %v", iface.Name, err)
// Try with the next interface
continue
}

ipNet, retry, err := takeAddress(&iface)
if err != nil {
return retry, fmt.Errorf("parsing interface failed: %v", err)
}
// Bridge the Firecracker TAP interface with the container veth interface
dhcpIface, err := bridge(&iface)
if err != nil {
// Log the problem, but don't quit the function here as there might be other good interfaces
// Don't set shouldRetry here as there is no point really with retrying with this interface
// that seems broken/unsupported in some way.
log.Errorf("Bridging interface %s failed: %v", iface.Name, err)
// Try with the next interface
continue
}

dhcpIface, err := bridge(&iface)
if err != nil {
return false, fmt.Errorf("bridging interface %s failed: %v0", iface.Name, err)
}
// Gateway for now is just x.x.x.1 TODO: Better detection
dhcpIface.GatewayIP = &net.IP{ipNet.IP[0], ipNet.IP[1], ipNet.IP[2], 1}
dhcpIface.VMIPNet = ipNet

// Gateway for now is just x.x.x.1 TODO: Better detection
dhcpIface.GatewayIP = &net.IP{ipNet.IP[0], ipNet.IP[1], ipNet.IP[2], 1}
dhcpIface.VMIPNet = ipNet
*dhcpIfaces = append(*dhcpIfaces, *dhcpIface)

*dhcpIfaces = append(*dhcpIfaces, *dhcpIface)
}
// This is an interface we care about
interfacesCount++
}

// If there weren't any interfaces we cared about, retry the loop
// If there weren't any interfaces that were valid or active yet, retry the loop
if interfacesCount == 0 {
return true, fmt.Errorf("no active interfaces available yet")
return true, fmt.Errorf("no active or valid interfaces available yet")
}

return false, nil
Expand Down