From ed0baf727fba86a725445fb2683c8b724ace8ed2 Mon Sep 17 00:00:00 2001 From: Richard Gee Date: Fri, 29 Dec 2023 15:38:17 +0000 Subject: [PATCH] Add --no-extra flag to join command It was found that when joining servers to a cluster any additional servers would not honour the `--no-extras` flag used with the install command. It is necessary, therefore, for the flag to be added to `join` and only be applied in situations where `--server` has been provided. Signed-off-by: Richard Gee --- cmd/join.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/cmd/join.go b/cmd/join.go index 2435a83..96190ba 100644 --- a/cmd/join.go +++ b/cmd/join.go @@ -65,6 +65,7 @@ func MakeJoin() *cobra.Command { command.Flags().Bool("sudo", true, "Use sudo for installation. e.g. set to false when using the root user and no sudo is available.") command.Flags().Bool("server", false, "Join the cluster as a server rather than as an agent for the embedded etcd mode") + command.Flags().Bool("no-extras", false, `Disable "servicelb" and "traefik", when using --server flag`) command.Flags().Bool("print-command", false, "Print a command that you can use with SSH to manually recover from an error") command.Flags().String("node-token-path", "", "file containing --node-token") command.Flags().String("node-token", "", "prefetched token used by nodes to join the cluster") @@ -236,9 +237,11 @@ func MakeJoin() *cobra.Command { } if server { + tlsSan, _ := command.Flags().GetString("tls-san") + noExtras, _ := command.Flags().GetBool("no-extras") - err = setupAdditionalServer(serverHost, host, port, user, sshKeyPath, nodeToken, k3sExtraArgs, k3sVersion, k3sChannel, tlsSan, printCommand, serverURL) + err = setupAdditionalServer(serverHost, host, port, user, sshKeyPath, nodeToken, k3sExtraArgs, k3sVersion, k3sChannel, tlsSan, printCommand, serverURL, noExtras) } else { err = setupAgent(serverHost, host, port, user, sshKeyPath, nodeToken, k3sExtraArgs, k3sVersion, k3sChannel, printCommand, serverURL) } @@ -282,13 +285,21 @@ func MakeJoin() *cobra.Command { return err } - if len(tlsSan) > 0 { + noExtras, err := command.Flags().GetBool("no-extras") + if err != nil { + return err + } + + if len(tlsSan) > 0 || noExtras { server, err := command.Flags().GetBool("server") if err != nil { return err } if !server { + if noExtras { + return fmt.Errorf("--no-extras can only be used with --server") + } return fmt.Errorf("--tls-san can only be used with --server") } @@ -300,7 +311,7 @@ func MakeJoin() *cobra.Command { return command } -func setupAdditionalServer(serverHost, host string, port int, user, sshKeyPath, joinToken, k3sExtraArgs, k3sVersion, k3sChannel, tlsSAN string, printCommand bool, serverURL string) error { +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) var sshOperator *operator.SSHOperator @@ -355,6 +366,11 @@ func setupAdditionalServer(serverHost, host string, port int, user, sshKeyPath, defer sshOperator.Close() + if noExtras { + k3sExtraArgs += " --disable servicelb" + k3sExtraArgs += " --disable traefik" + } + installk3sExec := makeJoinExec( serverHost, strings.TrimSpace(joinToken),