diff --git a/pkg/downloader/chart_downloader.go b/pkg/downloader/chart_downloader.go index a95894e00..0fed58172 100644 --- a/pkg/downloader/chart_downloader.go +++ b/pkg/downloader/chart_downloader.go @@ -145,6 +145,14 @@ func (c *ChartDownloader) getOciURI(ref, version string, u *url.URL) (*url.URL, var tag string var err error + if strings.Contains(u.Path, ":") { + v := strings.Split(u.Path, ":")[1] + if version != "" && v != version { + return nil, errors.Errorf("chart ref version mismatch: %s, %s", version, v) + } + return u, nil + } + // Evaluate whether an explicit version has been provided. Otherwise, determine version to use _, errSemVer := semver.NewVersion(version) if errSemVer == nil { diff --git a/pkg/downloader/chart_downloader_test.go b/pkg/downloader/chart_downloader_test.go index 131e21306..ba27f6f8c 100644 --- a/pkg/downloader/chart_downloader_test.go +++ b/pkg/downloader/chart_downloader_test.go @@ -53,6 +53,8 @@ func TestResolveChartRef(t *testing.T) { {name: "full URL, file", ref: "file:///foo-1.2.3.tgz", fail: true}, {name: "invalid", ref: "invalid-1.2.3", fail: true}, {name: "not found", ref: "nosuchthing/invalid-1.2.3", fail: true}, + {name: "ref with tag", ref: "oci://example.com/helm-charts/nginx:15.4.2", expect: "oci://example.com/helm-charts/nginx:15.4.2"}, + {name: "oci ref", ref: "oci://example.com/helm-charts/nginx", version: "15.4.2", expect: "oci://example.com/helm-charts/nginx:15.4.2"}, } c := ChartDownloader{ diff --git a/pkg/getter/ocigetter.go b/pkg/getter/ocigetter.go index 209786bd7..3d571107d 100644 --- a/pkg/getter/ocigetter.go +++ b/pkg/getter/ocigetter.go @@ -20,6 +20,7 @@ import ( "fmt" "net" "net/http" + "path" "strings" "sync" "time" @@ -57,7 +58,9 @@ func (g *OCIGetter) get(href string) (*bytes.Buffer, error) { } ref := strings.TrimPrefix(href, fmt.Sprintf("%s://", registry.OCIScheme)) - + if version := g.opts.version; version != "" && !strings.Contains(path.Base(ref), ":") { + ref = fmt.Sprintf("%s:%s", ref, version) + } var pullOpts []registry.PullOption requestingProv := strings.HasSuffix(ref, ".prov") if requestingProv {