Skip to content

Commit

Permalink
Working oci code without providing versions
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Block <andy.block@gmail.com>
  • Loading branch information
sabre1041 authored and scottrigby committed Jan 12, 2022
1 parent 0fae7f5 commit df98e18
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 11 deletions.
9 changes: 5 additions & 4 deletions internal/experimental/registry/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
10 changes: 10 additions & 0 deletions internal/experimental/registry/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions internal/resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
5 changes: 2 additions & 3 deletions pkg/action/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
25 changes: 23 additions & 2 deletions pkg/getter/ocigetter.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"fmt"
"strings"

"github.com/pkg/errors"

"helm.sh/helm/v3/internal/experimental/registry"
)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit df98e18

Please sign in to comment.