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
7685da3e
Commit
7685da3e
authored
Nov 20, 2021
by
Manuel Buil
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve flannel logging
Signed-off-by:
Manuel Buil
<
mbuil@suse.com
>
parent
d93c82f9
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 @
7685da3e
...
...
@@ -497,9 +497,9 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N
}
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
{
nodeConfig
.
FlannelConf
=
envInfo
.
FlannelConf
nodeConfig
.
FlannelConf
File
=
envInfo
.
FlannelConf
nodeConfig
.
FlannelConfOverride
=
true
}
nodeConfig
.
AgentConfig
.
CNIBinDir
=
filepath
.
Dir
(
hostLocal
)
...
...
pkg/agent/flannel/setup.go
View file @
7685da3e
...
...
@@ -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
{
logrus
.
Infof
(
"Starting flannel with backend %s"
,
nodeConfig
.
FlannelBackend
)
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
)
...
...
@@ -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"
)
}
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
)
{
logrus
.
Fatalf
(
"flannel exited: %v"
,
err
)
}
...
...
@@ -125,11 +126,12 @@ func waitForPodCIDR(ctx context.Context, nodeName string, nodes typedcorev1.Node
break
}
}
logrus
.
Info
(
"PodCIDR assigned for node "
+
nodeName
)
logrus
.
Info
(
"
Flannel found
PodCIDR assigned for node "
+
nodeName
)
return
nil
}
func
createCNIConf
(
dir
string
)
error
{
logrus
.
Debugf
(
"Creating the CNI conf in directory %s"
,
dir
)
if
dir
==
""
{
return
nil
}
...
...
@@ -138,11 +140,12 @@ func createCNIConf(dir string) error {
}
func
createFlannelConf
(
nodeConfig
*
config
.
Node
)
error
{
if
nodeConfig
.
FlannelConf
==
""
{
return
nil
logrus
.
Debugf
(
"Creating the flannel configuration for backend %s in file %s"
,
nodeConfig
.
FlannelBackend
,
nodeConfig
.
FlannelConfFile
)
if
nodeConfig
.
FlannelConfFile
==
""
{
return
errors
.
New
(
"Flannel configuration not defined"
)
}
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
}
confJSON
:=
strings
.
ReplaceAll
(
flannelConf
,
"%CIDR%"
,
nodeConfig
.
AgentConfig
.
ClusterCIDR
.
String
())
...
...
@@ -160,7 +163,7 @@ func createFlannelConf(nodeConfig *config.Node) error {
return
err
}
case
config
.
FlannelBackendWireguard
:
backendConf
=
strings
.
ReplaceAll
(
wireguardBackend
,
"%flannelConfDir%"
,
filepath
.
Dir
(
nodeConfig
.
FlannelConf
))
backendConf
=
strings
.
ReplaceAll
(
wireguardBackend
,
"%flannelConfDir%"
,
filepath
.
Dir
(
nodeConfig
.
FlannelConf
File
))
default
:
return
fmt
.
Errorf
(
"Cannot configure unknown flannel backend '%s'"
,
nodeConfig
.
FlannelBackend
)
}
...
...
@@ -168,7 +171,7 @@ func createFlannelConf(nodeConfig *config.Node) error {
netMode
,
err
:=
findNetMode
(
nodeConfig
.
AgentConfig
.
ClusterCIDRs
)
if
err
!=
nil
{
logrus
.
Fatalf
(
"
Error checking netMode"
)
logrus
.
Fatalf
(
"
Flannel error checking netMode: %v"
,
err
)
return
err
}
...
...
@@ -184,7 +187,9 @@ func createFlannelConf(nodeConfig *config.Node) error {
confJSON
=
strings
.
ReplaceAll
(
confJSON
,
"%DUALSTACK%"
,
"false"
)
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
{
...
...
pkg/agent/flannel/setup_test.go
View file @
7685da3e
...
...
@@ -62,7 +62,7 @@ func Test_createFlannelConf(t *testing.T) {
var
agent
=
config
.
Agent
{}
agent
.
ClusterCIDR
=
stringToCIDR
(
tt
.
args
)[
0
]
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
)
{
if
err
:=
createFlannelConf
(
nodeConfig
);
(
err
!=
nil
)
!=
tt
.
wantErr
{
...
...
pkg/daemons/config/types.go
View file @
7685da3e
...
...
@@ -31,7 +31,7 @@ type Node struct {
NoFlannel
bool
SELinux
bool
FlannelBackend
string
FlannelConf
string
FlannelConf
File
string
FlannelConfOverride
bool
FlannelIface
*
net
.
Interface
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