Move OCI tag semver range logic from OCIGetter to ChartDownloader

Signed-off-by: Scott Rigby <scott@r6by.com>
pull/10527/head
Scott Rigby 4 years ago
parent c7b2a9d487
commit 4d50526a2b
No known key found for this signature in database
GPG Key ID: C7C6FBB5B91C1155

@ -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 {

@ -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

@ -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

Loading…
Cancel
Save