From cc15de0232f6fe3119ae05e942f1614e527749f9 Mon Sep 17 00:00:00 2001 From: MichaelMorris Date: Tue, 18 Feb 2025 12:32:44 +0000 Subject: [PATCH] Updated for review comments Signed-off-by: MichaelMorris --- internal/resolver/resolver.go | 13 +++++++------ pkg/downloader/manager.go | 13 ++++++++----- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/internal/resolver/resolver.go b/internal/resolver/resolver.go index 554d645b0..5d4d75f89 100644 --- a/internal/resolver/resolver.go +++ b/internal/resolver/resolver.go @@ -52,13 +52,14 @@ func New(chartpath, cachepath string, registryClient *registry.Client) *Resolver } } -// Resolve resolves dependencies and returns a lock file with the resolution. +// Resolve resolves dependencies and returns a lock file with the resolution and a map containaing the chart URLs for the dependencies. +// The key to the map is generated by concatenating the repo URL, name and version for the dependency func (r *Resolver) Resolve(reqs []*chart.Dependency, repoNames map[string]string) (*chart.Lock, map[string]string, error) { // Now we clone the dependencies, locking as we go. locked := make([]*chart.Dependency, len(reqs)) missing := []string{} - loadedIndexFiles := make(map[string]*repo.IndexFile) + chartRepoIndexURLs := make(map[string]*repo.IndexFile) urls := make(map[string]string) for i, d := range reqs { constraint, err := semver.NewConstraint(d.Version) @@ -125,16 +126,16 @@ func (r *Resolver) Resolve(reqs []*chart.Dependency, repoNames map[string]string var ok bool found := true if !registry.IsOCI(d.Repository) { - filepath := filepath.Join(r.cachepath, helmpath.CacheIndexFile(repoName)) + repoFilepath := filepath.Join(r.cachepath, helmpath.CacheIndexFile(repoName)) var repoIndex *repo.IndexFile // Store previously loaded index files in a map. If repositories share the // same index file there is no need to reload the same file again. This // improves performance. - if indexFile, loaded := loadedIndexFiles[filepath]; !loaded { + if indexFile, loaded := chartRepoIndexURLs[repoFilepath]; !loaded { var err error - repoIndex, err = repo.LoadIndexFile(filepath) - loadedIndexFiles[filepath] = repoIndex + repoIndex, err = repo.LoadIndexFile(repoFilepath) + chartRepoIndexURLs[repoFilepath] = repoIndex if err != nil { return nil, nil, fmt.Errorf("no cached repository for %s found. (try 'helm repo update'): %w", repoName, err) } diff --git a/pkg/downloader/manager.go b/pkg/downloader/manager.go index 38a305be3..68b6c5f6e 100644 --- a/pkg/downloader/manager.go +++ b/pkg/downloader/manager.go @@ -229,7 +229,8 @@ func (m *Manager) loadChartDir() (*chart.Chart, error) { // resolve takes a list of dependencies and translates them into an exact version to download. // -// This returns a lock file, which has all of the dependencies normalized to a specific version. +// This returns a lock file, which has all of the dependencies normalized to a specific version +// and a map containaing the URLs for the dependencies. The key to the map is generated by concatenating the repo URL, name and version for the dependency. func (m *Manager) resolve(req []*chart.Dependency, repoNames map[string]string) (*chart.Lock, map[string]string, error) { res := resolver.New(m.ChartPath, m.RepositoryCache, m.RegistryClient) return res.Resolve(req, repoNames) @@ -729,8 +730,10 @@ func (m *Manager) parallelRepoUpdate(repos []*repo.Entry) error { // // repoURL is the repository to search // +// resolvedChartUrls is a map of already resolved chart URLs keyed by a concatenation of the the repo URL, chart name and version. The URL shall be read from this map if present, rather than downloading and reading the index file +// // If it finds a URL that is "relative", it will prepend the repoURL. -func (m *Manager) findChartURL(name, version, repoURL string, repos map[string]*repo.ChartRepository, urls map[string]string) (url, username, password string, insecureskiptlsverify, passcredentialsall bool, caFile, certFile, keyFile string, err error) { +func (m *Manager) findChartURL(name, version, repoURL string, repos map[string]*repo.ChartRepository, resolvedChartUrls map[string]string) (url, username, password string, insecureskiptlsverify, passcredentialsall bool, caFile, certFile, keyFile string, err error) { if registry.IsOCI(repoURL) { return fmt.Sprintf("%s/%s:%s", repoURL, name, version), "", "", false, false, "", "", "", nil } @@ -770,10 +773,10 @@ func (m *Manager) findChartURL(name, version, repoURL string, repos map[string]* } urlsKey := repoURL + name + version - if _, ok := urls[urlsKey]; ok { - url, err = repo.ResolveReferenceURL(repoURL, urls[urlsKey]) + if chartURL, ok := resolvedChartUrls[urlsKey]; ok { + url, err = repo.ResolveReferenceURL(repoURL, chartURL) } else { - url, err = repo.FindChartInRepoURL(repoURL, name, m.Getters, repo.WithChartVersion(version), repo.WithClientTLS(certFile, keyFile, caFile)) + url, err = repo.FindChartInRepoURL(repoURL, name, m.Getters, repo.WithChartVersion(version), repo.WithClientTLS(certFile, keyFile, caFile)) } if err == nil {