fix: oci getter with version option and ref version

Signed-off-by: zhangzhiqiang02 <zhangzhiqiang02@megvii.com>
pull/12558/head
zhangzhiqiang02 8 months ago
parent 8219565249
commit 6923a82233
No known key found for this signature in database
GPG Key ID: 45FA21DD7659C90B

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

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

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

Loading…
Cancel
Save