Skip to content

Commit 6ecd349

Browse files
committed
use function from helm pkg
Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
1 parent e0fc0d0 commit 6ecd349

File tree

3 files changed

+3
-27
lines changed

3 files changed

+3
-27
lines changed

internal/helm/repository/chart_repository.go

+2-17
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"os"
3030
"path"
3131
"sort"
32-
"strings"
3332
"sync"
3433
"time"
3534

@@ -261,30 +260,16 @@ func (r *ChartRepository) DownloadChart(chart *repo.ChartVersion) (*bytes.Buffer
261260
// always the correct one to pick, check for updates once in awhile.
262261
// Ref: https://github.com/helm/helm/blob/v3.3.0/pkg/downloader/chart_downloader.go#L241
263262
ref := chart.URLs[0]
264-
u, err := url.Parse(ref)
263+
resolvedUrl, err := repo.ResolveReferenceURL(r.URL, ref)
265264
if err != nil {
266-
err = fmt.Errorf("invalid chart URL format '%s': %w", ref, err)
267265
return nil, err
268266
}
269267

270-
// Prepend the chart repository base URL if the URL is relative
271-
if !u.IsAbs() {
272-
repoURL, err := url.Parse(r.URL)
273-
if err != nil {
274-
err = fmt.Errorf("invalid chart repository URL format '%s': %w", r.URL, err)
275-
return nil, err
276-
}
277-
// Trailing slash is required for ResolveReference to work
278-
repoURL.Path = strings.TrimSuffix(repoURL.Path, "/") + "/"
279-
u = repoURL.ResolveReference(u)
280-
u.RawQuery = repoURL.RawQuery
281-
}
282-
283268
t := transport.NewOrIdle(r.tlsConfig)
284269
clientOpts := append(r.Options, getter.WithTransport(t))
285270
defer transport.Release(t)
286271

287-
return r.Client.Get(u.String(), clientOpts...)
272+
return r.Client.Get(resolvedUrl, clientOpts...)
288273
}
289274

290275
// LoadIndexFromBytes loads Index from the given bytes.

internal/helm/repository/utils.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,12 @@ var (
3737

3838
// NormalizeURL normalizes a ChartRepository URL by its scheme.
3939
func NormalizeURL(repositoryURL string) (string, error) {
40-
if repositoryURL == "" {
41-
return "", nil
42-
}
43-
4440
u, err := url.Parse(repositoryURL)
4541
if err != nil {
4642
return "", err
4743
}
4844

49-
if strings.Contains(repositoryURL, helmreg.OCIScheme) {
45+
if u.Scheme == helmreg.OCIScheme {
5046
u.Path = strings.TrimRight(u.Path, "/")
5147
return u.String(), nil
5248
}

internal/helm/repository/utils_test.go

-5
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ func TestNormalizeURL(t *testing.T) {
4343
url: "http://example.com//",
4444
want: "http://example.com/",
4545
},
46-
{
47-
name: "empty",
48-
url: "",
49-
want: "",
50-
},
5146
{
5247
name: "oci with slash",
5348
url: "oci://example.com/",

0 commit comments

Comments
 (0)