feat(initramfs): Add kernel arg for default interface

Should allow us to handle edge cases where eth0 is not the primary interface

Signed-off-by: Brad Beam <brad.beam@talos-systems.com>
This commit is contained in:
Brad Beam 2019-07-03 16:26:12 -05:00 committed by Andrew Rynhard
parent 8d9dde97fa
commit c194621e56
3 changed files with 19 additions and 4 deletions

View File

@ -39,7 +39,7 @@ func (svc *Service) Main(ctx context.Context, data *userdata.UserData, logWriter
wg.Add(1)
go func() {
defer wg.Done()
svc.DHCPd(ctx, DefaultInterface)
svc.DHCPd(ctx, defaultInterface())
}()
} else {
for _, netconf := range data.Networking.OS.Devices {

View File

@ -10,6 +10,8 @@ import (
"syscall"
"github.com/pkg/errors"
"github.com/talos-systems/talos/internal/pkg/constants"
"github.com/talos-systems/talos/internal/pkg/kernel"
"github.com/talos-systems/talos/pkg/userdata"
"github.com/vishvananda/netlink"
)
@ -75,12 +77,12 @@ func defaultNetworkSetup() (err error) {
if err = StaticAddress(userdata.Device{Interface: "lo", CIDR: "127.0.0.1/8"}); err != nil && err != syscall.EEXIST {
return err
}
if err = ifup(DefaultInterface); err != nil {
if err = ifup(defaultInterface()); err != nil {
return err
}
// TODO: this calls out to 'networkd' inline
if _, err = NewService().Dhclient(context.Background(), DefaultInterface); err != nil {
if _, err = NewService().Dhclient(context.Background(), defaultInterface()); err != nil {
return err
}
@ -109,3 +111,12 @@ func ifup(ifname string) (err error) {
return nil
}
func defaultInterface() string {
netif := DefaultInterface
if option := kernel.Cmdline().Get(constants.KernelParamDefaultInterface).First(); option != nil {
netif = *option
}
return netif
}

View File

@ -26,6 +26,10 @@ const (
// hostname.
KernelParamHostname = "talos.hostname"
// KernelParamDefaultInterface is the kernel parameter for specifying the
// initial interface used to bootstrap the node
KernelParamDefaultInterface = "talos.interface"
// KernelCurrentRoot is the kernel parameter name for specifying the
// current root partition.
KernelCurrentRoot = "talos.root"