Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
131f3bec
Unverified
Commit
131f3bec
authored
Jul 12, 2019
by
Erik Wilson
Committed by
GitHub
Jul 12, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #619 from erikwilson/node-ip-from-flannel-iface
Default node-ip from flannel-iface
parents
403e73ab
a1ce08d4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
0 deletions
+68
-0
agent.go
pkg/cli/agent/agent.go
+5
-0
server.go
pkg/cli/server/server.go
+6
-0
iface.go
pkg/netutil/iface.go
+57
-0
No files found.
pkg/cli/agent/agent.go
View file @
131f3bec
...
@@ -13,6 +13,7 @@ import (
...
@@ -13,6 +13,7 @@ import (
"github.com/rancher/k3s/pkg/agent"
"github.com/rancher/k3s/pkg/agent"
"github.com/rancher/k3s/pkg/cli/cmds"
"github.com/rancher/k3s/pkg/cli/cmds"
"github.com/rancher/k3s/pkg/datadir"
"github.com/rancher/k3s/pkg/datadir"
"github.com/rancher/k3s/pkg/netutil"
"github.com/sirupsen/logrus"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"github.com/urfave/cli"
)
)
...
@@ -56,6 +57,10 @@ func Run(ctx *cli.Context) error {
...
@@ -56,6 +57,10 @@ func Run(ctx *cli.Context) error {
return
fmt
.
Errorf
(
"--server is required"
)
return
fmt
.
Errorf
(
"--server is required"
)
}
}
if
cmds
.
AgentConfig
.
FlannelIface
!=
""
&&
cmds
.
AgentConfig
.
NodeIP
==
""
{
cmds
.
AgentConfig
.
NodeIP
=
netutil
.
GetIPFromInterface
(
cmds
.
AgentConfig
.
FlannelIface
)
}
logrus
.
Infof
(
"Starting k3s agent %s"
,
ctx
.
App
.
Version
)
logrus
.
Infof
(
"Starting k3s agent %s"
,
ctx
.
App
.
Version
)
dataDir
,
err
:=
datadir
.
LocalHome
(
cmds
.
AgentConfig
.
DataDir
,
cmds
.
AgentConfig
.
Rootless
)
dataDir
,
err
:=
datadir
.
LocalHome
(
cmds
.
AgentConfig
.
DataDir
,
cmds
.
AgentConfig
.
Rootless
)
...
...
pkg/cli/server/server.go
View file @
131f3bec
...
@@ -10,6 +10,8 @@ import (
...
@@ -10,6 +10,8 @@ import (
"strings"
"strings"
"time"
"time"
"github.com/rancher/k3s/pkg/netutil"
systemd
"github.com/coreos/go-systemd/daemon"
systemd
"github.com/coreos/go-systemd/daemon"
"github.com/docker/docker/pkg/reexec"
"github.com/docker/docker/pkg/reexec"
"github.com/natefinch/lumberjack"
"github.com/natefinch/lumberjack"
...
@@ -127,6 +129,10 @@ func run(app *cli.Context, cfg *cmds.Server) error {
...
@@ -127,6 +129,10 @@ func run(app *cli.Context, cfg *cmds.Server) error {
serverConfig
.
ControlConfig
.
AdvertisePort
=
cfg
.
AdvertisePort
serverConfig
.
ControlConfig
.
AdvertisePort
=
cfg
.
AdvertisePort
serverConfig
.
ControlConfig
.
BootstrapType
=
cfg
.
BootstrapType
serverConfig
.
ControlConfig
.
BootstrapType
=
cfg
.
BootstrapType
if
cmds
.
AgentConfig
.
FlannelIface
!=
""
&&
cmds
.
AgentConfig
.
NodeIP
==
""
{
cmds
.
AgentConfig
.
NodeIP
=
netutil
.
GetIPFromInterface
(
cmds
.
AgentConfig
.
FlannelIface
)
}
if
serverConfig
.
ControlConfig
.
AdvertiseIP
==
""
&&
cmds
.
AgentConfig
.
NodeIP
!=
""
{
if
serverConfig
.
ControlConfig
.
AdvertiseIP
==
""
&&
cmds
.
AgentConfig
.
NodeIP
!=
""
{
serverConfig
.
ControlConfig
.
AdvertiseIP
=
cmds
.
AgentConfig
.
NodeIP
serverConfig
.
ControlConfig
.
AdvertiseIP
=
cmds
.
AgentConfig
.
NodeIP
}
}
...
...
pkg/netutil/iface.go
0 → 100644
View file @
131f3bec
package
netutil
import
(
"fmt"
"net"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
func
GetIPFromInterface
(
ifaceName
string
)
string
{
ip
,
err
:=
getIPFromInterface
(
ifaceName
)
if
err
!=
nil
{
logrus
.
Warn
(
errors
.
Wrap
(
err
,
"unable to get global unicast ip from interface name"
))
}
else
{
logrus
.
Infof
(
"found ip %s from iface %s"
,
ip
,
ifaceName
)
}
return
ip
}
func
getIPFromInterface
(
ifaceName
string
)
(
string
,
error
)
{
iface
,
err
:=
net
.
InterfaceByName
(
ifaceName
)
if
err
!=
nil
{
return
""
,
err
}
addrs
,
err
:=
iface
.
Addrs
()
if
err
!=
nil
{
return
""
,
err
}
if
iface
.
Flags
&
net
.
FlagUp
==
0
{
return
""
,
fmt
.
Errorf
(
"the interface %s is not up"
,
ifaceName
)
}
globalUnicasts
:=
[]
string
{}
for
_
,
addr
:=
range
addrs
{
ip
,
_
,
err
:=
net
.
ParseCIDR
(
addr
.
String
())
if
err
!=
nil
{
return
""
,
errors
.
Wrapf
(
err
,
"unable to parse CIDR for interface %s"
,
iface
.
Name
)
}
// skipping if not ipv4
if
ip
.
To4
()
==
nil
{
continue
}
if
ip
.
IsGlobalUnicast
()
{
globalUnicasts
=
append
(
globalUnicasts
,
ip
.
String
())
}
}
if
len
(
globalUnicasts
)
>
1
{
return
""
,
fmt
.
Errorf
(
"multiple global unicast addresses defined for %s, please set ip from one of %v"
,
ifaceName
,
globalUnicasts
)
}
if
len
(
globalUnicasts
)
==
1
{
return
globalUnicasts
[
0
],
nil
}
return
""
,
fmt
.
Errorf
(
"can't find ip for interface %s"
,
ifaceName
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment