From 5f54ea6a0f06e9497eb62ebdf15094ed568752b1 Mon Sep 17 00:00:00 2001 From: Kjeld Schouten Date: Mon, 11 Nov 2024 14:18:14 +0100 Subject: [PATCH] fix(clustertool): Prevent empty extraargs to be added to cmd --- clustertool/pkg/gencmd/plain.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/clustertool/pkg/gencmd/plain.go b/clustertool/pkg/gencmd/plain.go index c0420d4004f..e64b2f84ef7 100644 --- a/clustertool/pkg/gencmd/plain.go +++ b/clustertool/pkg/gencmd/plain.go @@ -14,16 +14,33 @@ func GenPlain(command string, node string, extraArgs []string) []string { commands := []string{} talosPath := embed.GetTalosExec() + log.Debug().Msg("Generating plain CMDs...") if node == "" { + log.Debug().Msg("Cmd Nodes is empty, rendering cmds for all nodes...") for _, noderef := range talassist.TalConfig.Nodes { - cmd := talosPath + " " + command + " --talosconfig " + helper.TalosConfigFile + " -n " + noderef.IPAddress + " " + strings.Join(extraArgs, " ") + log.Debug().Msgf("Rendering for node: %s", noderef) + cmd := talosPath + " " + command + " --talosconfig " + helper.TalosConfigFile + " -n " + noderef.IPAddress + if len(extraArgs) == 0 { + log.Debug().Msg("extraArgs is empty, not adding extra args to cmd") + } else { + log.Debug().Msgf("extraArgs not empty, adding extra args to cmd: %s", extraArgs) + cmd = cmd + " " + strings.Join(extraArgs, " ") + } commands = append(commands, cmd) } } else { - cmd := talosPath + " " + command + " --talosconfig " + helper.TalosConfigFile + " -n " + node + " " + strings.Join(extraArgs, " ") + log.Debug().Msgf("Rendering for single node: %s", node) + cmd := talosPath + " " + command + " --talosconfig " + helper.TalosConfigFile + " -n " + node + if len(extraArgs) == 0 { + log.Debug().Msg("extraArgs is empty, not adding extra args to cmd") + } else { + log.Debug().Msgf("extraArgs not empty, adding extra args to cmd: %s", extraArgs) + cmd = cmd + " " + strings.Join(extraArgs, " ") + } + commands = append(commands, cmd) } - log.Debug().Msgf("%s Command rendered: %s", command, commands) + log.Debug().Msgf("%s Commands rendered: %s", command, commands) return commands }