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
073f155f
Commit
073f155f
authored
Mar 04, 2022
by
Roberto Bonafiglia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added ipv6 only support with flannel
Signed-off-by:
Roberto Bonafiglia
<
roberto.bonafiglia@suse.com
>
parent
93346904
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
32 deletions
+54
-32
flannel.go
pkg/agent/flannel/flannel.go
+18
-9
setup.go
pkg/agent/flannel/setup.go
+36
-20
server.go
pkg/cli/server/server.go
+0
-3
No files found.
pkg/agent/flannel/flannel.go
View file @
073f155f
...
...
@@ -68,8 +68,10 @@ func flannel(ctx context.Context, flannelIface *net.Interface, flannelConf, kube
return
err
}
go
network
.
SetupAndEnsureIPTables
(
network
.
MasqRules
(
config
.
Network
,
bn
.
Lease
()),
60
)
go
network
.
SetupAndEnsureIPTables
(
network
.
ForwardRules
(
config
.
Network
.
String
()),
50
)
if
netMode
==
(
ipv4
+
ipv6
)
||
netMode
==
ipv4
{
go
network
.
SetupAndEnsureIPTables
(
network
.
MasqRules
(
config
.
Network
,
bn
.
Lease
()),
60
)
go
network
.
SetupAndEnsureIPTables
(
network
.
ForwardRules
(
config
.
Network
.
String
()),
50
)
}
if
flannelIPv6Masq
&&
config
.
IPv6Network
.
String
()
!=
emptyIPv6Network
{
logrus
.
Debugf
(
"Creating IPv6 masquerading iptables rules for %s network"
,
config
.
IPv6Network
.
String
())
...
...
@@ -77,7 +79,7 @@ func flannel(ctx context.Context, flannelIface *net.Interface, flannelConf, kube
go
network
.
SetupAndEnsureIP6Tables
(
network
.
ForwardRules
(
config
.
IPv6Network
.
String
()),
50
)
}
if
err
:=
WriteSubnetFile
(
subnetFile
,
config
.
Network
,
config
.
IPv6Network
,
true
,
bn
);
err
!=
nil
{
if
err
:=
WriteSubnetFile
(
subnetFile
,
config
.
Network
,
config
.
IPv6Network
,
true
,
bn
,
netMode
);
err
!=
nil
{
// Continue, even though it failed.
logrus
.
Warningf
(
"Failed to write flannel subnet file: %s"
,
err
)
}
else
{
...
...
@@ -97,8 +99,14 @@ func LookupExtInterface(iface *net.Interface, netMode int) (*backend.ExternalInt
if
iface
==
nil
{
logrus
.
Debug
(
"No interface defined for flannel in the config. Fetching the default gateway interface"
)
if
iface
,
err
=
ip
.
GetDefaultGatewayInterface
();
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to get default interface: %s"
,
err
)
if
netMode
==
ipv4
||
netMode
==
(
ipv4
+
ipv6
)
{
if
iface
,
err
=
ip
.
GetDefaultGatewayInterface
();
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to get default interface: %s"
,
err
)
}
}
else
{
if
iface
,
err
=
ip
.
GetDefaultV6GatewayInterface
();
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to get default interface: %s"
,
err
)
}
}
}
logrus
.
Debugf
(
"The interface %s will be used by flannel"
,
iface
.
Name
)
...
...
@@ -147,7 +155,7 @@ func LookupExtInterface(iface *net.Interface, netMode int) (*backend.ExternalInt
},
nil
}
func
WriteSubnetFile
(
path
string
,
nw
ip
.
IP4Net
,
nwv6
ip
.
IP6Net
,
ipMasq
bool
,
bn
backend
.
Network
)
error
{
func
WriteSubnetFile
(
path
string
,
nw
ip
.
IP4Net
,
nwv6
ip
.
IP6Net
,
ipMasq
bool
,
bn
backend
.
Network
,
netMode
int
)
error
{
dir
,
name
:=
filepath
.
Split
(
path
)
os
.
MkdirAll
(
dir
,
0755
)
...
...
@@ -161,9 +169,10 @@ func WriteSubnetFile(path string, nw ip.IP4Net, nwv6 ip.IP6Net, ipMasq bool, bn
// sn.IP by one
sn
:=
bn
.
Lease
()
.
Subnet
sn
.
IP
++
fmt
.
Fprintf
(
f
,
"FLANNEL_NETWORK=%s
\n
"
,
nw
)
fmt
.
Fprintf
(
f
,
"FLANNEL_SUBNET=%s
\n
"
,
sn
)
if
netMode
==
ipv4
||
netMode
==
(
ipv4
+
ipv6
)
{
fmt
.
Fprintf
(
f
,
"FLANNEL_NETWORK=%s
\n
"
,
nw
)
fmt
.
Fprintf
(
f
,
"FLANNEL_SUBNET=%s
\n
"
,
sn
)
}
if
nwv6
.
String
()
!=
emptyIPv6Network
{
snv6
:=
bn
.
Lease
()
.
IPv6Subnet
...
...
pkg/agent/flannel/setup.go
View file @
073f155f
...
...
@@ -46,6 +46,7 @@ const (
flannelConf
=
`{
"Network": "%CIDR%",
"EnableIPv6": %DUALSTACK%,
"EnableIPv4": %IPV4_ENABLED%,
"IPv6Network": "%CIDR_IPV6%",
"Backend": %backend%
}
...
...
@@ -140,6 +141,7 @@ func createCNIConf(dir string) error {
}
func
createFlannelConf
(
nodeConfig
*
config
.
Node
)
error
{
var
ipv4Enabled
string
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"
)
...
...
@@ -148,7 +150,40 @@ func createFlannelConf(nodeConfig *config.Node) error {
logrus
.
Infof
(
"Using custom flannel conf defined at %s"
,
nodeConfig
.
FlannelConfFile
)
return
nil
}
confJSON
:=
strings
.
ReplaceAll
(
flannelConf
,
"%CIDR%"
,
nodeConfig
.
AgentConfig
.
ClusterCIDR
.
String
())
netMode
,
err
:=
findNetMode
(
nodeConfig
.
AgentConfig
.
ClusterCIDRs
)
if
err
!=
nil
{
logrus
.
Fatalf
(
"Flannel error checking netMode: %v"
,
err
)
return
err
}
if
netMode
==
ipv4
||
netMode
==
(
ipv4
+
ipv6
)
{
ipv4Enabled
=
"true"
}
else
{
ipv4Enabled
=
"false"
}
confJSON
:=
strings
.
ReplaceAll
(
flannelConf
,
"%IPV4_ENABLED%"
,
ipv4Enabled
)
if
netMode
==
ipv4
{
confJSON
=
strings
.
ReplaceAll
(
confJSON
,
"%CIDR%"
,
nodeConfig
.
AgentConfig
.
ClusterCIDR
.
String
())
confJSON
=
strings
.
ReplaceAll
(
confJSON
,
"%DUALSTACK%"
,
"false"
)
confJSON
=
strings
.
ReplaceAll
(
confJSON
,
"%CIDR_IPV6%"
,
emptyIPv6Network
)
}
else
if
netMode
==
(
ipv4
+
ipv6
)
{
confJSON
=
strings
.
ReplaceAll
(
confJSON
,
"%CIDR%"
,
nodeConfig
.
AgentConfig
.
ClusterCIDR
.
String
())
confJSON
=
strings
.
ReplaceAll
(
confJSON
,
"%DUALSTACK%"
,
"true"
)
for
_
,
cidr
:=
range
nodeConfig
.
AgentConfig
.
ClusterCIDRs
{
if
utilsnet
.
IsIPv6
(
cidr
.
IP
)
{
// Only one ipv6 range available. This might change in future: https://github.com/kubernetes/enhancements/issues/2593
confJSON
=
strings
.
ReplaceAll
(
confJSON
,
"%CIDR_IPV6%"
,
cidr
.
String
())
}
}
}
else
{
confJSON
=
strings
.
ReplaceAll
(
confJSON
,
"%CIDR%"
,
"0.0.0.0/0"
)
confJSON
=
strings
.
ReplaceAll
(
confJSON
,
"%DUALSTACK%"
,
"true"
)
for
_
,
cidr
:=
range
nodeConfig
.
AgentConfig
.
ClusterCIDRs
{
if
utilsnet
.
IsIPv6
(
cidr
.
IP
)
{
// Only one ipv6 range available. This might change in future: https://github.com/kubernetes/enhancements/issues/2593
confJSON
=
strings
.
ReplaceAll
(
confJSON
,
"%CIDR_IPV6%"
,
cidr
.
String
())
}
}
}
var
backendConf
string
...
...
@@ -169,25 +204,6 @@ func createFlannelConf(nodeConfig *config.Node) error {
}
confJSON
=
strings
.
ReplaceAll
(
confJSON
,
"%backend%"
,
backendConf
)
netMode
,
err
:=
findNetMode
(
nodeConfig
.
AgentConfig
.
ClusterCIDRs
)
if
err
!=
nil
{
logrus
.
Fatalf
(
"Flannel error checking netMode: %v"
,
err
)
return
err
}
if
netMode
==
(
ipv4
+
ipv6
)
{
confJSON
=
strings
.
ReplaceAll
(
confJSON
,
"%DUALSTACK%"
,
"true"
)
for
_
,
cidr
:=
range
nodeConfig
.
AgentConfig
.
ClusterCIDRs
{
if
utilsnet
.
IsIPv6
(
cidr
.
IP
)
{
// Only one ipv6 range available. This might change in future: https://github.com/kubernetes/enhancements/issues/2593
confJSON
=
strings
.
ReplaceAll
(
confJSON
,
"%CIDR_IPV6%"
,
cidr
.
String
())
}
}
}
else
{
confJSON
=
strings
.
ReplaceAll
(
confJSON
,
"%DUALSTACK%"
,
"false"
)
confJSON
=
strings
.
ReplaceAll
(
confJSON
,
"%CIDR_IPV6%"
,
emptyIPv6Network
)
}
logrus
.
Debugf
(
"The flannel configuration is %s"
,
confJSON
)
return
util
.
WriteFile
(
nodeConfig
.
FlannelConfFile
,
confJSON
)
}
...
...
pkg/cli/server/server.go
View file @
073f155f
...
...
@@ -534,9 +534,6 @@ func validateNetworkConfiguration(serverConfig server.Config) error {
if
serverConfig
.
ControlConfig
.
DisableNPC
==
false
{
return
errors
.
New
(
"network policy enforcement is not compatible with IPv6 only operation; server must be restarted with --disable-network-policy"
)
}
if
serverConfig
.
ControlConfig
.
FlannelBackend
!=
config
.
FlannelBackendNone
{
return
errors
.
New
(
"Flannel is not compatible with IPv6 only operation; server must be restarted with --flannel-backend=none"
)
}
}
return
nil
...
...
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