Skip to content

Commit

Permalink
Merge pull request k3s-io#8284 from manuelbuil/improveFlannelLogging
Browse files Browse the repository at this point in the history
Add context to flannel errors
  • Loading branch information
manuelbuil authored Sep 25, 2023
2 parents 56abe70 + 66cb106 commit 3194dc7
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions pkg/agent/flannel/flannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/flannel-io/flannel/pkg/ip"
"github.com/flannel-io/flannel/pkg/iptables"
"github.com/flannel-io/flannel/pkg/subnet/kube"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"golang.org/x/net/context"

Expand All @@ -49,7 +50,7 @@ var (
func flannel(ctx context.Context, flannelIface *net.Interface, flannelConf, kubeConfigFile string, flannelIPv6Masq bool, multiClusterCIDR bool, netMode int) error {
extIface, err := LookupExtInterface(flannelIface, netMode)
if err != nil {
return err
return errors.Wrap(err, "failed to find the interface")
}

sm, err := kube.NewSubnetManager(ctx,
Expand All @@ -60,31 +61,31 @@ func flannel(ctx context.Context, flannelIface *net.Interface, flannelConf, kube
false,
multiClusterCIDR)
if err != nil {
return err
return errors.Wrap(err, "failed to create the SubnetManager")
}

config, err := sm.GetNetworkConfig(ctx)
if err != nil {
return err
return errors.Wrap(err, "failed to get the network config")
}

// Create a backend manager then use it to create the backend and register the network with it.
bm := backend.NewManager(ctx, sm, extIface)

be, err := bm.GetBackend(config.BackendType)
if err != nil {
return err
return errors.Wrap(err, "failed to create the flannel backend")
}

bn, err := be.RegisterNetwork(ctx, &sync.WaitGroup{}, config)
if err != nil {
return err
return errors.Wrap(err, "failed to register flannel network")
}

if netMode == (ipv4+ipv6) || netMode == ipv4 {
net, err := config.GetFlannelNetwork(&bn.Lease().Subnet)
if err != nil {
return err
return errors.Wrap(err, "failed to get flannel network details")
}
iptables.CreateIP4Chain("nat", "FLANNEL-POSTRTG")
iptables.CreateIP4Chain("filter", "FLANNEL-FWD")
Expand All @@ -104,7 +105,7 @@ func flannel(ctx context.Context, flannelIface *net.Interface, flannelConf, kube
if config.IPv6Network.String() != emptyIPv6Network {
ip6net, err := config.GetFlannelIPv6Network(&bn.Lease().IPv6Subnet)
if err != nil {
return err
return errors.Wrap(err, "failed to get ipv6 flannel network details")
}
if flannelIPv6Masq {
logrus.Debugf("Creating IPv6 masquerading iptables rules for %s network", config.IPv6Network.String())
Expand Down Expand Up @@ -146,11 +147,11 @@ func LookupExtInterface(iface *net.Interface, netMode int) (*backend.ExternalInt
logrus.Debug("No interface defined for flannel in the config. Fetching the default gateway interface")
if netMode == ipv4 || netMode == (ipv4+ipv6) {
if iface, err = ip.GetDefaultGatewayInterface(); err != nil {
return nil, fmt.Errorf("failed to get default interface: %s", err)
return nil, errors.Wrap(err, "failed to get default interface")
}
} else {
if iface, err = ip.GetDefaultV6GatewayInterface(); err != nil {
return nil, fmt.Errorf("failed to get default interface: %s", err)
return nil, errors.Wrap(err, "failed to get default interface")
}
}
}
Expand All @@ -160,14 +161,14 @@ func LookupExtInterface(iface *net.Interface, netMode int) (*backend.ExternalInt
case ipv4:
ifaceAddr, err = ip.GetInterfaceIP4Addrs(iface)
if err != nil {
return nil, fmt.Errorf("failed to find IPv4 address for interface %s", iface.Name)
return nil, errors.Wrap(err, "failed to find IPv4 address for interface")
}
logrus.Infof("The interface %s with ipv4 address %s will be used by flannel", iface.Name, ifaceAddr[0])
ifacev6Addr = append(ifacev6Addr, nil)
case ipv6:
ifacev6Addr, err = ip.GetInterfaceIP6Addrs(iface)
if err != nil {
return nil, fmt.Errorf("failed to find IPv6 address for interface %s", iface.Name)
return nil, errors.Wrap(err, "failed to find IPv6 address for interface")
}
logrus.Infof("The interface %s with ipv6 address %s will be used by flannel", iface.Name, ifacev6Addr[0])
ifaceAddr = append(ifaceAddr, nil)
Expand Down

0 comments on commit 3194dc7

Please sign in to comment.