From 92f8d1285f4d5fcfcf3045631e8dc5da0a68b115 Mon Sep 17 00:00:00 2001 From: idebeijer <71566757+idebeijer@users.noreply.github.com> Date: Sun, 11 Aug 2024 18:17:57 +0200 Subject: [PATCH] fix: add k8s client auth plugins Fix and prevent errors like: Error: no Auth Provider found for name "oidc" --- cmd/root.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 26ef6c6..4231682 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -8,6 +8,7 @@ import ( "github.com/idebeijer/kubert/internal/config" "github.com/spf13/cobra" "github.com/spf13/viper" + _ "k8s.io/client-go/plugin/pkg/client/auth" ) const ( @@ -62,10 +63,6 @@ func (c *RootCmd) addCommands() { func (c *RootCmd) initConfig() { var level slog.Level - if viper.GetBool("debug") { - level = slog.LevelDebug - } - slog.SetLogLoggerLevel(level) if c.cfgFile != "" { // Use config file from the flag. @@ -81,6 +78,7 @@ func (c *RootCmd) initConfig() { viper.SetConfigName(".kubert.yaml") } + viper.SetEnvPrefix("kubert") viper.AutomaticEnv() // If a config file is found, read it in. @@ -89,4 +87,9 @@ func (c *RootCmd) initConfig() { } _ = viper.ReadInConfig() _ = viper.Unmarshal(&config.Cfg) + + if viper.GetBool("debug") { + level = slog.LevelDebug + } + slog.SetLogLoggerLevel(level) }