Skip to content

Commit 3c3d381

Browse files
authored
Merge pull request #118 from fluxcd/relative-chart-url-fix
Support Helm repository indexes with relative URLs
2 parents 3af8670 + f4d047a commit 3c3d381

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

controllers/helmchart_controller.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,27 @@ func (r *HelmChartReconciler) reconcile(ctx context.Context, repository sourcev1
180180

181181
// TODO(hidde): according to the Helm source the first item is not
182182
// always the correct one to pick, check for updates once in awhile.
183+
// Ref: https://github.com/helm/helm/blob/v3.3.0/pkg/downloader/chart_downloader.go#L241
183184
ref := cv.URLs[0]
184185
u, err := url.Parse(ref)
185186
if err != nil {
186187
err = fmt.Errorf("invalid chart URL format '%s': %w", ref, err)
187188
}
188189

190+
// Prepend the chart repository base URL if the URL is relative
191+
if !u.IsAbs() {
192+
repoURL, err := url.Parse(repository.Spec.URL)
193+
if err != nil {
194+
err = fmt.Errorf("invalid repository URL format '%s': %w", repository.Spec.URL, err)
195+
return sourcev1.HelmChartNotReady(chart, sourcev1.ChartPullFailedReason, err.Error()), err
196+
}
197+
q := repoURL.Query()
198+
// Trailing slash is required for ResolveReference to work
199+
repoURL.Path = strings.TrimSuffix(repoURL.Path, "/") + "/"
200+
u = repoURL.ResolveReference(u)
201+
u.RawQuery = q.Encode()
202+
}
203+
189204
c, err := r.Getters.ByScheme(u.Scheme)
190205
if err != nil {
191206
return sourcev1.HelmChartNotReady(chart, sourcev1.ChartPullFailedReason, err.Error()), err

0 commit comments

Comments
 (0)