diff --git a/pkg/repo/chartrepo.go b/pkg/repo/chartrepo.go index 970e96da2..eaf750551 100644 --- a/pkg/repo/chartrepo.go +++ b/pkg/repo/chartrepo.go @@ -48,6 +48,7 @@ type Entry struct { CAFile string `json:"caFile"` InsecureSkipTLSverify bool `json:"insecure_skip_tls_verify"` PassCredentialsAll bool `json:"pass_credentials_all"` + CachePath string `json:"cache_path"` } // ChartRepository represents a chart repository @@ -71,11 +72,16 @@ func NewChartRepository(cfg *Entry, getters getter.Providers) (*ChartRepository, return nil, errors.Errorf("could not find protocol handler for: %s", u.Scheme) } + cachePath := helmpath.CachePath("repository") + if cfg.CachePath != "" { + cachePath = cfg.CachePath + } + return &ChartRepository{ Config: cfg, IndexFile: NewIndexFile(), Client: client, - CachePath: helmpath.CachePath("repository"), + CachePath: cachePath, }, nil } diff --git a/pkg/repo/chartrepo_test.go b/pkg/repo/chartrepo_test.go index 0a658c0c2..12c18785e 100644 --- a/pkg/repo/chartrepo_test.go +++ b/pkg/repo/chartrepo_test.go @@ -73,6 +73,40 @@ func TestLoadChartRepository(t *testing.T) { } } +func TestNewChartRepositoryWithCachePath(t *testing.T) { + srv, err := startLocalServerForTests(nil) + if err != nil { + t.Fatal(err) + } + defer srv.Close() + + cacheDir := t.TempDir() + r, err := NewChartRepository(&Entry{ + Name: testRepository, + URL: srv.URL, + CachePath: cacheDir, + }, getter.All(&cli.EnvSettings{})) + if err != nil { + t.Errorf("Problem creating chart repository from %s: %v", testRepository, err) + } + + if err := r.Load(); err != nil { + t.Errorf("Problem loading chart repository from %s: %v", testRepository, err) + } + + _, err = r.DownloadIndexFile() + if err != nil { + t.Errorf("Problem downloading index file from %s: %v", testRepository, err) + } + + if _, err := os.Stat(filepath.Join(cacheDir, helmpath.CacheIndexFile(r.Config.Name))); err != nil { + t.Errorf("Expected index.yaml to be created in %s, but got an error: %v", cacheDir, err) + } + if _, err := os.Stat(filepath.Join(cacheDir, helmpath.CacheChartsFile(r.Config.Name))); err != nil { + t.Errorf("Expected charts to be created in %s, but got an error: %v", cacheDir, err) + } +} + func TestIndex(t *testing.T) { r, err := NewChartRepository(&Entry{ Name: testRepository,