diff --git a/clustertool/.gitignore b/clustertool/.gitignore index 7b369358bb94..145b4f56af08 100644 --- a/clustertool/.gitignore +++ b/clustertool/.gitignore @@ -26,3 +26,4 @@ embeded/darwin* embeded/windows* embeded/freebsd* .devcontainer +.envrc diff --git a/clustertool/cmd/adv_testcmd.go b/clustertool/cmd/adv_testcmd.go index 26d022dfd624..6ca96110a78e 100644 --- a/clustertool/cmd/adv_testcmd.go +++ b/clustertool/cmd/adv_testcmd.go @@ -3,8 +3,11 @@ package cmd import ( "strings" + "github.com/rs/zerolog/log" "github.com/spf13/cobra" + "github.com/truecharts/public/clustertool/pkg/gencmd" "github.com/truecharts/public/clustertool/pkg/initfiles" + "github.com/truecharts/public/clustertool/pkg/talassist" ) var advTestCmdlongHelp = strings.TrimSpace(` @@ -17,10 +20,13 @@ var testcmd = &cobra.Command{ Long: advTestCmdlongHelp, Run: func(cmd *cobra.Command, args []string) { initfiles.LoadTalEnv(false) + talassist.LoadTalConfig() // err := fluxhandler.ProcessJSONFiles("./testdata/truenas_exports") // if err != nil { // log.Info().Msg("Error:", err) // } + cmds := gencmd.GenApply("", []string{}) + log.Info().Msgf("%s", cmds[0]) }, } diff --git a/clustertool/pkg/gencmd/apply.go b/clustertool/pkg/gencmd/apply.go index d3554b6e5c6f..0e867fec0254 100644 --- a/clustertool/pkg/gencmd/apply.go +++ b/clustertool/pkg/gencmd/apply.go @@ -2,13 +2,15 @@ package gencmd import ( "path/filepath" + "strings" + "github.com/rs/zerolog/log" "github.com/truecharts/public/clustertool/embed" "github.com/truecharts/public/clustertool/pkg/helper" "github.com/truecharts/public/clustertool/pkg/talassist" ) -func GenApply(node string, extraFlags []string) []string { +func GenApply(node string, extraArgs []string) []string { commands := []string{} //extraFlags = append(extraFlags, "--preserve") @@ -19,12 +21,13 @@ func GenApply(node string, extraFlags []string) []string { for _, noderef := range talassist.TalConfig.Nodes { // TODO add extraFlags filename := talassist.TalConfig.ClusterName + "-" + noderef.Hostname + ".yaml" - cmd := talosPath + " " + "apply-config" + " --talosconfig " + helper.TalosConfigFile + " -n " + noderef.IPAddress + " " + "--file=" + filepath.Join(helper.TalosGenerated, filename) + cmd := talosPath + " " + "apply-config" + " --talosconfig " + helper.TalosConfigFile + " -n " + noderef.IPAddress + " -f " + filepath.Join(helper.TalosGenerated, filename) + " " + strings.Join(extraArgs, " ") commands = append(commands, cmd) } } else { - cmd := talosPath + " " + "apply-config" + " --talosconfig " + helper.TalosConfigFile + " -n " + node + " " + cmd := talosPath + " " + "apply-config" + " --talosconfig " + helper.TalosConfigFile + " -n " + node + " " + strings.Join(extraArgs, " ") commands = append(commands, cmd) } + log.Debug().Msgf("Apply Commands rendered: %s", commands) return commands } diff --git a/clustertool/pkg/gencmd/bootstrap.go b/clustertool/pkg/gencmd/bootstrap.go index e842c0ef9eca..65366d910e46 100644 --- a/clustertool/pkg/gencmd/bootstrap.go +++ b/clustertool/pkg/gencmd/bootstrap.go @@ -34,11 +34,11 @@ func RunBootstrap(args []string) { } bootstrapNode := talassist.TalConfig.Nodes[0].IPAddress - bootstrapcmds := GenPlain("bootstrap", bootstrapNode, extraArgs) nodestatus.WaitForHealth(bootstrapNode, []string{"maintenance"}) taloscmds := GenApply(bootstrapNode, extraArgs) + ExecCmds(taloscmds, false) nodestatus.WaitForHealth(bootstrapNode, []string{"booting"}) @@ -46,6 +46,8 @@ func RunBootstrap(args []string) { log.Info().Msgf("Bootstrap: At this point your system is installed to disk, please make sure not to reboot into the installer ISO/USB %s", bootstrapNode) log.Info().Msgf("Bootstrap: running bootstrap on node: %s", bootstrapNode) + bootstrapcmds := GenPlain("bootstrap", bootstrapNode, extraArgs) + ExecCmd(bootstrapcmds[0]) log.Info().Msgf("Bootstrap: waiting for VIP %v to come online...", helper.TalEnv["VIP_IP"]) diff --git a/clustertool/pkg/gencmd/execcmd.go b/clustertool/pkg/gencmd/execcmd.go index d152c172f77e..6db24125eeb0 100644 --- a/clustertool/pkg/gencmd/execcmd.go +++ b/clustertool/pkg/gencmd/execcmd.go @@ -47,7 +47,7 @@ func ExecCmd(cmd string) { } func ExecCmds(taloscmds []string, healthcheck bool) error { - log.Info().Msg("Regenerating config prior to apply...") + log.Info().Msg("Regenerating config prior to commands...") GenConfig([]string{}) var todocmds []string var healthcmd string @@ -56,6 +56,7 @@ func ExecCmds(taloscmds []string, healthcheck bool) error { log.Info().Msg("Pre-Run Healthchecks...") for _, command := range taloscmds { + node := helper.ExtractNode(command) log.Info().Msgf("checking node availability: %v", node) err := nodestatus.CheckHealth(node, "", false) @@ -92,10 +93,12 @@ func ExecCmds(taloscmds []string, healthcheck bool) error { log.Info().Msgf("Executing commands on node: %v", node) argslice := strings.Split(string(command), " ") // log.Info().Msg("test", strings.Join(argslice, " ")) + log.Debug().Msgf("running command: %s", command) out, err := helper.RunCommand(argslice, false) if err != nil { if strings.Contains(string(out), "certificate signed by unknown authority") { argslice = append(argslice, "--insecure") + log.Debug().Msgf("Re-Running command using insecure flag: %s", command) _, err2 := helper.RunCommand(argslice, false) if err2 != nil { log.Info().Msgf("err: %v", err2) diff --git a/clustertool/pkg/gencmd/plain.go b/clustertool/pkg/gencmd/plain.go index ff17742b0796..221bdb0a4897 100644 --- a/clustertool/pkg/gencmd/plain.go +++ b/clustertool/pkg/gencmd/plain.go @@ -1,27 +1,30 @@ package gencmd import ( + "strings" + + "github.com/rs/zerolog/log" "github.com/truecharts/public/clustertool/embed" "github.com/truecharts/public/clustertool/pkg/helper" "github.com/truecharts/public/clustertool/pkg/talassist" ) -func GenPlain(command string, node string, extraFlags []string) []string { +func GenPlain(command string, node string, extraArgs []string) []string { commands := []string{} - //extraFlags = append(extraFlags, "--preserve") talosPath := embed.GetTalosExec() if node == "" { for _, noderef := range talassist.TalConfig.Nodes { // TODO add extraFlags - cmd := talosPath + " " + command + " --talosconfig " + helper.TalosConfigFile + " -n " + noderef.IPAddress + " " + cmd := talosPath + " " + command + " --talosconfig " + helper.TalosConfigFile + " -n " + noderef.IPAddress + " " + strings.Join(extraArgs, " ") commands = append(commands, cmd) } } else { - cmd := talosPath + " " + command + " --talosconfig " + helper.TalosConfigFile + " -n " + node + " " + cmd := talosPath + " " + command + " --talosconfig " + helper.TalosConfigFile + " -n " + node + " " + strings.Join(extraArgs, " ") commands = append(commands, cmd) } + log.Debug().Msgf("%s Command rendered: %s", command, commands) return commands }