From 07d4638bd11f1da0da50d4a49cd5066345ccb221 Mon Sep 17 00:00:00 2001 From: Ramiro Berrelleza Date: Thu, 12 Mar 2020 12:40:17 -0700 Subject: [PATCH] return the right path for deployment home (#761) --- go.mod | 4 ++-- go.sum | 8 ++++---- pkg/analytics/analytics.go | 2 +- pkg/cmd/build/image.go | 2 +- pkg/cmd/doctor/run.go | 4 ++-- pkg/config/config.go | 10 +++++----- pkg/config/config_test.go | 34 +++++++++++++++++++++++++++++++++- pkg/log/log.go | 2 +- pkg/okteto/auth.go | 4 ++-- pkg/syncthing/syncthing.go | 6 +++--- 10 files changed, 54 insertions(+), 22 deletions(-) diff --git a/go.mod b/go.mod index bba7982b93a8..3a8a52e49a4d 100644 --- a/go.mod +++ b/go.mod @@ -52,13 +52,13 @@ require ( github.com/spf13/cobra v0.0.5 github.com/src-d/enry/v2 v2.1.0 github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect - go.undefinedlabs.com/scopeagent v0.0.0-20200123164547-e307ed3a9216 + go.undefinedlabs.com/scopeagent v0.1.12 golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586 golang.org/x/lint v0.0.0-20190409202823-959b441ac422 // indirect golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e google.golang.org/genproto v0.0.0-20191009194640-548a555dbc03 // indirect - google.golang.org/grpc v1.26.0 + google.golang.org/grpc v1.27.1 gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20180810215634-df19058c872c // indirect gopkg.in/natefinch/lumberjack.v2 v2.0.0 gopkg.in/yaml.v2 v2.2.4 diff --git a/go.sum b/go.sum index 9a77e1842faf..e8d615accc19 100644 --- a/go.sum +++ b/go.sum @@ -498,8 +498,8 @@ go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= -go.undefinedlabs.com/scopeagent v0.0.0-20200123164547-e307ed3a9216 h1:TPeghBQcHGAXiEjFaz+iBGlbz7wDKmE0GGTu9uf08ws= -go.undefinedlabs.com/scopeagent v0.0.0-20200123164547-e307ed3a9216/go.mod h1:4QeO91RRdKn2G+KyTqou6dZTWkUS+L0tnJIk0cbrQjM= +go.undefinedlabs.com/scopeagent v0.1.12 h1:EKOFhKGIWlEaNOziVMU3Fs5vMo9BdEMLUOx6EXvOuUQ= +go.undefinedlabs.com/scopeagent v0.1.12/go.mod h1:phe27toysIN8sk8tq6T99zi3WLVVwSASUAQb0ENVm9E= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= @@ -630,8 +630,8 @@ google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZi google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.26.0 h1:2dTRdpdFEEhJYQD8EMLB61nnrzSCTbG38PhqdhvOltg= -google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.27.1 h1:zvIju4sqAGvwKspUQOhwnpcqSbzi7/H6QomNNjTL4sk= +google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20180810215634-df19058c872c h1:vTxShRUnK60yd8DZU+f95p1zSLj814+5CuEh7NjF2/Y= diff --git a/pkg/analytics/analytics.go b/pkg/analytics/analytics.go index 625fe1bb0835..9253a208991f 100644 --- a/pkg/analytics/analytics.go +++ b/pkg/analytics/analytics.go @@ -241,7 +241,7 @@ func track(event string, success bool, props map[string]interface{}) { } func getFlagPath() string { - return filepath.Join(config.GetHome(), ".noanalytics") + return filepath.Join(config.GetOktetoHome(), ".noanalytics") } // Disable disables analytics diff --git a/pkg/cmd/build/image.go b/pkg/cmd/build/image.go index 2a3ae8c709d9..3268cb15d9ff 100644 --- a/pkg/cmd/build/image.go +++ b/pkg/cmd/build/image.go @@ -70,7 +70,7 @@ func getDockerfileWithCacheHandler(filename string) (string, error) { scanner := bufio.NewScanner(file) - dockerfileTmpFolder := filepath.Join(config.GetHome(), ".dockerfile") + dockerfileTmpFolder := filepath.Join(config.GetOktetoHome(), ".dockerfile") if err := os.MkdirAll(dockerfileTmpFolder, 0700); err != nil { return "", fmt.Errorf("failed to create %s: %s", dockerfileTmpFolder, err) } diff --git a/pkg/cmd/doctor/run.go b/pkg/cmd/doctor/run.go index fe133f17f050..03e29fc47f1a 100644 --- a/pkg/cmd/doctor/run.go +++ b/pkg/cmd/doctor/run.go @@ -60,8 +60,8 @@ func Run(ctx context.Context, dev *model.Dev, c *kubernetes.Clientset) (string, now := time.Now() archiveName := fmt.Sprintf("okteto-doctor-%s.zip", now.Format("20060102150405")) files := []string{summaryFilename} - if model.FileExists(filepath.Join(config.GetHome(), "okteto.log")) { - files = append(files, filepath.Join(config.GetHome(), "okteto.log")) + if model.FileExists(filepath.Join(config.GetOktetoHome(), "okteto.log")) { + files = append(files, filepath.Join(config.GetOktetoHome(), "okteto.log")) } if model.FileExists(config.GetSyncthingLogFile(dev.Namespace, dev.Name)) { files = append(files, config.GetSyncthingLogFile(dev.Namespace, dev.Name)) diff --git a/pkg/config/config.go b/pkg/config/config.go index 3be6591859d2..3c6ec7dcbfbe 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -47,8 +47,8 @@ func GetBinaryFullPath() string { return os.Args[0] } -// GetHome returns the path of the folder -func GetHome() string { +// GetOktetoHome returns the path of the okteto folder +func GetOktetoHome() string { home := GetUserHomeDir() d := filepath.Join(home, oktetoFolderName) @@ -56,13 +56,13 @@ func GetHome() string { log.Fatalf("failed to create %s: %s", d, err) } - return home + return d } // GetDeploymentHome returns the path of the folder func GetDeploymentHome(namespace, name string) string { - home := GetUserHomeDir() - d := filepath.Join(home, oktetoFolderName, namespace, name) + okHome := GetOktetoHome() + d := filepath.Join(okHome, namespace, name) if err := os.MkdirAll(d, 0700); err != nil { log.Fatalf("failed to create %s: %s", d, err) diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 6ab3a71d02a9..921a5890078e 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -16,11 +16,11 @@ package config import ( "io/ioutil" "os" + "path/filepath" "testing" ) func TestGetUserHomeDir(t *testing.T) { - home := GetUserHomeDir() if len(home) == 0 { t.Fatal("got an empty home value") @@ -39,3 +39,35 @@ func TestGetUserHomeDir(t *testing.T) { } } + +func TestGetOktetoHome(t *testing.T) { + dir, err := ioutil.TempDir("", "") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(dir) + + os.Setenv("OKTETO_HOME", dir) + + got := GetOktetoHome() + expected := filepath.Join(dir, ".okteto") + if got != expected { + t.Errorf("expected %s, got %s", expected, got) + } +} + +func TestGetDeploymentHome(t *testing.T) { + dir, err := ioutil.TempDir("", "") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(dir) + + os.Setenv("OKTETO_HOME", dir) + + got := GetDeploymentHome("ns", "dp") + expected := filepath.Join(dir, ".okteto", "ns", "dp") + if got != expected { + t.Errorf("expected %s, got %s", expected, got) + } +} diff --git a/pkg/log/log.go b/pkg/log/log.go index 2e20283a88d3..db9d5753d841 100644 --- a/pkg/log/log.go +++ b/pkg/log/log.go @@ -69,7 +69,7 @@ func Init(level logrus.Level) { FullTimestamp: true, }) - logPath := filepath.Join(config.GetHome(), "okteto.log") + logPath := filepath.Join(config.GetOktetoHome(), "okteto.log") rolling := getRollingLog(logPath) fileLogger.SetOutput(rolling) fileLogger.SetLevel(logrus.DebugLevel) diff --git a/pkg/okteto/auth.go b/pkg/okteto/auth.go index 0475d65bf682..4ab19c9088e4 100644 --- a/pkg/okteto/auth.go +++ b/pkg/okteto/auth.go @@ -287,7 +287,7 @@ func GetBuildKit() (string, error) { // GetCertificatePath returns the path to the certificate of the okteto buildkit func GetCertificatePath() string { - return filepath.Join(config.GetHome(), ".ca.crt") + return filepath.Join(config.GetOktetoHome(), ".ca.crt") } func saveToken(id, token, url, registry, buildkit string) error { @@ -354,5 +354,5 @@ func save(t *Token) error { } func getTokenPath() string { - return filepath.Join(config.GetHome(), tokenFile) + return filepath.Join(config.GetOktetoHome(), tokenFile) } diff --git a/pkg/syncthing/syncthing.go b/pkg/syncthing/syncthing.go index 27c4c7d5a8ab..281dcfd29906 100644 --- a/pkg/syncthing/syncthing.go +++ b/pkg/syncthing/syncthing.go @@ -603,8 +603,8 @@ func RemoveFolder(dev *model.Dev) error { return nil } - if _, err := filepath.Rel(config.GetHome(), s.Home); err != nil || config.GetHome() == s.Home { - log.Errorf("%s is not inside %s, ignoring", s.Home, config.GetHome()) + if _, err := filepath.Rel(config.GetOktetoHome(), s.Home); err != nil || config.GetOktetoHome() == s.Home { + log.Errorf("%s is not inside %s, ignoring", s.Home, config.GetOktetoHome()) return nil } @@ -661,7 +661,7 @@ func getPID(pidPath string) (int, error) { } func getInstallPath() string { - return filepath.Join(config.GetHome(), getBinaryName()) + return filepath.Join(config.GetOktetoHome(), getBinaryName()) } func getBinaryName() string {