mirror of https://github.com/k3s-io/k3s
Add ability to pass configuration options to flannel backend
Allow the flannel backend to be specified as backend=option=val,option2=val2 to select a given backend with extra options. In particular this adds the following options to wireguard-native backend: * Mode - flannel wireguard tunnel mode * PersistentKeepaliveInterval- wireguard persistent keepalive interval Signed-off-by: Sjoerd Simons <sjoerd@collabora.com>pull/5552/head
parent
99cc672d9a
commit
8643576985
|
@ -81,7 +81,8 @@ const (
|
|||
|
||||
wireguardNativeBackend = `{
|
||||
"Type": "wireguard",
|
||||
"PersistentKeepaliveInterval": 25
|
||||
"PersistentKeepaliveInterval": %PersistentKeepaliveInterval%,
|
||||
"Mode": "%Mode%"
|
||||
}`
|
||||
|
||||
emptyIPv6Network = "::/0"
|
||||
|
@ -201,8 +202,22 @@ func createFlannelConf(nodeConfig *config.Node) error {
|
|||
}
|
||||
|
||||
var backendConf string
|
||||
parts := strings.SplitN(nodeConfig.FlannelBackend, "=", 2)
|
||||
backend := parts[0]
|
||||
backendOptions := make(map[string]string)
|
||||
if len(parts) > 1 {
|
||||
options := strings.Split(parts[1], ",")
|
||||
for _, o := range options {
|
||||
p := strings.SplitN(o, "=", 2)
|
||||
if len(p) == 1 {
|
||||
backendOptions[p[0]] = ""
|
||||
} else {
|
||||
backendOptions[p[0]] = p[1]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch nodeConfig.FlannelBackend {
|
||||
switch backend {
|
||||
case config.FlannelBackendVXLAN:
|
||||
backendConf = vxlanBackend
|
||||
case config.FlannelBackendHostGW:
|
||||
|
@ -216,7 +231,16 @@ func createFlannelConf(nodeConfig *config.Node) error {
|
|||
backendConf = strings.ReplaceAll(wireguardBackend, "%flannelConfDir%", filepath.Dir(nodeConfig.FlannelConfFile))
|
||||
logrus.Warnf("The wireguard backend is deprecated and will be removed in k3s v1.26, please switch to wireguard-native. Check our docs for information about how to migrate")
|
||||
case config.FlannelBackendWireguardNative:
|
||||
backendConf = wireguardNativeBackend
|
||||
mode, ok := backendOptions["Mode"]
|
||||
if !ok {
|
||||
mode = "separate"
|
||||
}
|
||||
keepalive, ok := backendOptions["PersistentKeepaliveInterval"]
|
||||
if !ok {
|
||||
keepalive = "25"
|
||||
}
|
||||
backendConf = strings.ReplaceAll(wireguardNativeBackend, "%Mode%", mode)
|
||||
backendConf = strings.ReplaceAll(backendConf, "%PersistentKeepaliveInterval%", keepalive)
|
||||
default:
|
||||
return fmt.Errorf("Cannot configure unknown flannel backend '%s'", nodeConfig.FlannelBackend)
|
||||
}
|
||||
|
|
|
@ -205,7 +205,7 @@ var ServerFlags = []cli.Flag{
|
|||
ClusterDomain,
|
||||
cli.StringFlag{
|
||||
Name: "flannel-backend",
|
||||
Usage: "(networking) One of 'none', 'vxlan', 'ipsec', 'host-gw', 'wireguard'(deprecated), or 'wireguard-native'",
|
||||
Usage: "(networking) backend<=option1=val1,option2=val2> where backend is one of 'none', 'vxlan', 'ipsec', 'host-gw', 'wireguard-native', or 'wireguard' (deprecated)",
|
||||
Destination: &ServerConfig.FlannelBackend,
|
||||
Value: "vxlan",
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue