Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --merge flag to plan command #440

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 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 @@ -113,6 +115,12 @@ Examples JSON input file:
--k3s-extra-args "%s"`, agentK3sExtraArgs)
}

mergeStr := ""
if merge {
mergeStr = ` \
--merge`
}

for i, host := range hosts {
if serversAdded == 0 {

Expand All @@ -123,15 +131,16 @@ Examples JSON input file:
--user %s \
--cluster \
--local-path %s \
--context %s%s%s%s
--context %s%s%s%s%s
`,
host.IP,
user,
kubeconfig,
contextName,
tlsSanStr,
serverExtraArgsSt,
sshKeySt)
sshKeySt,
mergeStr)

script += fmt.Sprintf(`
echo "Fetching the server's node-token into memory"
Expand Down