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
8141a933
Unverified
Commit
8141a933
authored
Dec 01, 2021
by
Manuel Buil
Committed by
GitHub
Dec 01, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4550 from manuelbuil/improve_flannel_logging
Improve flannel code and logging
parents
d05c334a
7685da3e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
13 deletions
+18
-13
config.go
pkg/agent/config/config.go
+2
-2
setup.go
pkg/agent/flannel/setup.go
+14
-9
setup_test.go
pkg/agent/flannel/setup_test.go
+1
-1
types.go
pkg/daemons/config/types.go
+1
-1
No files found.
pkg/agent/config/config.go
View file @
8141a933
...
@@ -497,9 +497,9 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N
...
@@ -497,9 +497,9 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N
}
}
if
envInfo
.
FlannelConf
==
""
{
if
envInfo
.
FlannelConf
==
""
{
nodeConfig
.
FlannelConf
=
filepath
.
Join
(
envInfo
.
DataDir
,
"agent"
,
"etc"
,
"flannel"
,
"net-conf.json"
)
nodeConfig
.
FlannelConf
File
=
filepath
.
Join
(
envInfo
.
DataDir
,
"agent"
,
"etc"
,
"flannel"
,
"net-conf.json"
)
}
else
{
}
else
{
nodeConfig
.
FlannelConf
=
envInfo
.
FlannelConf
nodeConfig
.
FlannelConf
File
=
envInfo
.
FlannelConf
nodeConfig
.
FlannelConfOverride
=
true
nodeConfig
.
FlannelConfOverride
=
true
}
}
nodeConfig
.
AgentConfig
.
CNIBinDir
=
filepath
.
Dir
(
hostLocal
)
nodeConfig
.
AgentConfig
.
CNIBinDir
=
filepath
.
Dir
(
hostLocal
)
...
...
pkg/agent/flannel/setup.go
View file @
8141a933
...
@@ -89,8 +89,9 @@ func Prepare(ctx context.Context, nodeConfig *config.Node) error {
...
@@ -89,8 +89,9 @@ func Prepare(ctx context.Context, nodeConfig *config.Node) error {
}
}
func
Run
(
ctx
context
.
Context
,
nodeConfig
*
config
.
Node
,
nodes
typedcorev1
.
NodeInterface
)
error
{
func
Run
(
ctx
context
.
Context
,
nodeConfig
*
config
.
Node
,
nodes
typedcorev1
.
NodeInterface
)
error
{
logrus
.
Infof
(
"Starting flannel with backend %s"
,
nodeConfig
.
FlannelBackend
)
if
err
:=
waitForPodCIDR
(
ctx
,
nodeConfig
.
AgentConfig
.
NodeName
,
nodes
);
err
!=
nil
{
if
err
:=
waitForPodCIDR
(
ctx
,
nodeConfig
.
AgentConfig
.
NodeName
,
nodes
);
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"failed to wait for PodCIDR assignment"
)
return
errors
.
Wrap
(
err
,
"f
lannel f
ailed to wait for PodCIDR assignment"
)
}
}
netMode
,
err
:=
findNetMode
(
nodeConfig
.
AgentConfig
.
ClusterCIDRs
)
netMode
,
err
:=
findNetMode
(
nodeConfig
.
AgentConfig
.
ClusterCIDRs
)
...
@@ -98,7 +99,7 @@ func Run(ctx context.Context, nodeConfig *config.Node, nodes typedcorev1.NodeInt
...
@@ -98,7 +99,7 @@ func Run(ctx context.Context, nodeConfig *config.Node, nodes typedcorev1.NodeInt
return
errors
.
Wrap
(
err
,
"failed to check netMode for flannel"
)
return
errors
.
Wrap
(
err
,
"failed to check netMode for flannel"
)
}
}
go
func
()
{
go
func
()
{
err
:=
flannel
(
ctx
,
nodeConfig
.
FlannelIface
,
nodeConfig
.
FlannelConf
,
nodeConfig
.
AgentConfig
.
KubeConfigKubelet
,
netMode
)
err
:=
flannel
(
ctx
,
nodeConfig
.
FlannelIface
,
nodeConfig
.
FlannelConf
File
,
nodeConfig
.
AgentConfig
.
KubeConfigKubelet
,
netMode
)
if
err
!=
nil
&&
!
errors
.
Is
(
err
,
context
.
Canceled
)
{
if
err
!=
nil
&&
!
errors
.
Is
(
err
,
context
.
Canceled
)
{
logrus
.
Fatalf
(
"flannel exited: %v"
,
err
)
logrus
.
Fatalf
(
"flannel exited: %v"
,
err
)
}
}
...
@@ -125,11 +126,12 @@ func waitForPodCIDR(ctx context.Context, nodeName string, nodes typedcorev1.Node
...
@@ -125,11 +126,12 @@ func waitForPodCIDR(ctx context.Context, nodeName string, nodes typedcorev1.Node
break
break
}
}
}
}
logrus
.
Info
(
"PodCIDR assigned for node "
+
nodeName
)
logrus
.
Info
(
"
Flannel found
PodCIDR assigned for node "
+
nodeName
)
return
nil
return
nil
}
}
func
createCNIConf
(
dir
string
)
error
{
func
createCNIConf
(
dir
string
)
error
{
logrus
.
Debugf
(
"Creating the CNI conf in directory %s"
,
dir
)
if
dir
==
""
{
if
dir
==
""
{
return
nil
return
nil
}
}
...
@@ -138,11 +140,12 @@ func createCNIConf(dir string) error {
...
@@ -138,11 +140,12 @@ func createCNIConf(dir string) error {
}
}
func
createFlannelConf
(
nodeConfig
*
config
.
Node
)
error
{
func
createFlannelConf
(
nodeConfig
*
config
.
Node
)
error
{
if
nodeConfig
.
FlannelConf
==
""
{
logrus
.
Debugf
(
"Creating the flannel configuration for backend %s in file %s"
,
nodeConfig
.
FlannelBackend
,
nodeConfig
.
FlannelConfFile
)
return
nil
if
nodeConfig
.
FlannelConfFile
==
""
{
return
errors
.
New
(
"Flannel configuration not defined"
)
}
}
if
nodeConfig
.
FlannelConfOverride
{
if
nodeConfig
.
FlannelConfOverride
{
logrus
.
Infof
(
"Using custom flannel conf defined at %s"
,
nodeConfig
.
FlannelConf
)
logrus
.
Infof
(
"Using custom flannel conf defined at %s"
,
nodeConfig
.
FlannelConf
File
)
return
nil
return
nil
}
}
confJSON
:=
strings
.
ReplaceAll
(
flannelConf
,
"%CIDR%"
,
nodeConfig
.
AgentConfig
.
ClusterCIDR
.
String
())
confJSON
:=
strings
.
ReplaceAll
(
flannelConf
,
"%CIDR%"
,
nodeConfig
.
AgentConfig
.
ClusterCIDR
.
String
())
...
@@ -160,7 +163,7 @@ func createFlannelConf(nodeConfig *config.Node) error {
...
@@ -160,7 +163,7 @@ func createFlannelConf(nodeConfig *config.Node) error {
return
err
return
err
}
}
case
config
.
FlannelBackendWireguard
:
case
config
.
FlannelBackendWireguard
:
backendConf
=
strings
.
ReplaceAll
(
wireguardBackend
,
"%flannelConfDir%"
,
filepath
.
Dir
(
nodeConfig
.
FlannelConf
))
backendConf
=
strings
.
ReplaceAll
(
wireguardBackend
,
"%flannelConfDir%"
,
filepath
.
Dir
(
nodeConfig
.
FlannelConf
File
))
default
:
default
:
return
fmt
.
Errorf
(
"Cannot configure unknown flannel backend '%s'"
,
nodeConfig
.
FlannelBackend
)
return
fmt
.
Errorf
(
"Cannot configure unknown flannel backend '%s'"
,
nodeConfig
.
FlannelBackend
)
}
}
...
@@ -168,7 +171,7 @@ func createFlannelConf(nodeConfig *config.Node) error {
...
@@ -168,7 +171,7 @@ func createFlannelConf(nodeConfig *config.Node) error {
netMode
,
err
:=
findNetMode
(
nodeConfig
.
AgentConfig
.
ClusterCIDRs
)
netMode
,
err
:=
findNetMode
(
nodeConfig
.
AgentConfig
.
ClusterCIDRs
)
if
err
!=
nil
{
if
err
!=
nil
{
logrus
.
Fatalf
(
"
Error checking netMode"
)
logrus
.
Fatalf
(
"
Flannel error checking netMode: %v"
,
err
)
return
err
return
err
}
}
...
@@ -184,7 +187,9 @@ func createFlannelConf(nodeConfig *config.Node) error {
...
@@ -184,7 +187,9 @@ func createFlannelConf(nodeConfig *config.Node) error {
confJSON
=
strings
.
ReplaceAll
(
confJSON
,
"%DUALSTACK%"
,
"false"
)
confJSON
=
strings
.
ReplaceAll
(
confJSON
,
"%DUALSTACK%"
,
"false"
)
confJSON
=
strings
.
ReplaceAll
(
confJSON
,
"%CIDR_IPV6%"
,
emptyIPv6Network
)
confJSON
=
strings
.
ReplaceAll
(
confJSON
,
"%CIDR_IPV6%"
,
emptyIPv6Network
)
}
}
return
util
.
WriteFile
(
nodeConfig
.
FlannelConf
,
confJSON
)
logrus
.
Debugf
(
"The flannel configuration is %s"
,
confJSON
)
return
util
.
WriteFile
(
nodeConfig
.
FlannelConfFile
,
confJSON
)
}
}
func
setupStrongSwan
(
nodeConfig
*
config
.
Node
)
error
{
func
setupStrongSwan
(
nodeConfig
*
config
.
Node
)
error
{
...
...
pkg/agent/flannel/setup_test.go
View file @
8141a933
...
@@ -62,7 +62,7 @@ func Test_createFlannelConf(t *testing.T) {
...
@@ -62,7 +62,7 @@ func Test_createFlannelConf(t *testing.T) {
var
agent
=
config
.
Agent
{}
var
agent
=
config
.
Agent
{}
agent
.
ClusterCIDR
=
stringToCIDR
(
tt
.
args
)[
0
]
agent
.
ClusterCIDR
=
stringToCIDR
(
tt
.
args
)[
0
]
agent
.
ClusterCIDRs
=
stringToCIDR
(
tt
.
args
)
agent
.
ClusterCIDRs
=
stringToCIDR
(
tt
.
args
)
var
nodeConfig
=
&
config
.
Node
{
Docker
:
false
,
ContainerRuntimeEndpoint
:
""
,
NoFlannel
:
false
,
SELinux
:
false
,
FlannelBackend
:
"vxlan"
,
FlannelConf
:
"test_file"
,
FlannelConfOverride
:
false
,
FlannelIface
:
nil
,
Containerd
:
containerd
,
Images
:
""
,
AgentConfig
:
agent
,
Token
:
""
,
Certificate
:
nil
,
ServerHTTPSPort
:
0
}
var
nodeConfig
=
&
config
.
Node
{
Docker
:
false
,
ContainerRuntimeEndpoint
:
""
,
NoFlannel
:
false
,
SELinux
:
false
,
FlannelBackend
:
"vxlan"
,
FlannelConf
File
:
"test_file"
,
FlannelConfOverride
:
false
,
FlannelIface
:
nil
,
Containerd
:
containerd
,
Images
:
""
,
AgentConfig
:
agent
,
Token
:
""
,
Certificate
:
nil
,
ServerHTTPSPort
:
0
}
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
if
err
:=
createFlannelConf
(
nodeConfig
);
(
err
!=
nil
)
!=
tt
.
wantErr
{
if
err
:=
createFlannelConf
(
nodeConfig
);
(
err
!=
nil
)
!=
tt
.
wantErr
{
...
...
pkg/daemons/config/types.go
View file @
8141a933
...
@@ -31,7 +31,7 @@ type Node struct {
...
@@ -31,7 +31,7 @@ type Node struct {
NoFlannel
bool
NoFlannel
bool
SELinux
bool
SELinux
bool
FlannelBackend
string
FlannelBackend
string
FlannelConf
string
FlannelConf
File
string
FlannelConfOverride
bool
FlannelConfOverride
bool
FlannelIface
*
net
.
Interface
FlannelIface
*
net
.
Interface
Containerd
Containerd
Containerd
Containerd
...
...
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