From fc628c7148d79eb8fa31f635e59c771e1c5d27b7 Mon Sep 17 00:00:00 2001 From: Suleiman Dibirov Date: Fri, 21 Jun 2024 10:06:43 +0300 Subject: [PATCH] fixed commend and added cancellation of first result Signed-off-by: Suleiman Dibirov --- pkg/downloader/chart_downloader.go | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/pkg/downloader/chart_downloader.go b/pkg/downloader/chart_downloader.go index c4ed08ea9..18384c03b 100644 --- a/pkg/downloader/chart_downloader.go +++ b/pkg/downloader/chart_downloader.go @@ -16,6 +16,7 @@ limitations under the License. package downloader import ( + "context" "fmt" "io" "net/url" @@ -367,35 +368,47 @@ func pickChartRepositoryConfigByName(name string, cfgs []*repo.Entry) (*repo.Ent // Charts are not required to be included in an index before they are valid. So // be mindful of this case. // -// The same URL can technically exist in two or more repositories. This algorithm -// will return the first one it finds. Order is determined by the order of repositories -// in the repositories.yaml file. +// The same URL can technically exist in multiple repositories. +// This algorithm will return one of them based on concurrent processing, +// without regard to the order specified in the repositories.yaml file. func (c *ChartDownloader) scanReposForURL(u string, rf *repo.File) (*repo.Entry, error) { var ( g errgroup.Group result *repo.Entry once sync.Once ) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() scanRepo := func(rc *repo.Entry) error { r, err := repo.NewChartRepository(rc, c.Getters) if err != nil { + cancel() return err } idxFile := filepath.Join(c.RepositoryCache, helmpath.CacheIndexFile(r.Config.Name)) i, err := repo.LoadIndexFile(idxFile) if err != nil { + cancel() return errors.Wrap(err, "no cached repo found. (try 'helm repo update')") } for _, entry := range i.Entries { for _, ver := range entry { for _, dl := range ver.URLs { + select { + case <-ctx.Done(): + return nil + default: + } if urlutil.Equal(u, dl) { - once.Do(func() { - result = rc - }) + once.Do( + func() { + result = rc + cancel() + }, + ) return nil } }