feat(clustertool): move some functions away from talhelper
This commit is contained in:
@@ -105,7 +105,7 @@ func RunApply(kubeconfig bool, node string, extraArgs []string) {
|
||||
gencmd.ExecCmds(taloscmds, true)
|
||||
|
||||
if kubeconfig {
|
||||
kubeconfigcmds := gencmd.GenKubeConfig(helper.TalEnv["VIP_IP"])
|
||||
kubeconfigcmds := gencmd.GenKubeConfig(helper.TalEnv["VIP_IP"], extraArgs)
|
||||
gencmd.ExecCmd(kubeconfigcmds)
|
||||
}
|
||||
|
||||
|
||||
@@ -4,11 +4,9 @@ import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
talhelperCfg "github.com/budimanjojo/talhelper/v3/pkg/config"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/truecharts/public/clustertool/pkg/fluxhandler"
|
||||
"github.com/truecharts/public/clustertool/pkg/helper"
|
||||
"github.com/truecharts/public/clustertool/pkg/initfiles"
|
||||
"github.com/truecharts/public/clustertool/pkg/sops"
|
||||
)
|
||||
@@ -29,11 +27,6 @@ var fluxbootstrap = &cobra.Command{
|
||||
log.Info().Msgf("Error decrypting files: %v\n", err)
|
||||
}
|
||||
initfiles.LoadTalEnv(false)
|
||||
_, 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")
|
||||
}
|
||||
|
||||
fluxhandler.FluxBootstrap(ctx)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ var upgrade = &cobra.Command{
|
||||
gencmd.ExecCmd(kubeUpgradeCmd)
|
||||
|
||||
log.Info().Msg("(re)Loading KubeConfig)")
|
||||
kubeconfigcmds := gencmd.GenKubeConfig(helper.TalEnv["VIP_IP"])
|
||||
kubeconfigcmds := gencmd.GenKubeConfig(helper.TalEnv["VIP_IP"], extraArgs)
|
||||
gencmd.ExecCmd(kubeconfigcmds)
|
||||
|
||||
},
|
||||
|
||||
@@ -1,49 +1,30 @@
|
||||
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/initfiles"
|
||||
"github.com/truecharts/public/clustertool/pkg/talassist"
|
||||
)
|
||||
|
||||
func GenApply(node string, extraFlags []string) []string {
|
||||
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")
|
||||
}
|
||||
|
||||
applyStdout := os.Stdout
|
||||
r, w, _ := os.Pipe()
|
||||
os.Stdout = w
|
||||
commands := []string{}
|
||||
//extraFlags = append(extraFlags, "--preserve")
|
||||
|
||||
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 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)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("failed to generate talosctl apply command: %s")
|
||||
}
|
||||
return slice
|
||||
return commands
|
||||
}
|
||||
|
||||
@@ -2,21 +2,18 @@ package gencmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"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/fluxhandler"
|
||||
"github.com/truecharts/public/clustertool/pkg/helper"
|
||||
"github.com/truecharts/public/clustertool/pkg/kubectlcmds"
|
||||
"github.com/truecharts/public/clustertool/pkg/nodestatus"
|
||||
"github.com/truecharts/public/clustertool/pkg/sops"
|
||||
"github.com/truecharts/public/clustertool/pkg/talassist"
|
||||
)
|
||||
|
||||
var HelmRepos map[string]*fluxhandler.HelmRepo
|
||||
@@ -28,29 +25,8 @@ var manifestPaths = []string{
|
||||
}
|
||||
|
||||
func GenBootstrap(node string, extraFlags []string) string {
|
||||
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")
|
||||
}
|
||||
|
||||
applyStdout := os.Stdout
|
||||
r, w, _ := os.Pipe()
|
||||
os.Stdout = w
|
||||
|
||||
err = generate.GenerateBootstrapCommand(cfg, helper.TalosGenerated, node, extraFlags)
|
||||
|
||||
w.Close()
|
||||
out, _ := io.ReadAll(r)
|
||||
os.Stdout = applyStdout
|
||||
|
||||
talosPath := embed.GetTalosExec()
|
||||
strout := strings.ReplaceAll(string(out), "talosctl", talosPath)
|
||||
strout = strings.ReplaceAll(strout, "\n", "")
|
||||
strout = strings.ReplaceAll(strout, ";", "")
|
||||
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("failed to generate talosctl bootstrap command: %s")
|
||||
}
|
||||
strout := talosPath + "bootstrap --talosconfig " + helper.TalosConfigFile + " -n " + talassist.IpAddresses[0]
|
||||
return strout
|
||||
}
|
||||
|
||||
@@ -83,7 +59,7 @@ func RunBootstrap(args []string) {
|
||||
|
||||
log.Info().Msgf("Bootstrap: Configuring kubectl for VIP: %v", helper.TalEnv["VIP_IP"])
|
||||
// Ensure kubeconfig is loaded
|
||||
kubeconfigcmds := GenKubeConfig(helper.TalEnv["VIP_IP"])
|
||||
kubeconfigcmds := GenKubeConfig(helper.TalEnv["VIP_IP"], extraArgs)
|
||||
ExecCmd(kubeconfigcmds)
|
||||
|
||||
// Desired pod names
|
||||
|
||||
@@ -5,8 +5,11 @@ import (
|
||||
"github.com/truecharts/public/clustertool/pkg/helper"
|
||||
)
|
||||
|
||||
func GenKubeConfig(node string) string {
|
||||
func GenKubeConfig(node string, extraFlags []string) string {
|
||||
|
||||
//extraFlags = append(extraFlags, "--preserve")
|
||||
talosPath := embed.GetTalosExec()
|
||||
strout := talosPath + " kubeconfig --talosconfig " + helper.TalosConfigFile + " -n " + node + " --force"
|
||||
return strout
|
||||
cmd := talosPath + " kubeconfig --talosconfig " + helper.TalosConfigFile + " -n " + node + " "
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -1,47 +1,30 @@
|
||||
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"
|
||||
)
|
||||
|
||||
func GenReset(node string, extraFlags []string) []string {
|
||||
cfg, err := talhelperCfg.LoadAndValidateFromFile(helper.TalConfigFile, []string{helper.ClusterEnvFile}, false)
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msgf("failed to parse talconfig or talenv file: %s", err)
|
||||
}
|
||||
|
||||
resetStdout := os.Stdout
|
||||
r, w, _ := os.Pipe()
|
||||
os.Stdout = w
|
||||
commands := []string{}
|
||||
//extraFlags = append(extraFlags, "--preserve")
|
||||
|
||||
err = generate.GenerateResetCommand(cfg, helper.TalosGenerated, node, extraFlags)
|
||||
|
||||
w.Close()
|
||||
out, _ := io.ReadAll(r)
|
||||
os.Stdout = resetStdout
|
||||
|
||||
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 node == "" {
|
||||
for _, nodeRef := range talassist.IpAddresses {
|
||||
talassist.LoadNodeIPs()
|
||||
// TODO add extraFlags
|
||||
|
||||
// TODO: add images Refs
|
||||
// TODO: add schematic
|
||||
cmd := talosPath + " reset --talosconfig " + helper.TalosConfigFile + " -n " + nodeRef + " "
|
||||
commands = append(commands, cmd)
|
||||
}
|
||||
|
||||
} else {
|
||||
cmd := talosPath + " reset --talosconfig " + helper.TalosConfigFile + " -n " + node + " "
|
||||
commands = append(commands, cmd)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msgf("failed to generate talosctl reset command: %s", err)
|
||||
}
|
||||
return slice
|
||||
return commands
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/truecharts/public/clustertool/pkg/helper"
|
||||
)
|
||||
|
||||
// TODO: remove talhelper dependency for cmd creation
|
||||
func GenUpgrade(node string, extraFlags []string) []string {
|
||||
cfg, err := talhelperCfg.LoadAndValidateFromFile(helper.TalConfigFile, []string{helper.ClusterEnvFile}, false)
|
||||
if err != nil {
|
||||
|
||||
@@ -30,7 +30,7 @@ func LoadNodeIPs() error {
|
||||
|
||||
// Extract the IP addresses into a list
|
||||
for _, node := range config.Nodes {
|
||||
ipAddresses = append(ipAddresses, node.IPAddress)
|
||||
IpAddresses = append(IpAddresses, node.IPAddress)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package talassist
|
||||
|
||||
var (
|
||||
ipAddresses = []string{}
|
||||
IpAddresses = []string{}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user