Skip to content

Commit

Permalink
Add --merge flag to plan command
Browse files Browse the repository at this point in the history
Signed-off-by: Matteo Danelon <[email protected]>
  • Loading branch information
DaruZero committed Aug 20, 2024
1 parent b7bb7cb commit badd2e0
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions cmd/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func MakePlan() *cobra.Command {
var command = &cobra.Command{
command := &cobra.Command{
Use: "plan",
Short: "Plan an installation of K3s.",
Long: `Generate a bash script or plan of installation commands for K3s for a
Expand All @@ -37,6 +37,8 @@ Examples JSON input file:

command.Flags().Int("servers", 3, "Number of servers to use from the devices file")
command.Flags().String("local-path", "kubeconfig", "Where to save the kubeconfig file")
command.Flags().Bool("merge", false, `Merge the config with existing kubeconfig if it already exists.
Provide the --local-path flag with --merge if a kubeconfig already exists in some other directory`)
command.Flags().String("context", "default", "Name of the kubeconfig context to use")
command.Flags().String("user", "root", "Username for SSH login")

Expand All @@ -51,7 +53,6 @@ Examples JSON input file:
command.Flags().Int("limit", 0, "Maximum number of nodes to use from the devices file, 0 to use all devices")

command.RunE = func(cmd *cobra.Command, args []string) error {

if len(args) == 0 {
return fmt.Errorf("give a path to a JSON file containing a list of devices")
}
Expand All @@ -75,6 +76,7 @@ Examples JSON input file:

servers, _ := cmd.Flags().GetInt("servers")
kubeconfig, _ := cmd.Flags().GetString("local-path")
merge, _ := cmd.Flags().GetBool("merge")
contextName, _ := cmd.Flags().GetString("context")
user, _ := cmd.Flags().GetString("user")
tlsSan, _ := cmd.Flags().GetString("tls-san")
Expand Down Expand Up @@ -123,8 +125,7 @@ Examples JSON input file:
--user %s \
--cluster \
--local-path %s \
--context %s%s%s%s
`,
--context %s%s%s%s`,
host.IP,
user,
kubeconfig,
Expand All @@ -133,7 +134,13 @@ Examples JSON input file:
serverExtraArgsSt,
sshKeySt)

if merge {
script += ` \
--merge `
}

script += fmt.Sprintf(`
echo "Fetching the server's node-token into memory"
export NODE_TOKEN=$(k3sup node-token --host %s --user %s%s)
Expand Down

0 comments on commit badd2e0

Please sign in to comment.