fix(clustertool): add commands debug and allow for extra args

This commit is contained in:
Kjeld Schouten
2024-11-06 22:25:16 +01:00
parent eb1e7440dc
commit a11f019d6e
6 changed files with 27 additions and 9 deletions
+1
View File
@@ -26,3 +26,4 @@ embeded/darwin*
embeded/windows*
embeded/freebsd*
.devcontainer
.envrc
+6
View File
@@ -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])
},
}
+6 -3
View File
@@ -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
}
+3 -1
View File
@@ -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"])
+4 -1
View File
@@ -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)
+7 -4
View File
@@ -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
}