Limits need to call tag API when explicit version specified

Signed-off-by: Andrew Block <andy.block@gmail.com>
pull/10578/head
Andrew Block 3 years ago
parent 3c498fa961
commit 0677a156bc
No known key found for this signature in database
GPG Key ID: 02DFE631AEF35EBC

@ -23,6 +23,7 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/Masterminds/semver/v3"
"github.com/pkg/errors" "github.com/pkg/errors"
"helm.sh/helm/v3/internal/fileutil" "helm.sh/helm/v3/internal/fileutil"
@ -141,22 +142,31 @@ func (c *ChartDownloader) DownloadTo(ref, version, dest string) (string, *proven
} }
func (c *ChartDownloader) getOciURI(ref, version string, u *url.URL) (*url.URL, error) { func (c *ChartDownloader) getOciURI(ref, version string, u *url.URL) (*url.URL, error) {
// Retrieve list of repository tags var tag string
tags, err := c.RegistryClient.Tags(strings.TrimPrefix(ref, fmt.Sprintf("%s://", registry.OCIScheme))) var err error
if err != nil {
return nil, err // Evaluate whether an explicit version has been provided. Otherwise, determine version to use
} _, errSemVer := semver.NewVersion(version)
if len(tags) == 0 { if errSemVer == nil {
return nil, errors.Errorf("Unable to locate any tags in provided repository: %s", ref) tag = version
} } else {
// Retrieve list of repository tags
tags, err := c.RegistryClient.Tags(strings.TrimPrefix(ref, fmt.Sprintf("%s://", registry.OCIScheme)))
if err != nil {
return nil, err
}
if len(tags) == 0 {
return nil, errors.Errorf("Unable to locate any tags in provided repository: %s", ref)
}
// Determine if version provided // Determine if version provided
// If empty, try to get the highest available tag // If empty, try to get the highest available tag
// If exact version, try to find it // If exact version, try to find it
// If semver constraint string, try to find a match // If semver constraint string, try to find a match
tag, err := registry.GetTagMatchingVersionOrConstraint(tags, version) tag, err = registry.GetTagMatchingVersionOrConstraint(tags, version)
if err != nil { if err != nil {
return nil, err return nil, err
}
} }
u.Path = fmt.Sprintf("%s:%s", u.Path, tag) u.Path = fmt.Sprintf("%s:%s", u.Path, tag)

Loading…
Cancel
Save