From f85f387ff915cd49f315e2d2bacf94c8ea39b927 Mon Sep 17 00:00:00 2001 From: Alessio Dionisi Date: Thu, 3 Oct 2024 09:07:33 +0200 Subject: [PATCH] fix: fix get kubeconfig command --- cmd/get/kubeconfig.go | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/cmd/get/kubeconfig.go b/cmd/get/kubeconfig.go index 833823fdf..afd9a277a 100644 --- a/cmd/get/kubeconfig.go +++ b/cmd/get/kubeconfig.go @@ -22,6 +22,7 @@ import ( "github.com/sighupio/furyctl/internal/git" cobrax "github.com/sighupio/furyctl/internal/x/cobra" execx "github.com/sighupio/furyctl/internal/x/exec" + iox "github.com/sighupio/furyctl/internal/x/io" "github.com/sighupio/furyctl/pkg/dependencies" dist "github.com/sighupio/furyctl/pkg/distribution" netx "github.com/sighupio/furyctl/pkg/x/net" @@ -83,6 +84,7 @@ func NewKubeconfigCmd() *cobra.Command { // Get home dir. logrus.Debug("Getting Home directory path...") + homeDir, err := os.UserHomeDir() if err != nil { cmdEvent.AddErrorMessage(err) @@ -91,16 +93,16 @@ func NewKubeconfigCmd() *cobra.Command { return fmt.Errorf("error while getting user home directory: %w", err) } + if outDir == "" { + outDir = homeDir + } + if binPath == "" { - binPath = path.Join(homeDir, ".furyctl", "bin") + binPath = path.Join(outDir, ".furyctl", "bin") } parsedGitProtocol := (git.Protocol)(gitProtocol) - if outDir == "" { - outDir = currentDir - } - // Init packages. execx.Debug = debug @@ -140,7 +142,7 @@ func NewKubeconfigCmd() *cobra.Command { basePath := path.Join(outDir, ".furyctl", res.MinimalConf.Metadata.Name) // Init second half of collaborators. - depsdl := dependencies.NewCachingDownloader(client, homeDir, basePath, binPath, parsedGitProtocol) + depsdl := dependencies.NewCachingDownloader(client, outDir, basePath, binPath, parsedGitProtocol) // Validate the furyctl.yaml file. logrus.Info("Validating configuration file...") @@ -188,7 +190,14 @@ func NewKubeconfigCmd() *cobra.Command { return fmt.Errorf("error while getting the kubeconfig, please check that the cluster is up and running and is reachable: %w", err) } - logrus.Infof("Kubeconfig successfully retrieved, you can find it at: %s", path.Join(outDir, "kubeconfig")) + if err := iox.CopyFile(path.Join(outDir, "kubeconfig"), path.Join(currentDir, "kubeconfig")); err != nil { + cmdEvent.AddErrorMessage(err) + tracker.Track(cmdEvent) + + return fmt.Errorf("error while copying the kubeconfig: %w", err) + } + + logrus.Infof("Kubeconfig successfully retrieved, you can find it at: %s", path.Join(currentDir, "kubeconfig")) cmdEvent.AddSuccessMessage("kubeconfig successfully retrieved") tracker.Track(cmdEvent)