/
send_package.go
75 lines (70 loc) · 1.72 KB
/
send_package.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package install
import (
"fmt"
"path"
"strings"
"sync"
"github.com/wonderivan/logger"
)
//SendPackage is
func (s *SealosInstaller) SendPackage(url string) {
pkg := path.Base(url)
//only http
isHttp := strings.HasPrefix(url, "http")
wgetCommand := ""
if isHttp {
wgetParam := ""
if strings.HasPrefix(url, "https") {
wgetParam = "--no-check-certificate"
}
wgetCommand = fmt.Sprintf(" wget %s ", wgetParam)
}
remoteCmd := fmt.Sprintf("cd /root && %s %s && tar zxvf %s", wgetCommand, url, pkg)
localCmd := fmt.Sprintf("cd /root && rm -rf kube && tar zxvf %s ", pkg)
kubeCmd := "cd /root/kube/shell && sh init.sh"
kubeLocal := fmt.Sprintf("/root/%s", pkg)
var wm sync.WaitGroup
var wn sync.WaitGroup
for _, master := range s.Masters {
wm.Add(1)
go func(master string) {
defer wm.Done()
logger.Debug("please wait for tar zxvf exec")
if RemoteFilExist(master, kubeLocal) {
logger.Warn("host is ", master, ", SendPackage: file is exist")
Cmd(master, localCmd)
} else {
if isHttp {
go WatchFileSize(master, kubeLocal, GetFileSize(url))
Cmd(master, remoteCmd)
} else {
Copy(master, url, kubeLocal)
Cmd(master, localCmd)
}
}
Cmd(master, kubeCmd)
}(master)
}
for _, node := range s.Nodes {
wn.Add(1)
go func(node string) {
defer wn.Done()
logger.Debug("please wait for tar zxvf exec")
if RemoteFilExist(node, kubeLocal) {
logger.Warn("host is ", node, ", SendPackage: file is exist")
Cmd(node, localCmd)
} else {
if isHttp {
go WatchFileSize(node, kubeLocal, GetFileSize(url))
Cmd(node, remoteCmd)
} else {
Copy(node, url, kubeLocal)
Cmd(node, localCmd)
}
}
Cmd(node, kubeCmd)
}(node)
}
wm.Wait()
wn.Wait()
}