Skip to content

Commit

Permalink
fix(clustertool): add commands debug and allow for extra args
Browse files Browse the repository at this point in the history
  • Loading branch information
PrivatePuffin committed Nov 6, 2024
1 parent eb1e744 commit a11f019
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 9 deletions.
1 change: 1 addition & 0 deletions clustertool/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ embeded/darwin*
embeded/windows*
embeded/freebsd*
.devcontainer
.envrc
6 changes: 6 additions & 0 deletions clustertool/cmd/adv_testcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(`
Expand All @@ -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])
},
}

Expand Down
9 changes: 6 additions & 3 deletions clustertool/pkg/gencmd/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
}
4 changes: 3 additions & 1 deletion clustertool/pkg/gencmd/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,20 @@ 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"})

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"])
Expand Down
5 changes: 4 additions & 1 deletion clustertool/pkg/gencmd/execcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 7 additions & 4 deletions clustertool/pkg/gencmd/plain.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit a11f019

Please sign in to comment.