fix(clustertool): revert previous apply changes due to a mistake

This commit is contained in:
Kjeld Schouten
2024-11-05 23:45:36 +01:00
parent 61a01f3299
commit 45582c596b
+39 -20
View File
@@ -1,30 +1,49 @@
package gencmd
import (
"io"
"os"
"strings"
"github.com/rs/zerolog/log"
talhelperCfg "github.com/budimanjojo/talhelper/v3/pkg/config"
"github.com/budimanjojo/talhelper/v3/pkg/generate"
"github.com/truecharts/public/clustertool/embed"
"github.com/truecharts/public/clustertool/pkg/helper"
"github.com/truecharts/public/clustertool/pkg/talassist"
"github.com/truecharts/public/clustertool/pkg/initfiles"
)
func GenApply(node string, extraFlags []string) []string {
commands := []string{}
//extraFlags = append(extraFlags, "--preserve")
talosPath := embed.GetTalosExec()
if node == "" {
for _, nodeRef := range talassist.IpAddresses {
talassist.LoadNodeIPs()
// TODO add extraFlags
// TODO: add images Refs
// TODO: add schematic
cmd := talosPath + " apply --talosconfig " + helper.TalosConfigFile + " -n " + nodeRef + " "
commands = append(commands, cmd)
}
} else {
cmd := talosPath + " apply --talosconfig " + helper.TalosConfigFile + " -n " + node + " "
commands = append(commands, cmd)
initfiles.LoadTalEnv(false)
cfg, err := talhelperCfg.LoadAndValidateFromFile(helper.TalConfigFile, []string{helper.ClusterEnvFile}, false)
if err != nil {
log.Fatal().Err(err).Msg("failed to parse talconfig or talenv file: %s")
}
return commands
applyStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
// replace this with self-made stuff, be aware we also need to use the configfile
err = generate.GenerateApplyCommand(cfg, helper.TalosGenerated, node, extraFlags)
w.Close()
out, _ := io.ReadAll(r)
os.Stdout = applyStdout
sliceOut := strings.Split(string(out), ";\n")
talosPath := embed.GetTalosExec()
var slice []string
for _, str := range sliceOut {
if str != "" {
str = strings.ReplaceAll(str, "talosctl", talosPath)
slice = append(slice, str)
}
}
if err != nil {
log.Fatal().Err(err).Msg("failed to generate talosctl apply command: %s")
}
return slice
}