From 22c67a0648eb17ca9dc7dd55bd47d84907554571 Mon Sep 17 00:00:00 2001 From: Matthias Riegler Date: Mon, 26 Aug 2024 12:45:58 +0200 Subject: [PATCH 1/2] fix: allow IPv6 addresses for --ip and --server args Signed-off-by: Matthias Riegler --- cmd/install.go | 3 ++- cmd/join.go | 7 ++++--- cmd/node-token.go | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/cmd/install.go b/cmd/install.go index c7ca556..339bb32 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -9,6 +9,7 @@ import ( "os/exec" "path/filepath" "runtime" + "strconv" "strings" "github.com/alexellis/k3sup/pkg" @@ -294,7 +295,7 @@ Provide the --local-path flag with --merge if a kubeconfig already exists in som sshKey, _ := command.Flags().GetString("ssh-key") sshKeyPath := expandPath(sshKey) - address := fmt.Sprintf("%s:%d", host, port) + address := net.JoinHostPort(host, strconv.Itoa(port)) sshOperator, sshOperatorDone, errored, err := connectOperator(user, address, sshKeyPath) if errored { diff --git a/cmd/join.go b/cmd/join.go index 96190ba..88bbe51 100644 --- a/cmd/join.go +++ b/cmd/join.go @@ -6,6 +6,7 @@ import ( "os" "path" "runtime" + "strconv" "strings" "errors" @@ -198,7 +199,7 @@ func MakeJoin() *cobra.Command { sshKeyPath := expandPath(sshKey) if len(nodeToken) == 0 { - address := fmt.Sprintf("%s:%d", serverHost, serverPort) + address := net.JoinHostPort(host, strconv.Itoa(serverPort)) sshOperator, sshOperatorDone, errored, err := connectOperator(serverUser, address, sshKeyPath) if errored { @@ -312,7 +313,7 @@ func MakeJoin() *cobra.Command { } func setupAdditionalServer(serverHost, host string, port int, user, sshKeyPath, joinToken, k3sExtraArgs, k3sVersion, k3sChannel, tlsSAN string, printCommand bool, serverURL string, noExtras bool) error { - address := fmt.Sprintf("%s:%d", host, port) + address := net.JoinHostPort(host, strconv.Itoa(port)) var sshOperator *operator.SSHOperator var initialSSHErr error @@ -404,7 +405,7 @@ func setupAdditionalServer(serverHost, host string, port int, user, sshKeyPath, func setupAgent(serverHost, host string, port int, user, sshKeyPath, joinToken, k3sExtraArgs, k3sVersion, k3sChannel string, printCommand bool, serverURL string) error { - address := fmt.Sprintf("%s:%d", host, port) + address := net.JoinHostPort(host, strconv.Itoa(port)) var sshOperator *operator.SSHOperator var initialSSHErr error diff --git a/cmd/node-token.go b/cmd/node-token.go index 7063958..29b8114 100644 --- a/cmd/node-token.go +++ b/cmd/node-token.go @@ -5,6 +5,7 @@ import ( "net" "os" "path" + "strconv" "strings" "github.com/alexellis/k3sup/pkg" @@ -101,7 +102,7 @@ server or agent to join the cluster. dataDir, _ := command.Flags().GetString("server-data-dir") sshKeyPath := expandPath(sshKey) - address := fmt.Sprintf("%s:%d", host, port) + address := net.JoinHostPort(host, strconv.Itoa(port)) if !local { fmt.Fprintf(os.Stderr, "Remote: %s\n", address) } From d09e8ed8670d60a6c31bdafe167f5f98b28e3479 Mon Sep 17 00:00:00 2001 From: Matthias Riegler Date: Mon, 26 Aug 2024 13:19:56 +0200 Subject: [PATCH 2/2] fix: remoteURL Signed-off-by: Matthias Riegler --- cmd/join.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/join.go b/cmd/join.go index 88bbe51..7c1ad0e 100644 --- a/cmd/join.go +++ b/cmd/join.go @@ -506,7 +506,7 @@ func createVersionStr(k3sVersion, k3sChannel string) string { func makeJoinExec(serverIP, joinToken, installStr, k3sExtraArgs string, serverAgent bool, serverURL, tlsSan string) string { installEnvVar := []string{} - remoteURL := fmt.Sprintf("https://%s:6443", serverIP) + remoteURL := "https://" + net.JoinHostPort(serverIP, "6443") if len(serverURL) > 0 { remoteURL = serverURL }