Skip to content
This repository was archived by the owner on Aug 12, 2026. It is now read-only.

Commit e2153e2

Browse files
committed
fix relative urls
Signed-off-by: Andrei Kvapil <[email protected]>
1 parent b1467ce commit e2153e2

1 file changed

Lines changed: 33 additions & 3 deletions

File tree

  • cmd/kubeapps-apis/plugins/fluxv2/packages/v1alpha1/cache

‎cmd/kubeapps-apis/plugins/fluxv2/packages/v1alpha1/cache/chart_cache.go‎

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2021-2023 the Kubeapps contributors.
1+
// Copyright 2021-2023 the Kubeapps contribchart.ChartVersionsutors.
22
// SPDX-License-Identifier: Apache-2.0
33

44
package cache
@@ -165,11 +165,18 @@ func (c *ChartCache) SyncCharts(charts []models.Chart, downloadFn DownloadChartF
165165
u.RawQuery = q.Encode()
166166
}
167167

168+
rawURL := chart.ChartVersions[0].URLs[0]
169+
fullURL, err := resolveChartURL(chart.Repo.URL, rawURL)
170+
if err != nil {
171+
log.Warningf("Skipping chart [%s]: %v", chart.ID, err)
172+
continue
173+
}
174+
168175
entry := chartCacheStoreEntry{
169176
namespace: chart.Repo.Namespace,
170177
id: chart.ID,
171178
version: chart.ChartVersions[0].Version,
172-
url: u.String(),
179+
url: fullURL,
173180
downloadFn: downloadFn,
174181
deleted: false,
175182
}
@@ -538,13 +545,18 @@ func (c *ChartCache) Get(key string, chart *models.Chart, downloadFn DownloadCha
538545
if len(v.URLs) == 0 {
539546
log.Warningf("The chart: [%s], version: [%s] has no URLs", chart.ID, v.Version)
540547
} else {
548+
fullURL, err := resolveChartURL(chart.Repo.URL, v.URLs[0])
549+
if err != nil {
550+
return nil, err
551+
}
541552
entry = &chartCacheStoreEntry{
542553
namespace: namespace,
543554
id: chartID,
544555
version: v.Version,
545-
url: v.URLs[0],
556+
url: fullURL,
546557
downloadFn: downloadFn,
547558
}
559+
548560
}
549561
break
550562
}
@@ -695,3 +707,21 @@ func ChartCacheComputeValue(chartID, chartUrl, chartVersion string, downloadFn D
695707
return gobBuf.Bytes(), nil
696708
}
697709
}
710+
711+
func resolveChartURL(repo string, chartPath string) (string, error) {
712+
u, err := url.Parse(chartPath)
713+
if err != nil {
714+
return "", fmt.Errorf("invalid chart URL %q: %w", chartPath, err)
715+
}
716+
if u.IsAbs() { // уже полный URL
717+
return u.String(), nil
718+
}
719+
720+
base, err := url.Parse(repo)
721+
if err != nil {
722+
return "", fmt.Errorf("invalid repo URL %q: %w", repo, err)
723+
}
724+
// гарантируем, что в конце есть ровно один «/»
725+
base.Path = strings.TrimSuffix(base.Path, "/") + "/"
726+
return base.ResolveReference(u).String(), nil
727+
}

0 commit comments

Comments
 (0)