From 055ed7379de466ece3a5d2cf39888bad5ccc9ad2 Mon Sep 17 00:00:00 2001 From: Losev Valery Date: Mon, 13 Jul 2026 15:06:05 +0400 Subject: [PATCH 1/3] add the ability to use d8 in windows Signed-off-by: Losev Valery --- internal/backup/cmd/flags.go | 9 +++------ internal/plugins/flags/flags.go | 7 ++----- internal/status/cmd/flags.go | 11 ++++------- internal/system/flags/flags.go | 11 ++++------- internal/tools/sigmigrate/cmd/flags.go | 8 ++------ internal/utilk8s/clientset.go | 12 ++++++++++++ 6 files changed, 27 insertions(+), 31 deletions(-) diff --git a/internal/backup/cmd/flags.go b/internal/backup/cmd/flags.go index f16d42fda..7d9b03671 100644 --- a/internal/backup/cmd/flags.go +++ b/internal/backup/cmd/flags.go @@ -1,16 +1,13 @@ package backup import ( - "os" - "github.com/spf13/pflag" + + "github.com/deckhouse/deckhouse-cli/internal/utilk8s" ) func addPersistentFlags(flagSet *pflag.FlagSet) { - defaultKubeconfigPath := os.ExpandEnv("$HOME/.kube/config") - if p := os.Getenv("KUBECONFIG"); p != "" { - defaultKubeconfigPath = p - } + defaultKubeconfigPath := utilk8s.DefaultKubeconfigPath() flagSet.StringP( "kubeconfig", "k", diff --git a/internal/plugins/flags/flags.go b/internal/plugins/flags/flags.go index e91838259..6c26718e5 100644 --- a/internal/plugins/flags/flags.go +++ b/internal/plugins/flags/flags.go @@ -22,6 +22,7 @@ import ( "github.com/spf13/pflag" rppflags "github.com/deckhouse/deckhouse-cli/internal/rpp/flags" + "github.com/deckhouse/deckhouse-cli/internal/utilk8s" ) const ( @@ -61,11 +62,7 @@ func skipClusterChecksDefault() bool { } func defaultKubeconfigPath() string { - if v := os.Getenv("KUBECONFIG"); v != "" { - return v - } - - return os.ExpandEnv("$HOME/.kube/config") + return utilk8s.DefaultKubeconfigPath() } func AddFlags(flagSet *pflag.FlagSet) { diff --git a/internal/status/cmd/flags.go b/internal/status/cmd/flags.go index 9c16861de..5c9f3b09a 100644 --- a/internal/status/cmd/flags.go +++ b/internal/status/cmd/flags.go @@ -17,21 +17,18 @@ limitations under the License. package status import ( - "os" - "github.com/spf13/pflag" + + "github.com/deckhouse/deckhouse-cli/internal/utilk8s" ) func addPersistentFlags(flagSet *pflag.FlagSet) { - defaultKubeconfigPath := os.ExpandEnv("$HOME/.kube/config") - if p := os.Getenv("KUBECONFIG"); p != "" { - defaultKubeconfigPath = p - } + defaultKubeconfigPath := utilk8s.DefaultKubeconfigPath() flagSet.StringP( "kubeconfig", "k", defaultKubeconfigPath, - "KubeConfig of the cluster. (default is $KUBECONFIG when it is set, $HOME/.kube/config otherwise)", + "Path to kubeconfig file. (default is $KUBECONFIG when it is set, otherwise the default kubeconfig path for the current OS user)", ) flagSet.String("context", "", "The name of the kubeconfig context to use") diff --git a/internal/system/flags/flags.go b/internal/system/flags/flags.go index fbf7e9d00..f507ab2aa 100644 --- a/internal/system/flags/flags.go +++ b/internal/system/flags/flags.go @@ -17,22 +17,19 @@ limitations under the License. package flags import ( - "os" - "github.com/spf13/cobra" + + "github.com/deckhouse/deckhouse-cli/internal/utilk8s" ) func AddPersistentFlags(cmd *cobra.Command) { - defaultKubeconfigPath := os.ExpandEnv("$HOME/.kube/config") - if p := os.Getenv("KUBECONFIG"); p != "" { - defaultKubeconfigPath = p - } + defaultKubeconfigPath := utilk8s.DefaultKubeconfigPath() cmd.PersistentFlags().StringP( "kubeconfig", "k", defaultKubeconfigPath, - "KubeConfig of the cluster. (default is $KUBECONFIG when it is set, $HOME/.kube/config otherwise)", + "Path to kubeconfig file. (default is $KUBECONFIG when it is set, otherwise the default kubeconfig path for the current OS user)", ) cmd.PersistentFlags().String("context", "", "The name of the kubeconfig context to use") diff --git a/internal/tools/sigmigrate/cmd/flags.go b/internal/tools/sigmigrate/cmd/flags.go index 80acd1779..39cdee7ef 100644 --- a/internal/tools/sigmigrate/cmd/flags.go +++ b/internal/tools/sigmigrate/cmd/flags.go @@ -17,11 +17,10 @@ limitations under the License. package cmd import ( - "os" - "github.com/spf13/pflag" "github.com/deckhouse/deckhouse-cli/internal/tools/sigmigrate" + "github.com/deckhouse/deckhouse-cli/internal/utilk8s" ) const ( @@ -47,10 +46,7 @@ func addFlags(flags *pflag.FlagSet) { "Set the log level (INFO, DEBUG, TRACE). Defaults to DEBUG.", ) - defaultKubeconfigPath := os.ExpandEnv("$HOME/.kube/config") - if p := os.Getenv("KUBECONFIG"); p != "" { - defaultKubeconfigPath = p - } + defaultKubeconfigPath := utilk8s.DefaultKubeconfigPath() flags.String( "kubeconfig", diff --git a/internal/utilk8s/clientset.go b/internal/utilk8s/clientset.go index 2c9024f11..559dcb04d 100644 --- a/internal/utilk8s/clientset.go +++ b/internal/utilk8s/clientset.go @@ -2,6 +2,7 @@ package utilk8s import ( "fmt" + "os" "path/filepath" "k8s.io/client-go/kubernetes" @@ -11,6 +12,17 @@ import ( const DefaultKubeContext = "" +// DefaultKubeconfigPath returns the default path to the kubeconfig file. +// It respects the "KUBECONFIG" environment variable (clientcmd.RecommendedConfigPathEnvVar) +// when set, and falls back to the platform-appropriate default path (clientcmd.RecommendedHomeFile). +// This correctly resolves the home directory on all platforms, including "Windows" where $HOME is not set but %USERPROFILE% is. +func DefaultKubeconfigPath() string { + if p := os.Getenv(clientcmd.RecommendedConfigPathEnvVar); p != "" { + return p + } + return clientcmd.RecommendedHomeFile +} + // SetupK8sClientSet reads kubeconfig file at kubeconfigPath and constructs a kubernetes clientset from it. // If contextName is not empty, context under that name is used instead of default. func SetupK8sClientSet(kubeconfigPath, contextName string) (*rest.Config, *kubernetes.Clientset, error) { From 10be8de7fd54c49ec42b4a260982ac918e5d1766 Mon Sep 17 00:00:00 2001 From: Losev Valery Date: Mon, 13 Jul 2026 17:54:03 +0400 Subject: [PATCH 2/3] add the ability to use d8 in windows v2 Signed-off-by: Losev Valery --- internal/utilk8s/clientset.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/utilk8s/clientset.go b/internal/utilk8s/clientset.go index 559dcb04d..420333e0c 100644 --- a/internal/utilk8s/clientset.go +++ b/internal/utilk8s/clientset.go @@ -20,6 +20,7 @@ func DefaultKubeconfigPath() string { if p := os.Getenv(clientcmd.RecommendedConfigPathEnvVar); p != "" { return p } + return clientcmd.RecommendedHomeFile } From 8467a3d4bfbd0dd2a4c0a72fc2b62c9e1d038063 Mon Sep 17 00:00:00 2001 From: Roman Berezkin Date: Mon, 13 Jul 2026 16:55:28 +0300 Subject: [PATCH 3/3] align kubeconfig flag help with cross-platform default path Signed-off-by: Roman Berezkin --- internal/backup/cmd/flags.go | 2 +- internal/tools/sigmigrate/cmd/flags.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/backup/cmd/flags.go b/internal/backup/cmd/flags.go index 7d9b03671..3271ab55e 100644 --- a/internal/backup/cmd/flags.go +++ b/internal/backup/cmd/flags.go @@ -12,7 +12,7 @@ func addPersistentFlags(flagSet *pflag.FlagSet) { flagSet.StringP( "kubeconfig", "k", defaultKubeconfigPath, - "KubeConfig of the cluster. (default is $KUBECONFIG when it is set, $HOME/.kube/config otherwise)", + "Path to kubeconfig file. (default is $KUBECONFIG when it is set, otherwise the default kubeconfig path for the current OS user)", ) flagSet.String("context", "", "The name of the kubeconfig context to use") diff --git a/internal/tools/sigmigrate/cmd/flags.go b/internal/tools/sigmigrate/cmd/flags.go index 39cdee7ef..e607dc1eb 100644 --- a/internal/tools/sigmigrate/cmd/flags.go +++ b/internal/tools/sigmigrate/cmd/flags.go @@ -51,7 +51,7 @@ func addFlags(flags *pflag.FlagSet) { flags.String( "kubeconfig", defaultKubeconfigPath, - "Path to the kubeconfig file to use for CLI requests. (default is $KUBECONFIG when it is set, $HOME/.kube/config otherwise)", + "Path to the kubeconfig file to use for CLI requests. (default is $KUBECONFIG when it is set, otherwise the default kubeconfig path for the current OS user)", ) flags.String(