diff --git a/cmd/helm/init.go b/cmd/helm/init.go index 21381a0f6..2b1b9ddf6 100644 --- a/cmd/helm/init.go +++ b/cmd/helm/init.go @@ -23,6 +23,7 @@ import ( "fmt" "io" "os" + "path/filepath" "github.com/spf13/cobra" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -337,11 +338,11 @@ func ensureDefaultRepos(home helmpath.Home, out io.Writer, skipRefresh bool) err if fi, err := os.Stat(repoFile); err != nil { fmt.Fprintf(out, "Creating %s \n", repoFile) f := repo.NewRepoFile() - sr, err := initStableRepo(home.CacheIndex(stableRepository), out, skipRefresh) + sr, err := initStableRepo(home.RelativeIndex(stableRepository), out, skipRefresh, home) if err != nil { return err } - lr, err := initLocalRepo(home.LocalRepository(localRepositoryIndexFile), home.CacheIndex("local"), out) + lr, err := initLocalRepo(home.LocalRepository(localRepositoryIndexFile), home.RelativeIndex("local"), out, home) if err != nil { return err } @@ -356,7 +357,7 @@ func ensureDefaultRepos(home helmpath.Home, out io.Writer, skipRefresh bool) err return nil } -func initStableRepo(cacheFile string, out io.Writer, skipRefresh bool) (*repo.Entry, error) { +func initStableRepo(cacheFile string, out io.Writer, skipRefresh bool, home helmpath.Home) (*repo.Entry, error) { fmt.Fprintf(out, "Adding %s repo with URL: %s \n", stableRepository, stableRepositoryURL) c := repo.Entry{ Name: stableRepository, @@ -372,16 +373,14 @@ func initStableRepo(cacheFile string, out io.Writer, skipRefresh bool) (*repo.En return &c, nil } - // In this case, the cacheFile is always absolute. So passing empty string - // is safe. - if err := r.DownloadIndexFile(""); err != nil { + if err := r.DownloadIndexFile(home.Cache()); err != nil { return nil, fmt.Errorf("Looks like %q is not a valid chart repository or cannot be reached: %s", stableRepositoryURL, err.Error()) } return &c, nil } -func initLocalRepo(indexFile, cacheFile string, out io.Writer) (*repo.Entry, error) { +func initLocalRepo(indexFile, cacheFile string, out io.Writer, home helmpath.Home) (*repo.Entry, error) { if fi, err := os.Stat(indexFile); err != nil { fmt.Fprintf(out, "Adding %s repo with URL: %s \n", localRepository, localRepositoryURL) i := repo.NewIndexFile() @@ -390,7 +389,12 @@ func initLocalRepo(indexFile, cacheFile string, out io.Writer) (*repo.Entry, err } //TODO: take this out and replace with helm update functionality - os.Symlink(indexFile, cacheFile) + fp, err := filepath.Rel(filepath.Join(home.Cache(), cacheFile), indexFile) + if err != nil { + return nil, err + } + pth := home.Path(fp) + os.Symlink(pth, filepath.Join(home.Cache(), cacheFile)) } else if fi.IsDir() { return nil, fmt.Errorf("%s must be a file, not a directory", indexFile) } diff --git a/cmd/helm/repo_add.go b/cmd/helm/repo_add.go index b172d016c..7fb20d02d 100644 --- a/cmd/helm/repo_add.go +++ b/cmd/helm/repo_add.go @@ -86,7 +86,7 @@ func addRepository(name, url string, home helmpath.Home, certFile, keyFile, caFi return fmt.Errorf("repository name (%s) already exists, please specify a different name", name) } - cif := home.CacheIndex(name) + cif := home.RelativeIndex(name) c := repo.Entry{ Name: name, Cache: cif, diff --git a/pkg/helm/helmpath/helmhome.go b/pkg/helm/helmpath/helmhome.go index b5ec4909e..3c35c3b69 100644 --- a/pkg/helm/helmpath/helmhome.go +++ b/pkg/helm/helmpath/helmhome.go @@ -61,6 +61,12 @@ func (h Home) CacheIndex(name string) string { return h.Path("repository", "cache", target) } +// RelativeIndex returns the relative path to an index for the given named repository. +func (h Home) RelativeIndex(name string) string { + target := fmt.Sprintf("%s-index.yaml", name) + return filepath.Join(target) +} + // Starters returns the path to the Helm starter packs. func (h Home) Starters() string { return h.Path("starters") diff --git a/pkg/helm/helmpath/helmhome_unix_test.go b/pkg/helm/helmpath/helmhome_unix_test.go index 494d0f6b4..634faeef7 100644 --- a/pkg/helm/helmpath/helmhome_unix_test.go +++ b/pkg/helm/helmpath/helmhome_unix_test.go @@ -36,6 +36,7 @@ func TestHelmHome(t *testing.T) { isEq(t, hh.LocalRepository(), "/r/repository/local") isEq(t, hh.Cache(), "/r/repository/cache") isEq(t, hh.CacheIndex("t"), "/r/repository/cache/t-index.yaml") + isEq(t, hh.RelativeIndex("t"), "t-index.yaml") isEq(t, hh.Starters(), "/r/starters") isEq(t, hh.Archive(), "/r/cache/archive") isEq(t, hh.TLSCaCert(), "/r/ca.pem") diff --git a/pkg/helm/helmpath/helmhome_windows_test.go b/pkg/helm/helmpath/helmhome_windows_test.go index e416bfd58..43db9b8f1 100644 --- a/pkg/helm/helmpath/helmhome_windows_test.go +++ b/pkg/helm/helmpath/helmhome_windows_test.go @@ -33,6 +33,7 @@ func TestHelmHome(t *testing.T) { isEq(t, hh.LocalRepository(), "r:\\repository\\local") isEq(t, hh.Cache(), "r:\\repository\\cache") isEq(t, hh.CacheIndex("t"), "r:\\repository\\cache\\t-index.yaml") + isEq(t, hh.RelativeIndex("t"), "t-index.yaml") isEq(t, hh.Starters(), "r:\\starters") isEq(t, hh.Archive(), "r:\\cache\\archive") isEq(t, hh.TLSCaCert(), "r:\\ca.pem")