| | |
| | | ) |
| | | |
| | | // 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, |
| | |
| | | } |
| | | |
| | | // 安装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) |
| | |
| | | } |
| | | |
| | | // Create an HTTP client with insecure TLS configuration |
| | | func createHTTPClient() *http.Client { |
| | | func CreateHTTPClient() *http.Client { |
| | | transport := &http.Transport{ |
| | | TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, |
| | | } |
| | |
| | | } |
| | | |
| | | // 安装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) |