@@ -26,7 +26,6 @@ import (
2626
2727 "github.com/go-logr/logr"
2828 "helm.sh/helm/v3/pkg/getter"
29- "helm.sh/helm/v3/pkg/repo"
3029 corev1 "k8s.io/api/core/v1"
3130 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3231 "k8s.io/apimachinery/pkg/runtime"
@@ -36,9 +35,9 @@ import (
3635 ctrl "sigs.k8s.io/controller-runtime"
3736 "sigs.k8s.io/controller-runtime/pkg/client"
3837 "sigs.k8s.io/controller-runtime/pkg/controller"
39- "sigs.k8s.io/yaml"
4038
4139 "github.com/fluxcd/pkg/recorder"
40+
4241 sourcev1 "github.com/fluxcd/source-controller/api/v1alpha1"
4342 "github.com/fluxcd/source-controller/internal/helm"
4443)
@@ -174,30 +173,8 @@ func (r *HelmChartReconciler) SetupWithManagerAndOptions(mgr ctrl.Manager, opts
174173}
175174
176175func (r * HelmChartReconciler ) reconcile (ctx context.Context , repository sourcev1.HelmRepository , chart sourcev1.HelmChart ) (sourcev1.HelmChart , error ) {
177- indexBytes , err := ioutil .ReadFile (repository .Status .Artifact .Path )
178- if err != nil {
179- err = fmt .Errorf ("failed to read Helm repository index file: %w" , err )
180- return sourcev1 .HelmChartNotReady (chart , sourcev1 .StorageOperationFailedReason , err .Error ()), err
181- }
182- index := & repo.IndexFile {}
183- if err := yaml .Unmarshal (indexBytes , index ); err != nil {
184- return sourcev1 .HelmChartNotReady (chart , sourcev1 .StorageOperationFailedReason , err .Error ()), err
185- }
186-
187- // find referenced chart in index
188- cv , err := index .Get (chart .Spec .Name , chart .Spec .Version )
176+ cv , err := helm .GetDownloadableChartVersionFromIndex (repository .Status .Artifact .Path , chart .Spec .Name , chart .Spec .Version )
189177 if err != nil {
190- switch err {
191- case repo .ErrNoChartName :
192- err = fmt .Errorf ("chart '%s' could not be found in Helm repository '%s'" , chart .Spec .Name , repository .Name )
193- case repo .ErrNoChartVersion :
194- err = fmt .Errorf ("no chart with version '%s' found for '%s'" , chart .Spec .Version , chart .Spec .Name )
195- }
196- return sourcev1 .HelmChartNotReady (chart , sourcev1 .ChartPullFailedReason , err .Error ()), err
197- }
198-
199- if len (cv .URLs ) == 0 {
200- err = fmt .Errorf ("chart '%s' has no downloadable URLs" , cv .Name )
201178 return sourcev1 .HelmChartNotReady (chart , sourcev1 .ChartPullFailedReason , err .Error ()), err
202179 }
203180
@@ -207,7 +184,6 @@ func (r *HelmChartReconciler) reconcile(ctx context.Context, repository sourcev1
207184 u , err := url .Parse (ref )
208185 if err != nil {
209186 err = fmt .Errorf ("invalid chart URL format '%s': %w" , ref , err )
210- return sourcev1 .HelmChartNotReady (chart , sourcev1 .ChartPullFailedReason , err .Error ()), err
211187 }
212188
213189 c , err := r .Getters .ByScheme (u .Scheme )
0 commit comments