fix(clustertool): add commands debug and allow for extra args
This commit is contained in:
@@ -26,3 +26,4 @@ embeded/darwin*
|
|||||||
embeded/windows*
|
embeded/windows*
|
||||||
embeded/freebsd*
|
embeded/freebsd*
|
||||||
.devcontainer
|
.devcontainer
|
||||||
|
.envrc
|
||||||
|
|||||||
@@ -3,8 +3,11 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/truecharts/public/clustertool/pkg/gencmd"
|
||||||
"github.com/truecharts/public/clustertool/pkg/initfiles"
|
"github.com/truecharts/public/clustertool/pkg/initfiles"
|
||||||
|
"github.com/truecharts/public/clustertool/pkg/talassist"
|
||||||
)
|
)
|
||||||
|
|
||||||
var advTestCmdlongHelp = strings.TrimSpace(`
|
var advTestCmdlongHelp = strings.TrimSpace(`
|
||||||
@@ -17,10 +20,13 @@ var testcmd = &cobra.Command{
|
|||||||
Long: advTestCmdlongHelp,
|
Long: advTestCmdlongHelp,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
initfiles.LoadTalEnv(false)
|
initfiles.LoadTalEnv(false)
|
||||||
|
talassist.LoadTalConfig()
|
||||||
// err := fluxhandler.ProcessJSONFiles("./testdata/truenas_exports")
|
// err := fluxhandler.ProcessJSONFiles("./testdata/truenas_exports")
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
// log.Info().Msg("Error:", err)
|
// log.Info().Msg("Error:", err)
|
||||||
// }
|
// }
|
||||||
|
cmds := gencmd.GenApply("", []string{})
|
||||||
|
log.Info().Msgf("%s", cmds[0])
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,13 +2,15 @@ package gencmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/truecharts/public/clustertool/embed"
|
"github.com/truecharts/public/clustertool/embed"
|
||||||
"github.com/truecharts/public/clustertool/pkg/helper"
|
"github.com/truecharts/public/clustertool/pkg/helper"
|
||||||
"github.com/truecharts/public/clustertool/pkg/talassist"
|
"github.com/truecharts/public/clustertool/pkg/talassist"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GenApply(node string, extraFlags []string) []string {
|
func GenApply(node string, extraArgs []string) []string {
|
||||||
|
|
||||||
commands := []string{}
|
commands := []string{}
|
||||||
//extraFlags = append(extraFlags, "--preserve")
|
//extraFlags = append(extraFlags, "--preserve")
|
||||||
@@ -19,12 +21,13 @@ func GenApply(node string, extraFlags []string) []string {
|
|||||||
for _, noderef := range talassist.TalConfig.Nodes {
|
for _, noderef := range talassist.TalConfig.Nodes {
|
||||||
// TODO add extraFlags
|
// TODO add extraFlags
|
||||||
filename := talassist.TalConfig.ClusterName + "-" + noderef.Hostname + ".yaml"
|
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)
|
commands = append(commands, cmd)
|
||||||
}
|
}
|
||||||
} else {
|
} 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)
|
commands = append(commands, cmd)
|
||||||
}
|
}
|
||||||
|
log.Debug().Msgf("Apply Commands rendered: %s", commands)
|
||||||
return commands
|
return commands
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,11 +34,11 @@ func RunBootstrap(args []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bootstrapNode := talassist.TalConfig.Nodes[0].IPAddress
|
bootstrapNode := talassist.TalConfig.Nodes[0].IPAddress
|
||||||
bootstrapcmds := GenPlain("bootstrap", bootstrapNode, extraArgs)
|
|
||||||
|
|
||||||
nodestatus.WaitForHealth(bootstrapNode, []string{"maintenance"})
|
nodestatus.WaitForHealth(bootstrapNode, []string{"maintenance"})
|
||||||
|
|
||||||
taloscmds := GenApply(bootstrapNode, extraArgs)
|
taloscmds := GenApply(bootstrapNode, extraArgs)
|
||||||
|
|
||||||
ExecCmds(taloscmds, false)
|
ExecCmds(taloscmds, false)
|
||||||
|
|
||||||
nodestatus.WaitForHealth(bootstrapNode, []string{"booting"})
|
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: 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)
|
log.Info().Msgf("Bootstrap: running bootstrap on node: %s", bootstrapNode)
|
||||||
|
bootstrapcmds := GenPlain("bootstrap", bootstrapNode, extraArgs)
|
||||||
|
|
||||||
ExecCmd(bootstrapcmds[0])
|
ExecCmd(bootstrapcmds[0])
|
||||||
|
|
||||||
log.Info().Msgf("Bootstrap: waiting for VIP %v to come online...", helper.TalEnv["VIP_IP"])
|
log.Info().Msgf("Bootstrap: waiting for VIP %v to come online...", helper.TalEnv["VIP_IP"])
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ func ExecCmd(cmd string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ExecCmds(taloscmds []string, healthcheck bool) error {
|
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{})
|
GenConfig([]string{})
|
||||||
var todocmds []string
|
var todocmds []string
|
||||||
var healthcmd string
|
var healthcmd string
|
||||||
@@ -56,6 +56,7 @@ func ExecCmds(taloscmds []string, healthcheck bool) error {
|
|||||||
log.Info().Msg("Pre-Run Healthchecks...")
|
log.Info().Msg("Pre-Run Healthchecks...")
|
||||||
|
|
||||||
for _, command := range taloscmds {
|
for _, command := range taloscmds {
|
||||||
|
|
||||||
node := helper.ExtractNode(command)
|
node := helper.ExtractNode(command)
|
||||||
log.Info().Msgf("checking node availability: %v", node)
|
log.Info().Msgf("checking node availability: %v", node)
|
||||||
err := nodestatus.CheckHealth(node, "", false)
|
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)
|
log.Info().Msgf("Executing commands on node: %v", node)
|
||||||
argslice := strings.Split(string(command), " ")
|
argslice := strings.Split(string(command), " ")
|
||||||
// log.Info().Msg("test", strings.Join(argslice, " "))
|
// log.Info().Msg("test", strings.Join(argslice, " "))
|
||||||
|
log.Debug().Msgf("running command: %s", command)
|
||||||
out, err := helper.RunCommand(argslice, false)
|
out, err := helper.RunCommand(argslice, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if strings.Contains(string(out), "certificate signed by unknown authority") {
|
if strings.Contains(string(out), "certificate signed by unknown authority") {
|
||||||
argslice = append(argslice, "--insecure")
|
argslice = append(argslice, "--insecure")
|
||||||
|
log.Debug().Msgf("Re-Running command using insecure flag: %s", command)
|
||||||
_, err2 := helper.RunCommand(argslice, false)
|
_, err2 := helper.RunCommand(argslice, false)
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
log.Info().Msgf("err: %v", err2)
|
log.Info().Msgf("err: %v", err2)
|
||||||
|
|||||||
@@ -1,27 +1,30 @@
|
|||||||
package gencmd
|
package gencmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/truecharts/public/clustertool/embed"
|
"github.com/truecharts/public/clustertool/embed"
|
||||||
"github.com/truecharts/public/clustertool/pkg/helper"
|
"github.com/truecharts/public/clustertool/pkg/helper"
|
||||||
"github.com/truecharts/public/clustertool/pkg/talassist"
|
"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{}
|
commands := []string{}
|
||||||
//extraFlags = append(extraFlags, "--preserve")
|
|
||||||
|
|
||||||
talosPath := embed.GetTalosExec()
|
talosPath := embed.GetTalosExec()
|
||||||
if node == "" {
|
if node == "" {
|
||||||
|
|
||||||
for _, noderef := range talassist.TalConfig.Nodes {
|
for _, noderef := range talassist.TalConfig.Nodes {
|
||||||
// TODO add extraFlags
|
// 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)
|
commands = append(commands, cmd)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cmd := talosPath + " " + command + " --talosconfig " + helper.TalosConfigFile + " -n " + node + " "
|
cmd := talosPath + " " + command + " --talosconfig " + helper.TalosConfigFile + " -n " + node + " " + strings.Join(extraArgs, " ")
|
||||||
commands = append(commands, cmd)
|
commands = append(commands, cmd)
|
||||||
}
|
}
|
||||||
|
log.Debug().Msgf("%s Command rendered: %s", command, commands)
|
||||||
return commands
|
return commands
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user