Working oci code without providing versions

Signed-off-by: Andrew Block <andy.block@gmail.com>
pull/10527/head
Andrew Block 3 years ago committed by Scott Rigby
parent 0fae7f5008
commit df98e18eb7
No known key found for this signature in database
GPG Key ID: C7C6FBB5B91C1155

@ -567,20 +567,21 @@ func (c *Client) Tags(ref string) ([]string, error) {
Client: c.registryAuthorizer,
}
registrtyTags, err := registry.Tags(ctx(c.out, c.debug), &repository)
registryTags, err := registry.Tags(ctx(c.out, c.debug), &repository)
if err != nil {
return nil, err
}
var tagVersions []*semver.Version
for _, tag := range registrtyTags {
for _, tag := range registryTags {
tagVersion, err := semver.StrictNewVersion(tag)
if err != nil {
if err == nil {
tagVersions = append(tagVersions, tagVersion)
}
}
sort.Sort(semver.Collection(tagVersions))
// Sort the collection
sort.Sort(sort.Reverse(semver.Collection(tagVersions)))
tags := make([]string, len(tagVersions))

@ -36,6 +36,16 @@ func IsOCI(url string) bool {
return strings.HasPrefix(url, fmt.Sprintf("%s://", OCIScheme))
}
// ContainsTag determines whether a tag is found in a provided list of tags
func ContainsTag(tags []string, tag string) bool {
for _, t := range tags {
if tag == t {
return true
}
}
return false
}
// extractChartMeta is used to extract a chart metadata from a byte array
func extractChartMeta(chartData []byte) (*chart.Metadata, error) {
ch, err := loader.LoadArchive(bytes.NewReader(chartData))

@ -144,10 +144,10 @@ func (r *Resolver) Resolve(reqs []*chart.Dependency, repoNames map[string]string
"repository %s is an OCI registry", d.Repository)
}
// Retrive list of tags for repository
// Retrieve list of tags for repository
tags, err := r.registryClient.Tags(d.Repository)
if err != nil {
return nil, errors.Wrapf(err, "could not retrieve list of tags for repository", d.Repository)
return nil, errors.Wrapf(err, "could not retrieve list of tags for repository %s", d.Repository)
}
vs = make(repo.ChartVersions, len(tags))

@ -695,10 +695,9 @@ func (c *ChartPathOptions) LocateChart(name string, settings *cli.EnvSettings) (
}
if registry.IsOCI(name) {
if version == "" {
return "", errors.New("version is explicitly required for OCI registries")
if version != "" {
dl.Options = append(dl.Options, getter.WithTagName(version))
}
dl.Options = append(dl.Options, getter.WithTagName(version))
}
if c.Verify {

@ -20,6 +20,8 @@ import (
"fmt"
"strings"
"github.com/pkg/errors"
"helm.sh/helm/v3/internal/experimental/registry"
)
@ -50,10 +52,29 @@ func (g *OCIGetter) get(href string) (*bytes.Buffer, error) {
registry.PullOptWithProv(true))
}
if version := g.opts.version; version != "" {
ref = fmt.Sprintf("%s:%s", ref, version)
// Retrieve list of repository tags
tags, err := client.Tags(ref)
if err != nil {
return nil, err
}
//Determine if version provided. If not
providedVersion := g.opts.version
if g.opts.version == "" {
if len(tags) > 0 {
providedVersion = tags[0]
} else {
return nil, errors.Errorf("Unable to locate any tags in provided repository: %s", ref)
}
} else {
if !registry.ContainsTag(tags, providedVersion) {
return nil, errors.Errorf("Could not located provided version %s in repository %s", providedVersion, ref)
}
}
ref = fmt.Sprintf("%s:%s", ref, providedVersion)
result, err := client.Pull(ref, pullOpts...)
if err != nil {
return nil, err

Loading…
Cancel
Save