cheliequan
2023-05-24 49a352c6540ff77a2dd2c704d6a613be60ea52e0
src/util/util.go
@@ -12,14 +12,14 @@
)
// homeDir 获取当前用户的家目录路径
func homeDir() string {
func HomeDir() string {
   if h := os.Getenv("HOME"); h != "" {
      return h
   }
   return os.Getenv("USERPROFILE") // Windows 环境下获取用户目录
}
func sshExec(nodeIP, sshUsername, sshPassword, remoteSSHCommand string, sshPort int) (string, error) {
func SSHExec(nodeIP, sshUsername, sshPassword, remoteSSHCommand string, sshPort int) (string, error) {
   // SSH 连接配置
   config := &ssh.ClientConfig{
      User: sshUsername,
@@ -97,7 +97,7 @@
}
// 安装Docker
func installDocker(nodeIP, sshUsername, sshPassword string, sshPort int) error {
func InstallDocker(nodeIP, sshUsername, sshPassword string, sshPort int) error {
   // 检查Docker是否已安装
   checkCommand := "which docker"
   _, err := sshExec(nodeIP, sshUsername, sshPassword, checkCommand, sshPort)
@@ -118,7 +118,7 @@
}
// Create an HTTP client with insecure TLS configuration
func createHTTPClient() *http.Client {
func CreateHTTPClient() *http.Client {
   transport := &http.Transport{
      TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
   }
@@ -126,7 +126,7 @@
}
// 安装kubectl
func installKubectl(nodeIP, sshUsername, sshPassword string, sshPort int) error {
func InstallKubectl(nodeIP, sshUsername, sshPassword string, sshPort int) error {
   // 检查kubectl是否已安装
   checkCommand := "which kubectl"
   _, err := sshExec(nodeIP, sshUsername, sshPassword, checkCommand, sshPort)