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