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
29c55f5e
Unverified
Commit
29c55f5e
authored
Mar 11, 2022
by
Roberto Bonafiglia
Committed by
GitHub
Mar 11, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5238 from rbrtbnfgl/ipv6-only-with-flannel
Added ipv6 only support with flannel
parents
93346904
ff85faa7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
33 deletions
+55
-33
flannel.go
pkg/agent/flannel/flannel.go
+18
-9
setup.go
pkg/agent/flannel/setup.go
+37
-21
server.go
pkg/cli/server/server.go
+0
-3
No files found.
pkg/agent/flannel/flannel.go
View file @
29c55f5e
...
@@ -68,8 +68,10 @@ func flannel(ctx context.Context, flannelIface *net.Interface, flannelConf, kube
...
@@ -68,8 +68,10 @@ func flannel(ctx context.Context, flannelIface *net.Interface, flannelConf, kube
return
err
return
err
}
}
go
network
.
SetupAndEnsureIPTables
(
network
.
MasqRules
(
config
.
Network
,
bn
.
Lease
()),
60
)
if
netMode
==
(
ipv4
+
ipv6
)
||
netMode
==
ipv4
{
go
network
.
SetupAndEnsureIPTables
(
network
.
ForwardRules
(
config
.
Network
.
String
()),
50
)
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
{
if
flannelIPv6Masq
&&
config
.
IPv6Network
.
String
()
!=
emptyIPv6Network
{
logrus
.
Debugf
(
"Creating IPv6 masquerading iptables rules for %s network"
,
config
.
IPv6Network
.
String
())
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
...
@@ -77,7 +79,7 @@ func flannel(ctx context.Context, flannelIface *net.Interface, flannelConf, kube
go
network
.
SetupAndEnsureIP6Tables
(
network
.
ForwardRules
(
config
.
IPv6Network
.
String
()),
50
)
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.
// Continue, even though it failed.
logrus
.
Warningf
(
"Failed to write flannel subnet file: %s"
,
err
)
logrus
.
Warningf
(
"Failed to write flannel subnet file: %s"
,
err
)
}
else
{
}
else
{
...
@@ -97,8 +99,14 @@ func LookupExtInterface(iface *net.Interface, netMode int) (*backend.ExternalInt
...
@@ -97,8 +99,14 @@ func LookupExtInterface(iface *net.Interface, netMode int) (*backend.ExternalInt
if
iface
==
nil
{
if
iface
==
nil
{
logrus
.
Debug
(
"No interface defined for flannel in the config. Fetching the default gateway interface"
)
logrus
.
Debug
(
"No interface defined for flannel in the config. Fetching the default gateway interface"
)
if
iface
,
err
=
ip
.
GetDefaultGatewayInterface
();
err
!=
nil
{
if
netMode
==
ipv4
||
netMode
==
(
ipv4
+
ipv6
)
{
return
nil
,
fmt
.
Errorf
(
"failed to get default interface: %s"
,
err
)
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
)
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
...
@@ -147,7 +155,7 @@ func LookupExtInterface(iface *net.Interface, netMode int) (*backend.ExternalInt
},
nil
},
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
)
dir
,
name
:=
filepath
.
Split
(
path
)
os
.
MkdirAll
(
dir
,
0755
)
os
.
MkdirAll
(
dir
,
0755
)
...
@@ -161,9 +169,10 @@ func WriteSubnetFile(path string, nw ip.IP4Net, nwv6 ip.IP6Net, ipMasq bool, bn
...
@@ -161,9 +169,10 @@ func WriteSubnetFile(path string, nw ip.IP4Net, nwv6 ip.IP6Net, ipMasq bool, bn
// sn.IP by one
// sn.IP by one
sn
:=
bn
.
Lease
()
.
Subnet
sn
:=
bn
.
Lease
()
.
Subnet
sn
.
IP
++
sn
.
IP
++
if
netMode
==
ipv4
||
netMode
==
(
ipv4
+
ipv6
)
{
fmt
.
Fprintf
(
f
,
"FLANNEL_NETWORK=%s
\n
"
,
nw
)
fmt
.
Fprintf
(
f
,
"FLANNEL_NETWORK=%s
\n
"
,
nw
)
fmt
.
Fprintf
(
f
,
"FLANNEL_SUBNET=%s
\n
"
,
sn
)
fmt
.
Fprintf
(
f
,
"FLANNEL_SUBNET=%s
\n
"
,
sn
)
}
if
nwv6
.
String
()
!=
emptyIPv6Network
{
if
nwv6
.
String
()
!=
emptyIPv6Network
{
snv6
:=
bn
.
Lease
()
.
IPv6Subnet
snv6
:=
bn
.
Lease
()
.
IPv6Subnet
...
...
pkg/agent/flannel/setup.go
View file @
29c55f5e
...
@@ -45,7 +45,8 @@ const (
...
@@ -45,7 +45,8 @@ const (
flannelConf
=
`{
flannelConf
=
`{
"Network": "%CIDR%",
"Network": "%CIDR%",
"EnableIPv6": %DUALSTACK%,
"EnableIPv6": %IPV6_ENABLED%,
"EnableIPv4": %IPV4_ENABLED%,
"IPv6Network": "%CIDR_IPV6%",
"IPv6Network": "%CIDR_IPV6%",
"Backend": %backend%
"Backend": %backend%
}
}
...
@@ -140,6 +141,7 @@ func createCNIConf(dir string) error {
...
@@ -140,6 +141,7 @@ func createCNIConf(dir string) error {
}
}
func
createFlannelConf
(
nodeConfig
*
config
.
Node
)
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
)
logrus
.
Debugf
(
"Creating the flannel configuration for backend %s in file %s"
,
nodeConfig
.
FlannelBackend
,
nodeConfig
.
FlannelConfFile
)
if
nodeConfig
.
FlannelConfFile
==
""
{
if
nodeConfig
.
FlannelConfFile
==
""
{
return
errors
.
New
(
"Flannel configuration not defined"
)
return
errors
.
New
(
"Flannel configuration not defined"
)
...
@@ -148,7 +150,40 @@ func createFlannelConf(nodeConfig *config.Node) error {
...
@@ -148,7 +150,40 @@ func createFlannelConf(nodeConfig *config.Node) error {
logrus
.
Infof
(
"Using custom flannel conf defined at %s"
,
nodeConfig
.
FlannelConfFile
)
logrus
.
Infof
(
"Using custom flannel conf defined at %s"
,
nodeConfig
.
FlannelConfFile
)
return
nil
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
,
"%IPV6_ENABLED%"
,
"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
,
"%IPV6_ENABLED%"
,
"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
,
"%IPV6_ENABLED%"
,
"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
var
backendConf
string
...
@@ -169,25 +204,6 @@ func createFlannelConf(nodeConfig *config.Node) error {
...
@@ -169,25 +204,6 @@ func createFlannelConf(nodeConfig *config.Node) error {
}
}
confJSON
=
strings
.
ReplaceAll
(
confJSON
,
"%backend%"
,
backendConf
)
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
)
logrus
.
Debugf
(
"The flannel configuration is %s"
,
confJSON
)
return
util
.
WriteFile
(
nodeConfig
.
FlannelConfFile
,
confJSON
)
return
util
.
WriteFile
(
nodeConfig
.
FlannelConfFile
,
confJSON
)
}
}
...
...
pkg/cli/server/server.go
View file @
29c55f5e
...
@@ -534,9 +534,6 @@ func validateNetworkConfiguration(serverConfig server.Config) error {
...
@@ -534,9 +534,6 @@ func validateNetworkConfiguration(serverConfig server.Config) error {
if
serverConfig
.
ControlConfig
.
DisableNPC
==
false
{
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"
)
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
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