Commit d29b6211 authored by Sjoerd Simons's avatar Sjoerd Simons Committed by Roberto Bonafiglia

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 330993e1
......@@ -81,7 +81,8 @@ const (
wireguardNativeBackend = `{
"Type": "wireguard",
"PersistentKeepaliveInterval": 25
"PersistentKeepaliveInterval": %PersistentKeepaliveInterval%,
"Mode": "%Mode%"
}`
emptyIPv6Network = "::/0"
......@@ -206,8 +207,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:
......@@ -221,7 +236,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)
}
......
......@@ -206,7 +206,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",
},
......
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