diff --git a/cmd/join.go b/cmd/join.go index 55fbcef6..930c00e6 100644 --- a/cmd/join.go +++ b/cmd/join.go @@ -253,22 +253,21 @@ func MakeJoin() *cobra.Command { sshOperator.Close() - joinToken := string(res.StdOut) + joinToken := strings.TrimSpace(string(res.StdOut)) - var boostrapErr error if server { tlsSan, _ := command.Flags().GetString("tls-san") - boostrapErr = setupAdditionalServer(serverHost, host, port, user, sshKeyPath, joinToken, k3sExtraArgs, k3sVersion, k3sChannel, tlsSan, printCommand, serverURL) + err = setupAdditionalServer(serverHost, host, port, user, sshKeyPath, joinToken, k3sExtraArgs, k3sVersion, k3sChannel, tlsSan, printCommand, serverURL) } else { - boostrapErr = setupAgent(serverHost, host, port, user, sshKeyPath, joinToken, k3sExtraArgs, k3sVersion, k3sChannel, printCommand, serverURL) + err = setupAgent(serverHost, host, port, user, sshKeyPath, joinToken, k3sExtraArgs, k3sVersion, k3sChannel, printCommand, serverURL) } - if boostrapErr == nil { + if err == nil { fmt.Printf("\n%s\n", pkg.SupportMessageShort) } - return boostrapErr + return err } command.PreRunE = func(command *cobra.Command, args []string) error { @@ -452,7 +451,6 @@ func setupAgent(serverHost, host string, port int, user, sshKeyPath, joinToken, } sshOperator, err = operator.NewSSHOperator(address, config) - if err != nil { return errors.Wrapf(err, "unable to connect to %s over ssh", address) } @@ -515,6 +513,7 @@ func makeJoinExec(serverIP, joinToken, installStr, k3sExtraArgs string, serverAg if len(serverURL) > 0 { remoteURL = serverURL } + installEnvVar = append(installEnvVar, fmt.Sprintf("K3S_URL='%s'", remoteURL)) installEnvVar = append(installEnvVar, fmt.Sprintf("K3S_TOKEN='%s'", joinToken)) installEnvVar = append(installEnvVar, installStr) @@ -531,7 +530,9 @@ func makeJoinExec(serverIP, joinToken, installStr, k3sExtraArgs string, serverAg joinExec += " sh -s -" if len(k3sExtraArgs) > 0 { - installEnvVar = append(installEnvVar, k3sExtraArgs) + // AE: this doesn't seem to be used + // installEnvVar = append(installEnvVar, k3sExtraArgs) + joinExec += fmt.Sprintf(" %s", k3sExtraArgs) } diff --git a/cmd/join_test.go b/cmd/join_test.go index d62a75e2..87e5f4d3 100644 --- a/cmd/join_test.go +++ b/cmd/join_test.go @@ -47,13 +47,23 @@ func Test_makeJoinServerExec(t *testing.T) { serverAgent: true, tlsSAN: "127.0.0.1", }, + { + title: "Join agent with K3sExtraArgs", + serverIP: "172.27.251.164", + joinToken: "K10c8bc21f68fef3f56d431a08df2e894481ab0a61a3c84cbd639b56449ad15523c::server:9d30861e1ba54177b8e4dd1426076e5d", + installStr: "INSTALL_K3S_VERSION=1.18", + installk3sExec: "K3S_URL='https://172.27.251.164:6443' K3S_TOKEN='K10c8bc21f68fef3f56d431a08df2e894481ab0a61a3c84cbd639b56449ad15523c::server:9d30861e1ba54177b8e4dd1426076e5d' INSTALL_K3S_VERSION=1.18 sh -s - --node-ip=192.0.3.4 --node-external-ip=85.159.215.50", + k3sExtraArgs: "--node-ip=192.0.3.4 --node-external-ip=85.159.215.50", + serverAgent: false, + tlsSAN: "127.0.0.1", + }, } for _, tc := range tests { t.Run(tc.title, func(t *testing.T) { got := makeJoinExec(tc.serverIP, tc.joinToken, tc.installStr, tc.k3sExtraArgs, tc.serverAgent, "", tc.tlsSAN) if got != tc.installk3sExec { - t.Errorf("want: %s, got: %s", tc.installk3sExec, got) + t.Errorf("want:\n%s\n, got:\n%s\n", tc.installk3sExec, got) } }) }