Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow flannel interface to be specified on the command line #250

Merged
merged 1 commit into from
Apr 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pkg/agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,20 @@ func get(envInfo *cmds.Agent) (*config.Node, error) {
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{
Docker: envInfo.Docker,
NoFlannel: envInfo.NoFlannel,
ContainerRuntimeEndpoint: envInfo.ContainerRuntimeEndpoint,
}
nodeConfig.FlannelIface = flannelIface
nodeConfig.LocalAddress = localAddress(controlConfig)
nodeConfig.Images = filepath.Join(envInfo.DataDir, "images")
nodeConfig.AgentConfig.NodeIP = nodeIP
Expand Down
17 changes: 10 additions & 7 deletions pkg/agent/flannel/flannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ const (
subnetFile = "/run/flannel/subnet.env"
)

func flannel(ctx context.Context, flannelConf, kubeConfigFile string) error {
extIface, err := LookupExtIface()
func flannel(ctx context.Context, flannelIface *net.Interface, flannelConf, kubeConfigFile string) error {
extIface, err := LookupExtIface(flannelIface)
if err != nil {
return err
}
Expand Down Expand Up @@ -81,14 +81,17 @@ func flannel(ctx context.Context, flannelConf, kubeConfigFile string) error {
return nil
}

func LookupExtIface() (*backend.ExternalInterface, error) {
var iface *net.Interface
func LookupExtIface(iface *net.Interface) (*backend.ExternalInterface, error) {
var ifaceAddr net.IP
var err error

log.Info("Determining IP address of default interface")
if iface, err = ip.GetDefaultGatewayIface(); err != nil {
return nil, fmt.Errorf("failed to get default interface: %s", err)
if iface == nil {
log.Info("Determining IP address of default interface")
if iface, err = ip.GetDefaultGatewayIface(); err != nil {
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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/flannel/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func Run(ctx context.Context, config *config.Node) error {
}

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)
}()

Expand Down
7 changes: 7 additions & 0 deletions pkg/cli/cmds/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Agent struct {
Docker bool
ContainerRuntimeEndpoint string
NoFlannel bool
FlannelIface string
Debug bool
Rootless bool
AgentShared
Expand Down Expand Up @@ -54,6 +55,11 @@ var (
Usage: "(agent) Disable embedded flannel",
Destination: &AgentConfig.NoFlannel,
}
FlannelIfaceFlag = cli.StringFlag{
Name: "flannel-iface",
Usage: "(agent) Override default flannel interface",
Destination: &AgentConfig.FlannelIface,
}
CRIEndpointFlag = cli.StringFlag{
Name: "container-runtime-endpoint",
Usage: "(agent) Disable embedded containerd and use alternative CRI implementation",
Expand Down Expand Up @@ -121,6 +127,7 @@ func NewAgentCommand(action func(ctx *cli.Context) error) cli.Command {
},
DockerFlag,
FlannelFlag,
FlannelIfaceFlag,
NodeNameFlag,
NodeIPFlag,
CRIEndpointFlag,
Expand Down
1 change: 1 addition & 0 deletions pkg/cli/cmds/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ func NewServerCommand(action func(*cli.Context) error) cli.Command {
NodeNameFlag,
DockerFlag,
FlannelFlag,
FlannelIfaceFlag,
CRIEndpointFlag,
ResolvConfFlag,
ExtraKubeletArgs,
Expand Down
1 change: 1 addition & 0 deletions pkg/daemons/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Node struct {
ContainerRuntimeEndpoint string
NoFlannel bool
FlannelConf string
FlannelIface *net.Interface
LocalAddress string
Containerd Containerd
Images string
Expand Down