This repository has been archived by the owner on Mar 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
send.go
54 lines (44 loc) · 1.49 KB
/
send.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
package send
import (
"fmt"
"path"
"path/filepath"
"github.com/fatih/color"
"k8s.io/klog"
"github.com/yuyicai/kubei/internal/constants"
"github.com/yuyicai/kubei/internal/operator"
"github.com/yuyicai/kubei/internal/rundata"
)
func Send(c *rundata.Cluster) error {
color.HiBlue("Sending Kubernetes offline pkg to nodes ✉️")
return operator.RunOnAllNodes(c, func(node *rundata.Node, c *rundata.Cluster) error {
if err := send(node, c.Kubei); err != nil {
return err
}
fmt.Printf("[%s] [send] send kubernetes offline pkg: %s\n", node.HostInfo.Host, color.HiGreenString("done✅️"))
return nil
})
}
func send(node *rundata.Node, cfg *rundata.Kubei) error {
return sendAndtar(path.Join("/tmp/.kubei", filepath.Base(cfg.OfflineFile)), cfg.OfflineFile, node)
}
func sendAndtar(dstFile, srcFile string, node *rundata.Node) error {
if node.InstallType == constants.InstallTypeOffline && !node.IsSend {
if err := sendFile(dstFile, srcFile, node); err != nil {
return err
}
klog.V(3).Infof("[%s] [send] send pkg to %s, ", node.HostInfo.Host, dstFile)
if err := tar(dstFile, node); err != nil {
return fmt.Errorf("[%s] [tar] failed to Decompress the file %s: %v", node.HostInfo.Host, dstFile, err)
}
node.IsSend = true
return nil
}
return nil
}
func sendFile(dstFile, srcFile string, node *rundata.Node) error {
return node.SSH.SendFile(dstFile, srcFile)
}
func tar(file string, node *rundata.Node) error {
return node.Run(fmt.Sprintf("tar xf %s -C /tmp/.kubei", file))
}