Commit 86435769 authored by Sjoerd Simons's avatar Sjoerd Simons

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: 's avatarSjoerd Simons <sjoerd@collabora.com>
parent 99cc672d
...@@ -81,7 +81,8 @@ const ( ...@@ -81,7 +81,8 @@ const (
wireguardNativeBackend = `{ wireguardNativeBackend = `{
"Type": "wireguard", "Type": "wireguard",
"PersistentKeepaliveInterval": 25 "PersistentKeepaliveInterval": %PersistentKeepaliveInterval%,
"Mode": "%Mode%"
}` }`
emptyIPv6Network = "::/0" emptyIPv6Network = "::/0"
...@@ -201,8 +202,22 @@ func createFlannelConf(nodeConfig *config.Node) error { ...@@ -201,8 +202,22 @@ func createFlannelConf(nodeConfig *config.Node) error {
} }
var backendConf string 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: case config.FlannelBackendVXLAN:
backendConf = vxlanBackend backendConf = vxlanBackend
case config.FlannelBackendHostGW: case config.FlannelBackendHostGW:
...@@ -216,7 +231,16 @@ func createFlannelConf(nodeConfig *config.Node) error { ...@@ -216,7 +231,16 @@ func createFlannelConf(nodeConfig *config.Node) error {
backendConf = strings.ReplaceAll(wireguardBackend, "%flannelConfDir%", filepath.Dir(nodeConfig.FlannelConfFile)) 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") 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: 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: default:
return fmt.Errorf("Cannot configure unknown flannel backend '%s'", nodeConfig.FlannelBackend) return fmt.Errorf("Cannot configure unknown flannel backend '%s'", nodeConfig.FlannelBackend)
} }
......
...@@ -205,7 +205,7 @@ var ServerFlags = []cli.Flag{ ...@@ -205,7 +205,7 @@ var ServerFlags = []cli.Flag{
ClusterDomain, ClusterDomain,
cli.StringFlag{ cli.StringFlag{
Name: "flannel-backend", 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, Destination: &ServerConfig.FlannelBackend,
Value: "vxlan", Value: "vxlan",
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment