fixed commend and added cancellation of first result

Signed-off-by: Suleiman Dibirov <idsulik@gmail.com>
pull/13112/head
Suleiman Dibirov 1 year ago
parent 38d8c98f7b
commit fc628c7148

@ -16,6 +16,7 @@ limitations under the License.
package downloader package downloader
import ( import (
"context"
"fmt" "fmt"
"io" "io"
"net/url" "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 // Charts are not required to be included in an index before they are valid. So
// be mindful of this case. // be mindful of this case.
// //
// The same URL can technically exist in two or more repositories. This algorithm // The same URL can technically exist in multiple repositories.
// will return the first one it finds. Order is determined by the order of repositories // This algorithm will return one of them based on concurrent processing,
// in the repositories.yaml file. // without regard to the order specified in the repositories.yaml file.
func (c *ChartDownloader) scanReposForURL(u string, rf *repo.File) (*repo.Entry, error) { func (c *ChartDownloader) scanReposForURL(u string, rf *repo.File) (*repo.Entry, error) {
var ( var (
g errgroup.Group g errgroup.Group
result *repo.Entry result *repo.Entry
once sync.Once once sync.Once
) )
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
scanRepo := func(rc *repo.Entry) error { scanRepo := func(rc *repo.Entry) error {
r, err := repo.NewChartRepository(rc, c.Getters) r, err := repo.NewChartRepository(rc, c.Getters)
if err != nil { if err != nil {
cancel()
return err return err
} }
idxFile := filepath.Join(c.RepositoryCache, helmpath.CacheIndexFile(r.Config.Name)) idxFile := filepath.Join(c.RepositoryCache, helmpath.CacheIndexFile(r.Config.Name))
i, err := repo.LoadIndexFile(idxFile) i, err := repo.LoadIndexFile(idxFile)
if err != nil { if err != nil {
cancel()
return errors.Wrap(err, "no cached repo found. (try 'helm repo update')") return errors.Wrap(err, "no cached repo found. (try 'helm repo update')")
} }
for _, entry := range i.Entries { for _, entry := range i.Entries {
for _, ver := range entry { for _, ver := range entry {
for _, dl := range ver.URLs { for _, dl := range ver.URLs {
select {
case <-ctx.Done():
return nil
default:
}
if urlutil.Equal(u, dl) { if urlutil.Equal(u, dl) {
once.Do(func() { once.Do(
result = rc func() {
}) result = rc
cancel()
},
)
return nil return nil
} }
} }

Loading…
Cancel
Save