do not error for remote chart if there's a missing local repo cache

Signed-off-by: Mike Seese <seesemichaelj@gmail.com>
pull/11963/head
Mike Seese 1 year ago
parent 518c69281f
commit 2532fc89f3
No known key found for this signature in database
GPG Key ID: A8EA84CD6581B1CF

@ -54,7 +54,7 @@ const (
)
// ErrNoOwnerRepo indicates that a given chart URL can't be found in any repos.
var ErrNoOwnerRepo = errors.New("could not find a repo containing the given URL")
var ErrNoOwnerRepo = errors.New("could not find a repo containing the given URL (try 'helm repo update')")
// ChartDownloader handles downloading a chart.
//
@ -380,7 +380,8 @@ func (c *ChartDownloader) scanReposForURL(u string, rf *repo.File) (*repo.Entry,
idxFile := filepath.Join(c.RepositoryCache, helmpath.CacheIndexFile(r.Config.Name))
i, err := repo.LoadIndexFile(idxFile)
if err != nil {
return nil, errors.Wrap(err, "no cached repo found. (try 'helm repo update')")
// No cache for this repository; let's keep looking rather than erroring
continue
}
for _, entry := range i.Entries {

@ -28,8 +28,9 @@ import (
)
const (
repoConfig = "testdata/repositories.yaml"
repoCache = "testdata/repository"
repoConfig = "testdata/repositories.yaml"
repoCache = "testdata/repository"
repoCacheEmpty = "testdata/repository-empty"
)
func TestResolveChartRef(t *testing.T) {
@ -344,3 +345,30 @@ func TestScanReposForURL(t *testing.T) {
t.Fatalf("expected ErrNoOwnerRepo, got %v", err)
}
}
// In an scenario where a full URL is provided, chart_downloader will swallow the
// ErrNoOwnerRepo error and return an HTTP client to download the chart. This specific
// test shows that the chart will get downloaded in that scenario if the cache is empty
// (hence `repoCacheEmpty`).
func TestScanReposForURLWithEmptyCache(t *testing.T) {
c := ChartDownloader{
Out: os.Stderr,
Verify: VerifyLater,
RepositoryConfig: repoConfig,
RepositoryCache: repoCacheEmpty,
Getters: getter.All(&cli.EnvSettings{
RepositoryConfig: repoConfig,
RepositoryCache: repoCacheEmpty,
}),
}
u := "http://example.com/alpine-0.2.0.tgz"
rf, err := repo.LoadFile(repoConfig)
if err != nil {
t.Fatal(err)
}
if _, err = c.scanReposForURL(u, rf); err != ErrNoOwnerRepo {
t.Fatalf("expected ErrNoOwnerRepo, got %v", err)
}
}

Loading…
Cancel
Save