diff --git a/cmd/helm/dependency_build_test.go b/cmd/helm/dependency_build_test.go index 7038e9aa1..361d3ed6c 100644 --- a/cmd/helm/dependency_build_test.go +++ b/cmd/helm/dependency_build_test.go @@ -103,7 +103,7 @@ func TestDependencyBuildCmd(t *testing.T) { t.Fatal(err) } - i, err := repo.LoadIndexFile(cacheIndexFile("test")) + i, err := repo.LoadIndexFile(dbc.helmhome.CacheIndex("test")) if err != nil { t.Fatal(err) } diff --git a/cmd/helm/dependency_update_test.go b/cmd/helm/dependency_update_test.go index becbef9a3..465b2afc1 100644 --- a/cmd/helm/dependency_update_test.go +++ b/cmd/helm/dependency_update_test.go @@ -85,7 +85,7 @@ func TestDependencyUpdateCmd(t *testing.T) { t.Fatal(err) } - i, err := repo.LoadIndexFile(cacheIndexFile("test")) + i, err := repo.LoadIndexFile(duc.helmhome.CacheIndex("test")) if err != nil { t.Fatal(err) } diff --git a/cmd/helm/helm.go b/cmd/helm/helm.go index 46d13c64d..201bc52c6 100644 --- a/cmd/helm/helm.go +++ b/cmd/helm/helm.go @@ -25,6 +25,8 @@ import ( "github.com/spf13/cobra" "google.golang.org/grpc" + + "k8s.io/helm/cmd/helm/helmpath" ) const ( @@ -161,7 +163,9 @@ func checkArgsLength(argsReceived int, requiredArgs ...string) error { // requireInit is a PreRunE implementation for validating that $HELM_HOME is configured. func requireInit(cmd *cobra.Command, args []string) error { - err := requireHome() + // FIXME: requireInit seems to only be called from search. Either it should be called from more + // places or just removed. + err := requireHome(helmpath.Home(homePath())) if err != nil { return fmt.Errorf("%s (try running 'helm init')", err) } diff --git a/cmd/helm/helm_test.go b/cmd/helm/helm_test.go index 43a1c8b64..e3bba8777 100644 --- a/cmd/helm/helm_test.go +++ b/cmd/helm/helm_test.go @@ -255,6 +255,15 @@ func ensureTestHome(home helmpath.Home, t *testing.T) error { repoFile := home.RepositoryFile() if fi, err := os.Stat(repoFile); err != nil { rf := repo.NewRepoFile() + rf.Add(&repo.Entry{ + Name: "charts", + URL: "http://example.com/foo", + Cache: "charts-index.yaml", + }, &repo.Entry{ + Name: "local", + URL: "http://localhost.com:7743/foo", + Cache: "local-index.yaml", + }) if err := rf.WriteFile(repoFile, 0644); err != nil { return err } @@ -276,7 +285,7 @@ func ensureTestHome(home helmpath.Home, t *testing.T) error { } //TODO: take this out and replace with helm update functionality - os.Symlink(localRepoIndexFile, cacheDirectory("local-index.yaml")) + os.Symlink(localRepoIndexFile, home.CacheIndex("local")) } else if fi.IsDir() { return fmt.Errorf("%s must be a file, not a directory", localRepoIndexFile) } diff --git a/cmd/helm/init.go b/cmd/helm/init.go index 1546860c6..3507d90d1 100644 --- a/cmd/helm/init.go +++ b/cmd/helm/init.go @@ -92,8 +92,8 @@ func (i *initCmd) run() error { return nil } -func requireHome() error { - dirs := []string{homePath(), repositoryDirectory(), cacheDirectory(), localRepoDirectory()} +func requireHome(home helmpath.Home) error { + dirs := []string{home.String(), home.Repository(), home.Cache(), home.LocalRepository()} for _, d := range dirs { if fi, err := os.Stat(d); err != nil { return fmt.Errorf("directory %q is not configured", d) @@ -150,7 +150,7 @@ func ensureHome(home helmpath.Home, out io.Writer) error { } } - localRepoIndexFile := localRepoDirectory(localRepoIndexFilePath) + localRepoIndexFile := home.LocalRepository(localRepoIndexFilePath) if fi, err := os.Stat(localRepoIndexFile); err != nil { fmt.Fprintf(out, "Creating %s \n", localRepoIndexFile) i := repo.NewIndexFile() @@ -159,7 +159,7 @@ func ensureHome(home helmpath.Home, out io.Writer) error { } //TODO: take this out and replace with helm update functionality - os.Symlink(localRepoIndexFile, cacheDirectory("local-index.yaml")) + os.Symlink(localRepoIndexFile, home.CacheIndex("local")) } else if fi.IsDir() { return fmt.Errorf("%s must be a file, not a directory", localRepoIndexFile) } diff --git a/cmd/helm/init_test.go b/cmd/helm/init_test.go index 171ef1ac5..bbea3b608 100644 --- a/cmd/helm/init_test.go +++ b/cmd/helm/init_test.go @@ -54,7 +54,7 @@ func TestEnsureHome(t *testing.T) { t.Errorf("%s should not be a directory", fi) } - if fi, err := os.Stat(localRepoDirectory(localRepoIndexFilePath)); err != nil { + if fi, err := os.Stat(hh.LocalRepository(localRepoIndexFilePath)); err != nil { t.Errorf("%s", err) } else if fi.IsDir() { t.Errorf("%s should not be a directory", fi) diff --git a/cmd/helm/install.go b/cmd/helm/install.go index d53dd7bd2..38cb01767 100644 --- a/cmd/helm/install.go +++ b/cmd/helm/install.go @@ -323,7 +323,7 @@ func locateChartPath(name, version string, verify bool, keyring string) (string, return name, fmt.Errorf("path %q not found", name) } - crepo := filepath.Join(repositoryDirectory(), name) + crepo := filepath.Join(helmpath.Home(homePath()).Repository(), name) if _, err := os.Stat(crepo); err == nil { return filepath.Abs(crepo) } diff --git a/cmd/helm/repo_update.go b/cmd/helm/repo_update.go index 1a7685abe..7e04b5e27 100644 --- a/cmd/helm/repo_update.go +++ b/cmd/helm/repo_update.go @@ -37,17 +37,15 @@ future releases. ` type repoUpdateCmd struct { - repoFile string - update func([]*repo.Entry, bool, io.Writer, helmpath.Home) - out io.Writer - home helmpath.Home + update func([]*repo.Entry, bool, io.Writer, helmpath.Home) + out io.Writer + home helmpath.Home } func newRepoUpdateCmd(out io.Writer) *cobra.Command { u := &repoUpdateCmd{ - out: out, - update: updateCharts, - repoFile: repositoriesFile(), + out: out, + update: updateCharts, } cmd := &cobra.Command{ Use: "update", @@ -63,7 +61,7 @@ func newRepoUpdateCmd(out io.Writer) *cobra.Command { } func (u *repoUpdateCmd) run() error { - f, err := repo.LoadRepositoriesFile(u.repoFile) + f, err := repo.LoadRepositoriesFile(u.home.RepositoryFile()) if err != nil { return err } diff --git a/cmd/helm/repo_update_test.go b/cmd/helm/repo_update_test.go index 857fbbf88..5906bd62d 100644 --- a/cmd/helm/repo_update_test.go +++ b/cmd/helm/repo_update_test.go @@ -29,7 +29,6 @@ import ( ) func TestUpdateCmd(t *testing.T) { - thome, err := tempHelmHome(t) if err != nil { t.Fatal(err) @@ -50,14 +49,16 @@ func TestUpdateCmd(t *testing.T) { } } uc := &repoUpdateCmd{ - out: out, - update: updater, - repoFile: "testdata/repositories.yaml", + out: out, + update: updater, + home: helmpath.Home(thome), + } + if err := uc.run(); err != nil { + t.Fatal(err) } - uc.run() if got := out.String(); !strings.Contains(got, "charts") || !strings.Contains(got, "local") { - t.Errorf("Expected 'charts' and 'local' (in any order) got %s", got) + t.Errorf("Expected 'charts' and 'local' (in any order) got %q", got) } } diff --git a/cmd/helm/structure.go b/cmd/helm/structure.go index f1d40040a..bb74c10d1 100644 --- a/cmd/helm/structure.go +++ b/cmd/helm/structure.go @@ -18,40 +18,10 @@ package main import ( "os" - "path/filepath" ) -const ( - repositoryDir string = "repository" - repositoriesFilePath string = "repositories.yaml" - cachePath string = "cache" - localRepoPath string = "local" - localRepoIndexFilePath string = "index.yaml" -) +const localRepoIndexFilePath string = "index.yaml" func homePath() string { return os.ExpandEnv(helmHome) } - -// All other directories go under the $HELM_HOME/repository. -func repositoryDirectory() string { - return homePath() + "/" + repositoryDir -} - -func cacheDirectory(paths ...string) string { - fragments := append([]string{repositoryDirectory(), cachePath}, paths...) - return filepath.Join(fragments...) -} - -func cacheIndexFile(repoName string) string { - return cacheDirectory(repoName + "-index.yaml") -} - -func localRepoDirectory(paths ...string) string { - fragments := append([]string{repositoryDirectory(), localRepoPath}, paths...) - return filepath.Join(fragments...) -} - -func repositoriesFile() string { - return filepath.Join(repositoryDirectory(), repositoriesFilePath) -}