From 45582c596b0231a3c1db82ecc5fe5e1376b4135a Mon Sep 17 00:00:00 2001 From: Kjeld Schouten Date: Tue, 5 Nov 2024 23:45:36 +0100 Subject: [PATCH] fix(clustertool): revert previous apply changes due to a mistake --- clustertool/pkg/gencmd/apply.go | 59 ++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/clustertool/pkg/gencmd/apply.go b/clustertool/pkg/gencmd/apply.go index 36b68d74b20..f31beb11177 100644 --- a/clustertool/pkg/gencmd/apply.go +++ b/clustertool/pkg/gencmd/apply.go @@ -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 }