Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix get kubeconfig command #543

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions cmd/get/kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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...")
Expand Down Expand Up @@ -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)
Expand Down