diff --git a/pkg/action/pull.go b/pkg/action/pull.go index f09da82d0..6de08a6da 100644 --- a/pkg/action/pull.go +++ b/pkg/action/pull.go @@ -94,11 +94,6 @@ func (p *Pull) Run(chartRef string) (string, error) { if registry.IsOCI(chartRef) { c.Options = append(c.Options, getter.WithRegistryClient(p.cfg.RegistryClient)) - - if p.Version != "" { - c.Options = append(c.Options, - getter.WithTagName(p.Version)) - } } if p.Verify { diff --git a/pkg/downloader/chart_downloader.go b/pkg/downloader/chart_downloader.go index 93afb1461..cd5a5d83d 100644 --- a/pkg/downloader/chart_downloader.go +++ b/pkg/downloader/chart_downloader.go @@ -139,12 +139,41 @@ func (c *ChartDownloader) DownloadTo(ref, version, dest string) (string, *proven return destfile, ver, nil } +func (c *ChartDownloader) getOciUri(ref, version string, u *url.URL) (*url.URL, error) { + // Retrieve list of repository tags + tags, err := c.RegistryClient.Tags(ref) + 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 + // If empty, try to get the highest available tag + // If exact version, try to find it + // If semver constraint string, try to find a match + providedVersion := version + + tag, err := registry.GetTagMatchingVersionOrConstraint(tags, providedVersion) + if err != nil { + return nil, err + } + + // TODO Find a net/url equivalent of this + //ref = fmt.Sprintf("%s:%s", ref, tag) + u.Path = fmt.Sprintf("%s:%s", u.Path, tag) + + return u, err +} + // ResolveChartVersion resolves a chart reference to a URL. // // It returns the URL and sets the ChartDownloader's Options that can fetch // the URL using the appropriate Getter. // -// A reference may be an HTTP URL, a 'reponame/chartname' reference, or a local path. +// A reference may be an HTTP URL, an oci reference URL, a 'reponame/chartname' +// reference, or a local path. // // A version is a SemVer string (1.2.3-beta.1+f334a6789). // @@ -159,6 +188,10 @@ func (c *ChartDownloader) ResolveChartVersion(ref, version string) (*url.URL, er return nil, errors.Errorf("invalid chart URL format: %s", ref) } + if registry.IsOCI(u.Path) { + return c.getOciUri(ref, version, u) + } + rf, err := loadRepoConfig(c.RepositoryConfig) if err != nil { return u, err diff --git a/pkg/getter/ocigetter.go b/pkg/getter/ocigetter.go index 0de5987db..dbf382102 100644 --- a/pkg/getter/ocigetter.go +++ b/pkg/getter/ocigetter.go @@ -20,8 +20,6 @@ import ( "fmt" "strings" - "github.com/pkg/errors" - "helm.sh/helm/v3/internal/experimental/registry" ) @@ -52,28 +50,6 @@ func (g *OCIGetter) get(href string) (*bytes.Buffer, error) { registry.PullOptWithProv(true)) } - // Retrieve list of repository tags - tags, err := client.Tags(ref) - 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 - // If empty, try to get the highest available tag - // If exact version, try to find it - // If semver constraint string, try to find a match - providedVersion := g.opts.version - - tag, err := registry.GetTagMatchingVersionOrConstraint(tags, providedVersion) - if err != nil { - return nil, err - } - - ref = fmt.Sprintf("%s:%s", ref, tag) - result, err := client.Pull(ref, pullOpts...) if err != nil { return nil, err