1
0
mirror of https://github.com/rancher/os.git synced 2025-09-02 23:34:57 +00:00

Add ability to configure docker-sys bridge subnet (#2217)

This commit is contained in:
niusmallnan
2018-01-10 16:44:59 +08:00
committed by GitHub
parent 480e45cd01
commit 44552d55d0
3 changed files with 36 additions and 0 deletions

View File

@@ -1,7 +1,9 @@
package config
import (
"encoding/json"
"io/ioutil"
"net"
"os"
"path"
"path/filepath"
@@ -125,6 +127,30 @@ func SaveInitCmdline(cmdLineArgs string) {
}
}
func SaveCNISubnet(subnet, filename string) {
if _, _, err := net.ParseCIDR(subnet); err != nil {
log.Errorf("Failed to parse system-docker subnet from cmdline: %v", err)
}
rBytes, err := ioutil.ReadFile(filename)
if err != nil {
log.Errorf("Failed to read from %s: %v", filename, err)
}
var data map[string]interface{}
if err = json.Unmarshal(rBytes, &data); err != nil {
log.Errorf("Failed to pasre json: %v", err)
}
ipam := data["ipam"].(map[string]interface{})
ipam["subnet"] = subnet
wBytes, err := json.MarshalIndent(data, "", "\t")
if err != nil {
log.Errorf("Failed to convert to bytes: %v", err)
}
log.Debugf("New cni bridge conf: %s", wBytes)
if err = ioutil.WriteFile(filename, wBytes, 0644); err != nil {
log.Errorf("Failed to write cni bridge file %s: %v", filename, err)
}
}
func CloudConfigDirFiles(dirPrefix string) []string {
cloudConfigDir := path.Join(dirPrefix, CloudConfigDir)