Skip to content

Commit

Permalink
return the right path for deployment home (#761)
Browse files Browse the repository at this point in the history
  • Loading branch information
rberrelleza committed Mar 12, 2020
1 parent c857737 commit 07d4638
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 22 deletions.
4 changes: 2 additions & 2 deletions go.mod
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion pkg/analytics/analytics.go
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/build/image.go
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/doctor/run.go
Expand Up @@ -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))
Expand Down
10 changes: 5 additions & 5 deletions pkg/config/config.go
Expand Up @@ -47,22 +47,22 @@ 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)

if err := os.MkdirAll(d, 0700); err != nil {
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)
Expand Down
34 changes: 33 additions & 1 deletion pkg/config/config_test.go
Expand Up @@ -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")
Expand All @@ -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)
}
}
2 changes: 1 addition & 1 deletion pkg/log/log.go
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/okteto/auth.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -354,5 +354,5 @@ func save(t *Token) error {
}

func getTokenPath() string {
return filepath.Join(config.GetHome(), tokenFile)
return filepath.Join(config.GetOktetoHome(), tokenFile)
}
6 changes: 3 additions & 3 deletions pkg/syncthing/syncthing.go
Expand Up @@ -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
}

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 07d4638

Please sign in to comment.