fix(clustertool): fix kubectl logging error, add kubeconfig command and fix some command docs
This commit is contained in:
@@ -1,10 +1,16 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/truecharts/public/clustertool/pkg/helper"
|
||||
"github.com/truecharts/public/clustertool/pkg/initfiles"
|
||||
"github.com/truecharts/public/clustertool/pkg/kubectlcmds"
|
||||
"github.com/truecharts/public/clustertool/pkg/talassist"
|
||||
)
|
||||
|
||||
@@ -17,13 +23,25 @@ var testcmd = &cobra.Command{
|
||||
Short: "tests specific code for developer usages",
|
||||
Long: advTestCmdlongHelp,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
ctx := context.Background()
|
||||
initfiles.LoadTalEnv(false)
|
||||
talassist.LoadTalConfig()
|
||||
// err := fluxhandler.ProcessJSONFiles("./testdata/truenas_exports")
|
||||
// if err != nil {
|
||||
// log.Info().Msg("Error:", err)
|
||||
// }
|
||||
RunApply(false, "", []string{})
|
||||
var manifestPaths = []string{
|
||||
filepath.Join(helper.KubernetesPath, "flux-system", "flux", "sopssecret.secret.yaml"),
|
||||
filepath.Join(helper.KubernetesPath, "flux-system", "flux", "deploykey.secret.yaml"),
|
||||
filepath.Join(helper.KubernetesPath, "flux-system", "flux", "clustersettings.secret.yaml"),
|
||||
}
|
||||
for _, filePath := range manifestPaths {
|
||||
log.Info().Msgf("Bootstrap: Loading Manifest: %v", filePath)
|
||||
if err := kubectlcmds.KubectlApply(ctx, filePath); err != nil {
|
||||
log.Info().Msgf("Error applying manifest for %s: %v\n", filepath.Base(filePath), err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ var advBootstrapLongHelp = strings.TrimSpace(`
|
||||
var bootstrap = &cobra.Command{
|
||||
Use: "bootstrap",
|
||||
Short: "bootstrap first Talos Node",
|
||||
Example: "clustertool adv bootstrap",
|
||||
Example: "clustertool talos bootstrap",
|
||||
Long: advBootstrapLongHelp,
|
||||
Run: bootstrapfunc,
|
||||
}
|
||||
|
||||
@@ -7,7 +7,9 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/truecharts/public/clustertool/pkg/gencmd"
|
||||
"github.com/truecharts/public/clustertool/pkg/helper"
|
||||
"github.com/truecharts/public/clustertool/pkg/initfiles"
|
||||
"github.com/truecharts/public/clustertool/pkg/sops"
|
||||
"github.com/truecharts/public/clustertool/pkg/talassist"
|
||||
)
|
||||
|
||||
var advHealthLongHelp = strings.TrimSpace(`
|
||||
@@ -17,12 +19,14 @@ var advHealthLongHelp = strings.TrimSpace(`
|
||||
var health = &cobra.Command{
|
||||
Use: "health",
|
||||
Short: "Check Talos Cluster Health",
|
||||
Example: "clustertool adv health",
|
||||
Example: "clustertool talos health",
|
||||
Long: advHealthLongHelp,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if err := sops.DecryptFiles(); err != nil {
|
||||
log.Info().Msgf("Error decrypting files: %v\n", err)
|
||||
}
|
||||
initfiles.LoadTalEnv(false)
|
||||
talassist.LoadTalConfig()
|
||||
log.Info().Msg("Running Cluster HealthCheck")
|
||||
healthcmd := gencmd.GenPlain("health", helper.TalEnv["VIP_IP"], []string{})
|
||||
gencmd.ExecCmd(healthcmd[0])
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/truecharts/public/clustertool/pkg/gencmd"
|
||||
"github.com/truecharts/public/clustertool/pkg/initfiles"
|
||||
"github.com/truecharts/public/clustertool/pkg/sops"
|
||||
"github.com/truecharts/public/clustertool/pkg/talassist"
|
||||
)
|
||||
|
||||
var advKubeconfigLongHelp = strings.TrimSpace(`
|
||||
|
||||
`)
|
||||
|
||||
var kubeconfig = &cobra.Command{
|
||||
Use: "kubeconfig",
|
||||
Short: "kubeconfig for Talos Cluster",
|
||||
Example: "clustertool talos kubeconfig <NodeIP>",
|
||||
Long: advResetLongHelp,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
var extraArgs []string
|
||||
node := ""
|
||||
|
||||
if len(args) > 1 {
|
||||
extraArgs = args[1:]
|
||||
}
|
||||
if len(args) >= 1 {
|
||||
node = args[0]
|
||||
if args[0] == "all" {
|
||||
node = ""
|
||||
}
|
||||
}
|
||||
|
||||
if err := sops.DecryptFiles(); err != nil {
|
||||
log.Info().Msgf("Error decrypting files: %v\n", err)
|
||||
}
|
||||
initfiles.LoadTalEnv(false)
|
||||
talassist.LoadTalConfig()
|
||||
log.Info().Msg("Running Cluster kubeconfig")
|
||||
|
||||
taloscmds := gencmd.GenPlain("kubeconfig", node, extraArgs)
|
||||
gencmd.ExecCmds(taloscmds, true)
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
talosCmd.AddCommand(kubeconfig)
|
||||
}
|
||||
@@ -6,7 +6,9 @@ import (
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/truecharts/public/clustertool/pkg/gencmd"
|
||||
"github.com/truecharts/public/clustertool/pkg/initfiles"
|
||||
"github.com/truecharts/public/clustertool/pkg/sops"
|
||||
"github.com/truecharts/public/clustertool/pkg/talassist"
|
||||
)
|
||||
|
||||
var advResetLongHelp = strings.TrimSpace(`
|
||||
@@ -16,7 +18,7 @@ var advResetLongHelp = strings.TrimSpace(`
|
||||
var reset = &cobra.Command{
|
||||
Use: "reset",
|
||||
Short: "Reset Talos Nodes and Kubernetes",
|
||||
Example: "clustertool adv reset <NodeIP>",
|
||||
Example: "clustertool talos reset <NodeIP>",
|
||||
Long: advResetLongHelp,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
var extraArgs []string
|
||||
@@ -35,6 +37,8 @@ var reset = &cobra.Command{
|
||||
if err := sops.DecryptFiles(); err != nil {
|
||||
log.Info().Msgf("Error decrypting files: %v\n", err)
|
||||
}
|
||||
initfiles.LoadTalEnv(false)
|
||||
talassist.LoadTalConfig()
|
||||
|
||||
log.Info().Msg("Running Cluster node Reset")
|
||||
|
||||
|
||||
@@ -7,7 +7,9 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/truecharts/public/clustertool/pkg/gencmd"
|
||||
"github.com/truecharts/public/clustertool/pkg/helper"
|
||||
"github.com/truecharts/public/clustertool/pkg/initfiles"
|
||||
"github.com/truecharts/public/clustertool/pkg/sops"
|
||||
"github.com/truecharts/public/clustertool/pkg/talassist"
|
||||
)
|
||||
|
||||
var upgradeLongHelp = strings.TrimSpace(`
|
||||
@@ -21,7 +23,7 @@ On top of this, after upgrading Talos on all nodes, it also executes kubernetes-
|
||||
var upgrade = &cobra.Command{
|
||||
Use: "upgrade",
|
||||
Short: "Upgrade Talos Nodes and Kubernetes",
|
||||
Example: "clustertool upgrade <NodeIP>",
|
||||
Example: "clustertool talos upgrade <NodeIP>",
|
||||
Long: upgradeLongHelp,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
var extraArgs []string
|
||||
@@ -40,6 +42,8 @@ var upgrade = &cobra.Command{
|
||||
if err := sops.DecryptFiles(); err != nil {
|
||||
log.Info().Msgf("Error decrypting files: %v\n", err)
|
||||
}
|
||||
initfiles.LoadTalEnv(false)
|
||||
talassist.LoadTalConfig()
|
||||
|
||||
log.Info().Msg("Running Cluster Upgrade")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user