|
|
@ -25,6 +25,7 @@ import (
|
|
|
|
"github.com/flannel-io/flannel/pkg/ip"
|
|
|
|
"github.com/flannel-io/flannel/pkg/ip"
|
|
|
|
"github.com/flannel-io/flannel/pkg/iptables"
|
|
|
|
"github.com/flannel-io/flannel/pkg/iptables"
|
|
|
|
"github.com/flannel-io/flannel/pkg/subnet/kube"
|
|
|
|
"github.com/flannel-io/flannel/pkg/subnet/kube"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
|
|
|
|
|
|
|
@ -49,7 +50,7 @@ var (
|
|
|
|
func flannel(ctx context.Context, flannelIface *net.Interface, flannelConf, kubeConfigFile string, flannelIPv6Masq bool, multiClusterCIDR bool, netMode int) error {
|
|
|
|
func flannel(ctx context.Context, flannelIface *net.Interface, flannelConf, kubeConfigFile string, flannelIPv6Masq bool, multiClusterCIDR bool, netMode int) error {
|
|
|
|
extIface, err := LookupExtInterface(flannelIface, netMode)
|
|
|
|
extIface, err := LookupExtInterface(flannelIface, netMode)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return errors.Wrap(err, "failed to find the interface")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sm, err := kube.NewSubnetManager(ctx,
|
|
|
|
sm, err := kube.NewSubnetManager(ctx,
|
|
|
@ -60,12 +61,12 @@ func flannel(ctx context.Context, flannelIface *net.Interface, flannelConf, kube
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
multiClusterCIDR)
|
|
|
|
multiClusterCIDR)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return errors.Wrap(err, "failed to create the SubnetManager")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
config, err := sm.GetNetworkConfig(ctx)
|
|
|
|
config, err := sm.GetNetworkConfig(ctx)
|
|
|
|
if err != nil {
|
|
|
|
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.
|
|
|
|
// Create a backend manager then use it to create the backend and register the network with it.
|
|
|
@ -73,18 +74,18 @@ func flannel(ctx context.Context, flannelIface *net.Interface, flannelConf, kube
|
|
|
|
|
|
|
|
|
|
|
|
be, err := bm.GetBackend(config.BackendType)
|
|
|
|
be, err := bm.GetBackend(config.BackendType)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return errors.Wrap(err, "failed to create the flannel backend")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bn, err := be.RegisterNetwork(ctx, &sync.WaitGroup{}, config)
|
|
|
|
bn, err := be.RegisterNetwork(ctx, &sync.WaitGroup{}, config)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return errors.Wrap(err, "failed to register flannel network")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if netMode == (ipv4+ipv6) || netMode == ipv4 {
|
|
|
|
if netMode == (ipv4+ipv6) || netMode == ipv4 {
|
|
|
|
net, err := config.GetFlannelNetwork(&bn.Lease().Subnet)
|
|
|
|
net, err := config.GetFlannelNetwork(&bn.Lease().Subnet)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return errors.Wrap(err, "failed to get flannel network details")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
iptables.CreateIP4Chain("nat", "FLANNEL-POSTRTG")
|
|
|
|
iptables.CreateIP4Chain("nat", "FLANNEL-POSTRTG")
|
|
|
|
iptables.CreateIP4Chain("filter", "FLANNEL-FWD")
|
|
|
|
iptables.CreateIP4Chain("filter", "FLANNEL-FWD")
|
|
|
@ -104,7 +105,7 @@ func flannel(ctx context.Context, flannelIface *net.Interface, flannelConf, kube
|
|
|
|
if config.IPv6Network.String() != emptyIPv6Network {
|
|
|
|
if config.IPv6Network.String() != emptyIPv6Network {
|
|
|
|
ip6net, err := config.GetFlannelIPv6Network(&bn.Lease().IPv6Subnet)
|
|
|
|
ip6net, err := config.GetFlannelIPv6Network(&bn.Lease().IPv6Subnet)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return errors.Wrap(err, "failed to get ipv6 flannel network details")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if flannelIPv6Masq {
|
|
|
|
if flannelIPv6Masq {
|
|
|
|
logrus.Debugf("Creating IPv6 masquerading iptables rules for %s network", config.IPv6Network.String())
|
|
|
|
logrus.Debugf("Creating IPv6 masquerading iptables rules for %s network", config.IPv6Network.String())
|
|
|
@ -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")
|
|
|
|
logrus.Debug("No interface defined for flannel in the config. Fetching the default gateway interface")
|
|
|
|
if netMode == ipv4 || netMode == (ipv4+ipv6) {
|
|
|
|
if netMode == ipv4 || netMode == (ipv4+ipv6) {
|
|
|
|
if iface, err = ip.GetDefaultGatewayInterface(); err != nil {
|
|
|
|
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 {
|
|
|
|
} else {
|
|
|
|
if iface, err = ip.GetDefaultV6GatewayInterface(); err != nil {
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -160,14 +161,14 @@ func LookupExtInterface(iface *net.Interface, netMode int) (*backend.ExternalInt
|
|
|
|
case ipv4:
|
|
|
|
case ipv4:
|
|
|
|
ifaceAddr, err = ip.GetInterfaceIP4Addrs(iface)
|
|
|
|
ifaceAddr, err = ip.GetInterfaceIP4Addrs(iface)
|
|
|
|
if err != nil {
|
|
|
|
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])
|
|
|
|
logrus.Infof("The interface %s with ipv4 address %s will be used by flannel", iface.Name, ifaceAddr[0])
|
|
|
|
ifacev6Addr = append(ifacev6Addr, nil)
|
|
|
|
ifacev6Addr = append(ifacev6Addr, nil)
|
|
|
|
case ipv6:
|
|
|
|
case ipv6:
|
|
|
|
ifacev6Addr, err = ip.GetInterfaceIP6Addrs(iface)
|
|
|
|
ifacev6Addr, err = ip.GetInterfaceIP6Addrs(iface)
|
|
|
|
if err != nil {
|
|
|
|
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])
|
|
|
|
logrus.Infof("The interface %s with ipv6 address %s will be used by flannel", iface.Name, ifacev6Addr[0])
|
|
|
|
ifaceAddr = append(ifaceAddr, nil)
|
|
|
|
ifaceAddr = append(ifaceAddr, nil)
|
|
|
|