Skip to content

Commit

Permalink
Format some of the code, comment out unused line
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
  • Loading branch information
alexellis committed Aug 18, 2023
1 parent e4107dd commit 3f8b3fa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
17 changes: 9 additions & 8 deletions cmd/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}

Expand Down
12 changes: 11 additions & 1 deletion cmd/join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}
Expand Down

0 comments on commit 3f8b3fa

Please sign in to comment.