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
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"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/kubectlcmds"
|
||||||
"github.com/truecharts/public/clustertool/pkg/talassist"
|
"github.com/truecharts/public/clustertool/pkg/talassist"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -17,13 +23,25 @@ var testcmd = &cobra.Command{
|
|||||||
Short: "tests specific code for developer usages",
|
Short: "tests specific code for developer usages",
|
||||||
Long: advTestCmdlongHelp,
|
Long: advTestCmdlongHelp,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
ctx := context.Background()
|
||||||
initfiles.LoadTalEnv(false)
|
initfiles.LoadTalEnv(false)
|
||||||
talassist.LoadTalConfig()
|
talassist.LoadTalConfig()
|
||||||
// err := fluxhandler.ProcessJSONFiles("./testdata/truenas_exports")
|
// err := fluxhandler.ProcessJSONFiles("./testdata/truenas_exports")
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
// log.Info().Msg("Error:", err)
|
// 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{
|
var bootstrap = &cobra.Command{
|
||||||
Use: "bootstrap",
|
Use: "bootstrap",
|
||||||
Short: "bootstrap first Talos Node",
|
Short: "bootstrap first Talos Node",
|
||||||
Example: "clustertool adv bootstrap",
|
Example: "clustertool talos bootstrap",
|
||||||
Long: advBootstrapLongHelp,
|
Long: advBootstrapLongHelp,
|
||||||
Run: bootstrapfunc,
|
Run: bootstrapfunc,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,9 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/truecharts/public/clustertool/pkg/gencmd"
|
"github.com/truecharts/public/clustertool/pkg/gencmd"
|
||||||
"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/sops"
|
"github.com/truecharts/public/clustertool/pkg/sops"
|
||||||
|
"github.com/truecharts/public/clustertool/pkg/talassist"
|
||||||
)
|
)
|
||||||
|
|
||||||
var advHealthLongHelp = strings.TrimSpace(`
|
var advHealthLongHelp = strings.TrimSpace(`
|
||||||
@@ -17,12 +19,14 @@ var advHealthLongHelp = strings.TrimSpace(`
|
|||||||
var health = &cobra.Command{
|
var health = &cobra.Command{
|
||||||
Use: "health",
|
Use: "health",
|
||||||
Short: "Check Talos Cluster Health",
|
Short: "Check Talos Cluster Health",
|
||||||
Example: "clustertool adv health",
|
Example: "clustertool talos health",
|
||||||
Long: advHealthLongHelp,
|
Long: advHealthLongHelp,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
if err := sops.DecryptFiles(); err != nil {
|
if err := sops.DecryptFiles(); err != nil {
|
||||||
log.Info().Msgf("Error decrypting files: %v\n", err)
|
log.Info().Msgf("Error decrypting files: %v\n", err)
|
||||||
}
|
}
|
||||||
|
initfiles.LoadTalEnv(false)
|
||||||
|
talassist.LoadTalConfig()
|
||||||
log.Info().Msg("Running Cluster HealthCheck")
|
log.Info().Msg("Running Cluster HealthCheck")
|
||||||
healthcmd := gencmd.GenPlain("health", helper.TalEnv["VIP_IP"], []string{})
|
healthcmd := gencmd.GenPlain("health", helper.TalEnv["VIP_IP"], []string{})
|
||||||
gencmd.ExecCmd(healthcmd[0])
|
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/rs/zerolog/log"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/truecharts/public/clustertool/pkg/gencmd"
|
"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/sops"
|
||||||
|
"github.com/truecharts/public/clustertool/pkg/talassist"
|
||||||
)
|
)
|
||||||
|
|
||||||
var advResetLongHelp = strings.TrimSpace(`
|
var advResetLongHelp = strings.TrimSpace(`
|
||||||
@@ -16,7 +18,7 @@ var advResetLongHelp = strings.TrimSpace(`
|
|||||||
var reset = &cobra.Command{
|
var reset = &cobra.Command{
|
||||||
Use: "reset",
|
Use: "reset",
|
||||||
Short: "Reset Talos Nodes and Kubernetes",
|
Short: "Reset Talos Nodes and Kubernetes",
|
||||||
Example: "clustertool adv reset <NodeIP>",
|
Example: "clustertool talos reset <NodeIP>",
|
||||||
Long: advResetLongHelp,
|
Long: advResetLongHelp,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
var extraArgs []string
|
var extraArgs []string
|
||||||
@@ -35,6 +37,8 @@ var reset = &cobra.Command{
|
|||||||
if err := sops.DecryptFiles(); err != nil {
|
if err := sops.DecryptFiles(); err != nil {
|
||||||
log.Info().Msgf("Error decrypting files: %v\n", err)
|
log.Info().Msgf("Error decrypting files: %v\n", err)
|
||||||
}
|
}
|
||||||
|
initfiles.LoadTalEnv(false)
|
||||||
|
talassist.LoadTalConfig()
|
||||||
|
|
||||||
log.Info().Msg("Running Cluster node Reset")
|
log.Info().Msg("Running Cluster node Reset")
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,9 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/truecharts/public/clustertool/pkg/gencmd"
|
"github.com/truecharts/public/clustertool/pkg/gencmd"
|
||||||
"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/sops"
|
"github.com/truecharts/public/clustertool/pkg/sops"
|
||||||
|
"github.com/truecharts/public/clustertool/pkg/talassist"
|
||||||
)
|
)
|
||||||
|
|
||||||
var upgradeLongHelp = strings.TrimSpace(`
|
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{
|
var upgrade = &cobra.Command{
|
||||||
Use: "upgrade",
|
Use: "upgrade",
|
||||||
Short: "Upgrade Talos Nodes and Kubernetes",
|
Short: "Upgrade Talos Nodes and Kubernetes",
|
||||||
Example: "clustertool upgrade <NodeIP>",
|
Example: "clustertool talos upgrade <NodeIP>",
|
||||||
Long: upgradeLongHelp,
|
Long: upgradeLongHelp,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
var extraArgs []string
|
var extraArgs []string
|
||||||
@@ -40,6 +42,8 @@ var upgrade = &cobra.Command{
|
|||||||
if err := sops.DecryptFiles(); err != nil {
|
if err := sops.DecryptFiles(); err != nil {
|
||||||
log.Info().Msgf("Error decrypting files: %v\n", err)
|
log.Info().Msgf("Error decrypting files: %v\n", err)
|
||||||
}
|
}
|
||||||
|
initfiles.LoadTalEnv(false)
|
||||||
|
talassist.LoadTalConfig()
|
||||||
|
|
||||||
log.Info().Msg("Running Cluster Upgrade")
|
log.Info().Msg("Running Cluster Upgrade")
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ require (
|
|||||||
github.com/budimanjojo/talhelper/v3 v3.0.8
|
github.com/budimanjojo/talhelper/v3 v3.0.8
|
||||||
github.com/getsops/sops/v3 v3.9.1
|
github.com/getsops/sops/v3 v3.9.1
|
||||||
github.com/go-git/go-git/v5 v5.12.0
|
github.com/go-git/go-git/v5 v5.12.0
|
||||||
|
github.com/go-logr/zerologr v1.2.3
|
||||||
github.com/go-playground/validator/v10 v10.22.1
|
github.com/go-playground/validator/v10 v10.22.1
|
||||||
github.com/invopop/jsonschema v0.12.0
|
github.com/invopop/jsonschema v0.12.0
|
||||||
github.com/joho/godotenv v1.5.1
|
github.com/joho/godotenv v1.5.1
|
||||||
|
|||||||
@@ -277,6 +277,8 @@ github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
|||||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||||
github.com/go-logr/zapr v1.3.0 h1:XGdV8XW8zdwFiwOA2Dryh1gj2KRQyOOoNmBy4EplIcQ=
|
github.com/go-logr/zapr v1.3.0 h1:XGdV8XW8zdwFiwOA2Dryh1gj2KRQyOOoNmBy4EplIcQ=
|
||||||
github.com/go-logr/zapr v1.3.0/go.mod h1:YKepepNBd1u/oyhd/yQmtjVXmm9uML4IXUgMOwR8/Gg=
|
github.com/go-logr/zapr v1.3.0/go.mod h1:YKepepNBd1u/oyhd/yQmtjVXmm9uML4IXUgMOwR8/Gg=
|
||||||
|
github.com/go-logr/zerologr v1.2.3 h1:up5N9vcH9Xck3jJkXzgyOxozT14R47IyDODz8LM1KSs=
|
||||||
|
github.com/go-logr/zerologr v1.2.3/go.mod h1:BxwGo7y5zgSHYR1BjbnHPyF/5ZjVKfKxAZANVu6E8Ho=
|
||||||
github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=
|
github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=
|
||||||
github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY=
|
github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY=
|
||||||
github.com/go-openapi/jsonreference v0.21.0 h1:Rs+Y7hSXT83Jacb7kFyjn4ijOuVGSvOdF2+tg1TRrwQ=
|
github.com/go-openapi/jsonreference v0.21.0 h1:Rs+Y7hSXT83Jacb7kFyjn4ijOuVGSvOdF2+tg1TRrwQ=
|
||||||
|
|||||||
@@ -8,9 +8,11 @@ import (
|
|||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
|
|
||||||
|
"github.com/go-logr/zerologr"
|
||||||
"github.com/truecharts/public/clustertool/cmd"
|
"github.com/truecharts/public/clustertool/cmd"
|
||||||
"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"
|
||||||
|
k8slog "sigs.k8s.io/controller-runtime/pkg/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Version = "dev"
|
var Version = "dev"
|
||||||
@@ -54,6 +56,15 @@ func main() {
|
|||||||
NoColor: noColor, // Set to true if you prefer no color
|
NoColor: noColor, // Set to true if you prefer no color
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Initialize zerolog with console output
|
||||||
|
zlogger := zerolog.New(os.Stderr).With().Timestamp().Logger()
|
||||||
|
|
||||||
|
// Wrap zerolog with zerologr to create a logr.Logger
|
||||||
|
logger := zerologr.New(&zlogger)
|
||||||
|
|
||||||
|
// Set this logger for dependencies expecting log.SetLogger
|
||||||
|
k8slog.SetLogger(logger)
|
||||||
|
|
||||||
fmt.Printf("\n%s\n", helper.Logo)
|
fmt.Printf("\n%s\n", helper.Logo)
|
||||||
fmt.Printf("---\nClustertool Version: %s\n---\n", Version)
|
fmt.Printf("---\nClustertool Version: %s\n---\n", Version)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user