Use cache index file to load Chart Repository

Signed-off-by: Paul Brousseau <object88@gmail.com>
pull/8724/head
Paul Brousseau 5 years ago
parent e2442699fa
commit 95347ba772

@ -83,18 +83,23 @@ func NewChartRepository(cfg *Entry, getters getter.Providers) (*ChartRepository,
//
// It requires the presence of an index.yaml file in the directory.
func (r *ChartRepository) Load() error {
dirInfo, err := os.Stat(r.Config.Name)
cacheIndexFile := r.Config.Name
dirInfo, err := os.Stat(cacheIndexFile)
if err != nil {
return err
cacheIndexFile = r.CachePath
dirInfo, err = os.Stat(cacheIndexFile)
if err != nil {
return err
}
}
if !dirInfo.IsDir() {
return errors.Errorf("%q is not a directory", r.Config.Name)
return errors.Errorf("%q is not a directory", cacheIndexFile)
}
// FIXME: Why are we recursively walking directories?
// FIXME: Why are we not reading the repositories.yaml to figure out
// what repos to use?
filepath.Walk(r.Config.Name, func(path string, f os.FileInfo, err error) error {
filepath.Walk(cacheIndexFile, func(path string, f os.FileInfo, err error) error {
if !f.IsDir() {
if strings.Contains(f.Name(), "-index.yaml") {
i, err := LoadIndexFile(path)

@ -74,6 +74,49 @@ func TestLoadChartRepository(t *testing.T) {
}
}
func TestLoadChartMetadataFromRepositoryConfig(t *testing.T) {
parentDir := os.TempDir()
defer os.RemoveAll(parentDir)
repositoryCacheDir, _ := ioutil.TempDir(parentDir, "*-cache")
repositoryConfigDir, _ := ioutil.TempDir(parentDir, "*-repository")
repositoryConfigFile := filepath.Join(repositoryConfigDir, "repository.yaml")
f := NewFile()
f.Add(&Entry{
Name: "stable",
URL: "https://kubernetes-charts.storage.googleapis.com",
})
err := f.WriteFile(repositoryConfigFile, 0644)
if err != nil {
t.Fatalf("Failed to write repository config '%s':\n\t%s\n", repositoryConfigFile, err.Error())
}
helmSettings := cli.New()
helmSettings.RepositoryCache = repositoryCacheDir
helmSettings.RepositoryConfig = repositoryConfigFile
entry := f.Repositories[0]
cr, _ := NewChartRepository(entry, getter.All(helmSettings))
cr.CachePath = helmSettings.RepositoryCache
indexFilePath, err := cr.DownloadIndexFile()
if err != nil {
t.Fatalf("Failed to download index file:\n\t%s\n", err.Error())
}
cr.ChartPaths = append(cr.ChartPaths, indexFilePath)
err = cr.Load()
if err != nil {
t.Fatalf("Failed to generate index file:\n\t%s\n", err.Error())
}
if len(cr.IndexFile.Entries) == 0 {
t.Errorf("Did not load entries")
}
}
func TestIndex(t *testing.T) {
r, err := NewChartRepository(&Entry{
Name: testRepository,

Loading…
Cancel
Save