Merge pull request #250 from yoink00/master

Allow flannel interface to be specified on the command line
This commit is contained in:
Darren Shepherd 2019-04-15 10:01:22 -07:00 committed by GitHub
commit 08c3d0d4ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 8 deletions

View File

@ -206,11 +206,20 @@ func get(envInfo *cmds.Agent) (*config.Node, error) {
return nil, errors.Wrapf(err, "failed to find host-local") return nil, errors.Wrapf(err, "failed to find host-local")
} }
var flannelIface *sysnet.Interface
if !envInfo.NoFlannel && len(envInfo.FlannelIface) > 0 {
flannelIface, err = sysnet.InterfaceByName(envInfo.FlannelIface)
if err != nil {
return nil, errors.Wrapf(err, "unable to find interface")
}
}
nodeConfig := &config.Node{ nodeConfig := &config.Node{
Docker: envInfo.Docker, Docker: envInfo.Docker,
NoFlannel: envInfo.NoFlannel, NoFlannel: envInfo.NoFlannel,
ContainerRuntimeEndpoint: envInfo.ContainerRuntimeEndpoint, ContainerRuntimeEndpoint: envInfo.ContainerRuntimeEndpoint,
} }
nodeConfig.FlannelIface = flannelIface
nodeConfig.LocalAddress = localAddress(controlConfig) nodeConfig.LocalAddress = localAddress(controlConfig)
nodeConfig.Images = filepath.Join(envInfo.DataDir, "images") nodeConfig.Images = filepath.Join(envInfo.DataDir, "images")
nodeConfig.AgentConfig.NodeIP = nodeIP nodeConfig.AgentConfig.NodeIP = nodeIP

View File

@ -36,8 +36,8 @@ const (
subnetFile = "/run/flannel/subnet.env" subnetFile = "/run/flannel/subnet.env"
) )
func flannel(ctx context.Context, flannelConf, kubeConfigFile string) error { func flannel(ctx context.Context, flannelIface *net.Interface, flannelConf, kubeConfigFile string) error {
extIface, err := LookupExtIface() extIface, err := LookupExtIface(flannelIface)
if err != nil { if err != nil {
return err return err
} }
@ -81,15 +81,18 @@ func flannel(ctx context.Context, flannelConf, kubeConfigFile string) error {
return nil return nil
} }
func LookupExtIface() (*backend.ExternalInterface, error) { func LookupExtIface(iface *net.Interface) (*backend.ExternalInterface, error) {
var iface *net.Interface
var ifaceAddr net.IP var ifaceAddr net.IP
var err error var err error
if iface == nil {
log.Info("Determining IP address of default interface") log.Info("Determining IP address of default interface")
if iface, err = ip.GetDefaultGatewayIface(); err != nil { if iface, err = ip.GetDefaultGatewayIface(); err != nil {
return nil, fmt.Errorf("failed to get default interface: %s", err) return nil, fmt.Errorf("failed to get default interface: %s", err)
} }
} else {
log.Info("Determining IP address of specified interface: ", iface.Name)
}
ifaceAddr, err = ip.GetIfaceIP4Addr(iface) ifaceAddr, err = ip.GetIfaceIP4Addr(iface)
if err != nil { if err != nil {

View File

@ -79,7 +79,7 @@ func Run(ctx context.Context, config *config.Node) error {
} }
go func() { go func() {
err := flannel(ctx, config.FlannelConf, config.AgentConfig.KubeConfig) err := flannel(ctx, config.FlannelIface, config.FlannelConf, config.AgentConfig.KubeConfig)
logrus.Fatalf("flannel exited: %v", err) logrus.Fatalf("flannel exited: %v", err)
}() }()

View File

@ -19,6 +19,7 @@ type Agent struct {
Docker bool Docker bool
ContainerRuntimeEndpoint string ContainerRuntimeEndpoint string
NoFlannel bool NoFlannel bool
FlannelIface string
Debug bool Debug bool
Rootless bool Rootless bool
AgentShared AgentShared
@ -54,6 +55,11 @@ var (
Usage: "(agent) Disable embedded flannel", Usage: "(agent) Disable embedded flannel",
Destination: &AgentConfig.NoFlannel, Destination: &AgentConfig.NoFlannel,
} }
FlannelIfaceFlag = cli.StringFlag{
Name: "flannel-iface",
Usage: "(agent) Override default flannel interface",
Destination: &AgentConfig.FlannelIface,
}
CRIEndpointFlag = cli.StringFlag{ CRIEndpointFlag = cli.StringFlag{
Name: "container-runtime-endpoint", Name: "container-runtime-endpoint",
Usage: "(agent) Disable embedded containerd and use alternative CRI implementation", Usage: "(agent) Disable embedded containerd and use alternative CRI implementation",
@ -121,6 +127,7 @@ func NewAgentCommand(action func(ctx *cli.Context) error) cli.Command {
}, },
DockerFlag, DockerFlag,
FlannelFlag, FlannelFlag,
FlannelIfaceFlag,
NodeNameFlag, NodeNameFlag,
NodeIPFlag, NodeIPFlag,
CRIEndpointFlag, CRIEndpointFlag,

View File

@ -134,6 +134,7 @@ func NewServerCommand(action func(*cli.Context) error) cli.Command {
NodeNameFlag, NodeNameFlag,
DockerFlag, DockerFlag,
FlannelFlag, FlannelFlag,
FlannelIfaceFlag,
CRIEndpointFlag, CRIEndpointFlag,
ResolvConfFlag, ResolvConfFlag,
ExtraKubeletArgs, ExtraKubeletArgs,

View File

@ -15,6 +15,7 @@ type Node struct {
ContainerRuntimeEndpoint string ContainerRuntimeEndpoint string
NoFlannel bool NoFlannel bool
FlannelConf string FlannelConf string
FlannelIface *net.Interface
LocalAddress string LocalAddress string
Containerd Containerd Containerd Containerd
Images string Images string