diff --git a/pkg/downloader/chart_downloader.go b/pkg/downloader/chart_downloader.go index f5d1deac9..808cf4cb7 100644 --- a/pkg/downloader/chart_downloader.go +++ b/pkg/downloader/chart_downloader.go @@ -53,7 +53,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. // @@ -348,7 +348,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 { diff --git a/pkg/downloader/chart_downloader_test.go b/pkg/downloader/chart_downloader_test.go index 26dcc58ff..ded2f0fe9 100644 --- a/pkg/downloader/chart_downloader_test.go +++ b/pkg/downloader/chart_downloader_test.go @@ -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) { @@ -357,3 +358,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) + } +} diff --git a/pkg/downloader/testdata/repository-empty/.keep b/pkg/downloader/testdata/repository-empty/.keep new file mode 100644 index 000000000..e69de29bb