-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
111 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package main | ||
|
||
import ( | ||
//"fmt" | ||
"log" | ||
"io/ioutil" | ||
"gopkg.in/yaml.v2" | ||
"os/exec" | ||
"os" | ||
) | ||
|
||
var boolOptions = []string{"no-flannel","docker","disable-agent"} | ||
|
||
func stringInSlice(a string, list []string) bool { | ||
for _, b := range list { | ||
if b == a { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
|
||
func getConf(file string) map[string]string { | ||
conf := make(map[string]string) | ||
var yamlFile []byte | ||
yamlFile, err := ioutil.ReadFile(file) | ||
if err != nil { | ||
log.Printf("can't find the yaml file") | ||
} | ||
err = yaml.Unmarshal([]byte(yamlFile), &conf) | ||
if err != nil { | ||
log.Fatalf("check the yaml file format") | ||
} | ||
return conf | ||
} | ||
|
||
func constructCmd(mode string) exec.Cmd{ | ||
args := []string{"/usr/local/bin/k3s",mode} | ||
for key,value := range getConf("/etc/k3s/"+mode+"-conf.yml") { | ||
if stringInSlice(key,boolOptions) { | ||
if value == "yes" { | ||
args = append(args,"--"+key) | ||
} | ||
} else if value != "" { | ||
args = append(args,"--"+key) | ||
args = append(args,value) | ||
} | ||
} | ||
cmd := exec.Cmd{} | ||
cmd.Path= "/usr/local/bin/k3s" | ||
cmd.Args = args | ||
return cmd | ||
} | ||
|
||
func main() { | ||
sleepcmd := exec.Command("sleep","10") | ||
err := sleepcmd.Start() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
k3scmd := constructCmd(os.Args[1]) | ||
err = k3scmd.Start() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
token: #Token to use for authentication [] | ||
server: #Server to connect to [] | ||
data-dir: #Folder to hold state (default: "/var/lib/rancher/k3s") | ||
docker: "no" #Use docker instead of containerd | ||
no-flannel: "no" #Disable embedded flannel | ||
cluster-secret : #Shared secret used to bootstrap a cluster [] | ||
node-name : #Node name [] | ||
node-ip: #IP address to advertise for node |