Make `ChartRepository`'s cache path customize via the `Entry`

Signed-off-by: Douglas Camata <159076+douglascamata@users.noreply.github.com>
pull/31092/head
Douglas Camata 2 months ago
parent 9ec1679d60
commit 5e024b9d85
No known key found for this signature in database

@ -48,6 +48,7 @@ type Entry struct {
CAFile string `json:"caFile"` CAFile string `json:"caFile"`
InsecureSkipTLSverify bool `json:"insecure_skip_tls_verify"` InsecureSkipTLSverify bool `json:"insecure_skip_tls_verify"`
PassCredentialsAll bool `json:"pass_credentials_all"` PassCredentialsAll bool `json:"pass_credentials_all"`
CachePath string `json:"cache_path"`
} }
// ChartRepository represents a chart repository // 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) 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{ return &ChartRepository{
Config: cfg, Config: cfg,
IndexFile: NewIndexFile(), IndexFile: NewIndexFile(),
Client: client, Client: client,
CachePath: helmpath.CachePath("repository"), CachePath: cachePath,
}, nil }, nil
} }

@ -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) { func TestIndex(t *testing.T) {
r, err := NewChartRepository(&Entry{ r, err := NewChartRepository(&Entry{
Name: testRepository, Name: testRepository,

Loading…
Cancel
Save