Skip to content

Commit

Permalink
fix: networkd updates for Packet, hostname detection, console kernel arg
Browse files Browse the repository at this point in the history
fix: bring up bonded interfaces correctly on packet

This probably fixes bonding in general if 2nd link in the bond is down.

For packet, set additional options for the bonded interface. In
networkd, add interfaces filtered out by link status as ignored to make
them available as bond subinterfaces.

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
(cherry picked from commit 5325a66)

fix: allow 'console' argument in kernel args to be always overridden

Fixes #3011

See also siderolabs/go-procfs#8

We don't want to allow all the kernel args to be overridden, as this
might compromise KSPP, but we would rather allow some args to be
overridden explicitly.

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
(cherry picked from commit d19486a)

fix: pick first interface valid hostname (vs. last one)

Looks like the code before change in #1578 returned the first hostname
found while interating over interfaces and addressing methods, but #1578
supposedly inadvertently flipped that to iterate over all interfaces (so
last interface wins).

Problem is that both `DHCP` and `Static` addressing methods provide
hostnames, while DHCP hostname comes from DHCP server, while `Static`
defines hostname as `talos-10-5-0-2` (by IP).

If we were to fix it for real, we should build a list of hostname with
priorities coming from different sources and pick a hostname with the
highest priority, so this fix is more of a bandaid rather than a real
fix.

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
(cherry picked from commit af5c34b)

refactor: define default kernel flags in machinery instead of procfs

That change should make Talos updates more straightforward in any
projects that depend on Talos.

Signed-off-by: Artem Chernyshev <artem.0xD2@gmail.com>
(cherry picked from commit 7b6c4bc)
  • Loading branch information
smira committed Jan 12, 2021
1 parent cf5226a commit d8646df
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 14 deletions.
7 changes: 5 additions & 2 deletions cmd/installer/pkg/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/bootloader/grub"
"github.com/talos-systems/talos/internal/pkg/mount"
"github.com/talos-systems/talos/pkg/machinery/constants"
"github.com/talos-systems/talos/pkg/machinery/kernel"
"github.com/talos-systems/talos/pkg/version"
)

Expand Down Expand Up @@ -48,9 +49,11 @@ func Install(p runtime.Platform, seq runtime.Sequence, opts *Options) (err error
cmdline.SetAll(p.KernelArgs().Strings())

// first defaults, then extra kernel args to allow extra kernel args to override defaults
cmdline.AppendDefaults()
if err = cmdline.AppendAll(kernel.DefaultArgs); err != nil {
return err
}

if err = cmdline.AppendAll(opts.ExtraKernelArgs); err != nil {
if err = cmdline.AppendAll(opts.ExtraKernelArgs, procfs.WithOverwriteArgs("console")); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ require (
github.com/talos-systems/crypto v0.2.1-0.20201203131813-e0dd56ac4745
github.com/talos-systems/go-blockdevice v0.1.1-0.20201218174450-f2728a581972
github.com/talos-systems/go-loadbalancer v0.1.0
github.com/talos-systems/go-procfs v0.0.0-20201223150035-a82654edcec1
github.com/talos-systems/go-procfs v0.0.0-20210108152626-8cbc42d3dc24
github.com/talos-systems/go-retry v0.1.1-0.20201113203059-8c63d290a688
github.com/talos-systems/go-smbios v0.0.0-20200807005123-80196199691e
github.com/talos-systems/grpc-proxy v0.2.0
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -933,10 +933,8 @@ github.com/talos-systems/go-blockdevice v0.1.1-0.20201218174450-f2728a581972 h1:
github.com/talos-systems/go-blockdevice v0.1.1-0.20201218174450-f2728a581972/go.mod h1:efEE9wjtgxiovqsZAV39xlOd/AOI/0sLuZqb5jEgeqo=
github.com/talos-systems/go-loadbalancer v0.1.0 h1:MQFONvSjoleU8RrKq1O1Z8CyTCJGd4SLqdAHDlR6o9s=
github.com/talos-systems/go-loadbalancer v0.1.0/go.mod h1:D5Qjfz+29WVjONWECZvOkmaLsBb3f5YeWME0u/5HmIc=
github.com/talos-systems/go-procfs v0.0.0-20201210152942-5a9a4a75d559 h1:wHuwJhQa20pD0Re+Ucpr0ec+om/b0GgPcpvTwRHSR3o=
github.com/talos-systems/go-procfs v0.0.0-20201210152942-5a9a4a75d559/go.mod h1:ATyUGFQIW8OnbnmvqefZWVPgL9g+CAmXHfkgny21xX8=
github.com/talos-systems/go-procfs v0.0.0-20201223150035-a82654edcec1 h1:n6q6VlyJp5yyCAzUyds+CFDLW6iDvTDSDXoI3NoXpcs=
github.com/talos-systems/go-procfs v0.0.0-20201223150035-a82654edcec1/go.mod h1:ATyUGFQIW8OnbnmvqefZWVPgL9g+CAmXHfkgny21xX8=
github.com/talos-systems/go-procfs v0.0.0-20210108152626-8cbc42d3dc24 h1:fN8vYvlB9XBQ5aImb1vLgR0ZaDwvfZfBMptqkpi3aEg=
github.com/talos-systems/go-procfs v0.0.0-20210108152626-8cbc42d3dc24/go.mod h1:ATyUGFQIW8OnbnmvqefZWVPgL9g+CAmXHfkgny21xX8=
github.com/talos-systems/go-retry v0.1.0/go.mod h1:HiXQqyVStZ35uSY/MTLWVvQVmC3lIW2MS5VdDaMtoKM=
github.com/talos-systems/go-retry v0.1.1-0.20201113203059-8c63d290a688 h1:U5wFGj5LXt/r+qfy1nGftQxJvEbg/lVJuasHKtk3K7s=
github.com/talos-systems/go-retry v0.1.1-0.20201113203059-8c63d290a688/go.mod h1:HiXQqyVStZ35uSY/MTLWVvQVmC3lIW2MS5VdDaMtoKM=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,6 @@ func (p *Packet) Configuration(ctx context.Context) ([]byte, error) {
}

bondName = iface.Bond

// nb: currently only one interface is supported, as adding one more interface breaks networking
break
}

// create multiple bond devices and add them to device list.
Expand All @@ -168,6 +165,10 @@ func (p *Packet) Configuration(ctx context.Context) ([]byte, error) {
DeviceCIDR: fmt.Sprintf("%s/%d", addr.Address, addr.CIDR),
DeviceBond: &v1alpha1.Bond{
BondMode: bondMode.String(),
BondDownDelay: 200,
BondMIIMon: 100,
BondUpDelay: 200,
BondHashPolicy: "layer3+4",
BondInterfaces: devicesInBond,
},
}
Expand Down
14 changes: 12 additions & 2 deletions internal/app/networkd/pkg/networkd/networkd.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ func New(config config.Provider) (*Networkd, error) {
}
}

// add local interfaces which were filtered out with Ignore
for _, device := range localInterfaces {
if _, ok := netconf[device.Name]; !ok {
netconf[device.Name] = []nic.Option{nic.WithName(device.Name), nic.WithIgnore()}
}
}

interfaces := make(map[string]*nic.NetworkInterface)

// Create nic.NetworkInterface representation of the interface
Expand Down Expand Up @@ -303,6 +310,7 @@ func (n *Networkd) decideHostname() (hostname, domainname string, address net.IP

// Loop through address responses and use the first hostname
// and address response.
outer:
for _, intName := range interfaceNames {
iface := n.Interfaces[intName]

Expand All @@ -322,7 +330,7 @@ func (n *Networkd) decideHostname() (hostname, domainname string, address net.IP

address = method.Address().IP

break
break outer
}
}
}
Expand Down Expand Up @@ -400,7 +408,9 @@ func (n *Networkd) configureLinks(bonded bool) error {
count++

go func(netif *nic.NetworkInterface) {
log.Printf("setting up %s", netif.Name)
if !netif.IsIgnored() {
log.Printf("setting up %s", netif.Name)
}

errCh <- func() error {
// Ensure link exists
Expand Down
5 changes: 5 additions & 0 deletions internal/app/networkd/pkg/networkd/networkd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ func dhcpConfigFile() config.Provider {
{
DeviceInterface: "eth0",
},
{
DeviceInterface: "eth1",
DeviceCIDR: "192.168.0.10/24",
DeviceMTU: 9100,
},
},
},
},
Expand Down
23 changes: 23 additions & 0 deletions pkg/machinery/kernel/kernel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

package kernel

// DefaultArgs returns the Talos default kernel commandline options.
var DefaultArgs = []string{
"init_on_alloc=1",
"init_on_free=1",
"slab_nomerge=",
"pti=on",
"consoleblank=0",
// AWS recommends setting the nvme_core.io_timeout to the highest value possible.
// See https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/nvme-ebs-volumes.html.
"nvme_core.io_timeout=4294967295",
"random.trust_cpu=on",
// Disable rate limited printk
"printk.devkmsg=on",
"ima_template=ima-ng",
"ima_appraise=fix",
"ima_hash=sha512",
}
5 changes: 4 additions & 1 deletion pkg/provision/providers/firecracker/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"k8s.io/apimachinery/pkg/util/json"

"github.com/talos-systems/talos/pkg/machinery/constants"
"github.com/talos-systems/talos/pkg/machinery/kernel"
"github.com/talos-systems/talos/pkg/provision"
"github.com/talos-systems/talos/pkg/provision/providers/vm"
)
Expand Down Expand Up @@ -75,7 +76,9 @@ func (p *provisioner) createNode(state *vm.State, clusterReq provision.ClusterRe
return provision.NodeInfo{}, err
}

cmdline := procfs.NewDefaultCmdline()
cmdline := procfs.NewCmdline("")

cmdline.SetAll(kernel.DefaultArgs)

// required to get kernel console
cmdline.Append("console", "ttyS0")
Expand Down
5 changes: 4 additions & 1 deletion pkg/provision/providers/qemu/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/talos-systems/go-procfs/procfs"

"github.com/talos-systems/talos/pkg/machinery/constants"
"github.com/talos-systems/talos/pkg/machinery/kernel"
"github.com/talos-systems/talos/pkg/provision"
"github.com/talos-systems/talos/pkg/provision/providers/vm"
)
Expand Down Expand Up @@ -66,7 +67,9 @@ func (p *provisioner) createNode(state *vm.State, clusterReq provision.ClusterRe

defer logFile.Close() //nolint: errcheck

cmdline := procfs.NewDefaultCmdline()
cmdline := procfs.NewCmdline("")

cmdline.SetAll(kernel.DefaultArgs)

// backwards compatibility to boot initrd from Talos < 0.8
// we can remove it once we stop testing upgrades from versions < 0.8
Expand Down

0 comments on commit d8646df

Please sign in to comment.