diff --git a/pkg/agent/flannel/setup.go b/pkg/agent/flannel/setup.go index fc21b51d52..a1f290897d 100644 --- a/pkg/agent/flannel/setup.go +++ b/pkg/agent/flannel/setup.go @@ -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) } diff --git a/pkg/cli/cmds/server.go b/pkg/cli/cmds/server.go index cc03ddd46a..04b429feb2 100644 --- a/pkg/cli/cmds/server.go +++ b/pkg/cli/cmds/server.go @@ -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", },