|
|
@ -3,6 +3,8 @@ package flannel |
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"context" |
|
|
|
"context" |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
|
|
|
|
"os" |
|
|
|
|
|
|
|
"path" |
|
|
|
"path/filepath" |
|
|
|
"path/filepath" |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
"time" |
|
|
|
"time" |
|
|
@ -131,6 +133,9 @@ func createFlannelConf(nodeConfig *config.Node) error { |
|
|
|
backendConf = vxlanBackend |
|
|
|
backendConf = vxlanBackend |
|
|
|
case config.FlannelBackendIPSEC: |
|
|
|
case config.FlannelBackendIPSEC: |
|
|
|
backendConf = strings.Replace(ipsecBackend, "%psk%", nodeConfig.AgentConfig.IPSECPSK, -1) |
|
|
|
backendConf = strings.Replace(ipsecBackend, "%psk%", nodeConfig.AgentConfig.IPSECPSK, -1) |
|
|
|
|
|
|
|
if err := setupStrongSwan(nodeConfig); err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
case config.FlannelBackendWireguard: |
|
|
|
case config.FlannelBackendWireguard: |
|
|
|
backendConf = wireguardBackend |
|
|
|
backendConf = wireguardBackend |
|
|
|
default: |
|
|
|
default: |
|
|
@ -140,3 +145,24 @@ func createFlannelConf(nodeConfig *config.Node) error { |
|
|
|
|
|
|
|
|
|
|
|
return util.WriteFile(nodeConfig.FlannelConf, confJSON) |
|
|
|
return util.WriteFile(nodeConfig.FlannelConf, confJSON) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func setupStrongSwan(nodeConfig *config.Node) error { |
|
|
|
|
|
|
|
// if we don't know the location of extracted strongswan data then return
|
|
|
|
|
|
|
|
dataDir := os.Getenv("K3S_DATA_DIR") |
|
|
|
|
|
|
|
if dataDir == "" { |
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
dataDir = path.Join(dataDir, "etc", "strongswan") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
info, err := os.Lstat(nodeConfig.AgentConfig.StrongSwanDir) |
|
|
|
|
|
|
|
// something exists but is not a symlink, return
|
|
|
|
|
|
|
|
if err == nil && info.Mode()&os.ModeSymlink == 0 { |
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// clean up strongswan old link
|
|
|
|
|
|
|
|
os.Remove(nodeConfig.AgentConfig.StrongSwanDir) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// make new strongswan link
|
|
|
|
|
|
|
|
return os.Symlink(dataDir, nodeConfig.AgentConfig.StrongSwanDir) |
|
|
|
|
|
|
|
} |
|
|
|