@@ -461,7 +461,7 @@ func (r *HelmChartReconciler) buildFromHelmRepository(ctx context.Context, obj *
461461 loginOpts []helmreg.LoginOption
462462 )
463463
464- normalizedURL := strings . TrimSuffix (repo .Spec .URL , "/" )
464+ normalizedURL := repository . NormalizeURL (repo .Spec .URL )
465465 // Construct the Getter options from the HelmRepository data
466466 clientOpts := []helmgetter.Option {
467467 helmgetter .WithURL (normalizedURL ),
@@ -519,7 +519,7 @@ func (r *HelmChartReconciler) buildFromHelmRepository(ctx context.Context, obj *
519519 }
520520
521521 // Initialize the chart repository
522- var chartRepo chart .Downloader
522+ var chartRepo repository .Downloader
523523 switch repo .Spec .Type {
524524 case sourcev1 .HelmRepositoryTypeOCI :
525525 if ! helmreg .IsOCI (normalizedURL ) {
@@ -687,7 +687,13 @@ func (r *HelmChartReconciler) buildFromTarballArtifact(ctx context.Context, obj
687687 dm := chart .NewDependencyManager (
688688 chart .WithDownloaderCallback (r .namespacedChartRepositoryCallback (ctx , obj .GetName (), obj .GetNamespace ())),
689689 )
690- defer dm .Clear ()
690+ defer func () {
691+ err := dm .Clear ()
692+ if err != nil {
693+ r .eventLogf (ctx , obj , corev1 .EventTypeWarning , meta .FailedReason ,
694+ "dependency manager cleanup error: %s" , err )
695+ }
696+ }()
691697
692698 // Configure builder options, including any previously cached chart
693699 opts := chart.BuildOptions {
@@ -915,16 +921,16 @@ func (r *HelmChartReconciler) garbageCollect(ctx context.Context, obj *sourcev1.
915921}
916922
917923// namespacedChartRepositoryCallback returns a chart.GetChartDownloaderCallback scoped to the given namespace.
918- // The returned callback returns a repository.ChartRepository configured with the retrieved v1beta1.HelmRepository,
924+ // The returned callback returns a repository.Downloader configured with the retrieved v1beta1.HelmRepository,
919925// or a shim with defaults if no object could be found.
920926// The callback returns an object with a state, so the caller has to do the necessary cleanup.
921927func (r * HelmChartReconciler ) namespacedChartRepositoryCallback (ctx context.Context , name , namespace string ) chart.GetChartDownloaderCallback {
922- return func (url string ) (chart. CleanableDownloader , error ) {
928+ return func (url string ) (repository. Downloader , error ) {
923929 var (
924930 tlsConfig * tls.Config
925931 loginOpts []helmreg.LoginOption
926932 )
927- normalizedURL := strings . TrimSuffix (url , "/" )
933+ normalizedURL := repository . NormalizeURL (url )
928934 repo , err := r .resolveDependencyRepository (ctx , url , namespace )
929935 if err != nil {
930936 // Return Kubernetes client errors, but ignore others
@@ -967,7 +973,7 @@ func (r *HelmChartReconciler) namespacedChartRepositoryCallback(ctx context.Cont
967973 loginOpts = append ([]helmreg.LoginOption {}, loginOpt )
968974 }
969975
970- var chartRepo chart. CleanableDownloader
976+ var chartRepo repository. Downloader
971977 if helmreg .IsOCI (normalizedURL ) {
972978 registryClient , file , err := r .RegistryClientGenerator (loginOpts != nil )
973979 if err != nil {
@@ -980,13 +986,15 @@ func (r *HelmChartReconciler) namespacedChartRepositoryCallback(ctx context.Cont
980986 ociChartRepo , err := repository .NewOCIChartRepository (normalizedURL , repository .WithOCIGetter (r .Getters ),
981987 repository .WithOCIGetterOptions (clientOpts ),
982988 repository .WithOCIRegistryClient (registryClient ),
983- repository .WithCredentialFile (file ))
989+ repository .WithCredentialsFile (file ))
984990 if err != nil {
991+ errs = append (errs , fmt .Errorf ("failed to create OCI chart repository for HelmRepository '%s': %w" , repo .Name , err ))
985992 // clean up the file
986- if err := os .Remove (file ); err != nil {
987- errs = append (errs , err )
993+ if file != "" {
994+ if err := os .Remove (file ); err != nil {
995+ errs = append (errs , err )
996+ }
988997 }
989- errs = append (errs , fmt .Errorf ("failed to create OCI chart repository for HelmRepository '%s': %w" , repo .Name , err ))
990998 return nil , kerrors .NewAggregate (errs )
991999 }
9921000
@@ -995,7 +1003,14 @@ func (r *HelmChartReconciler) namespacedChartRepositoryCallback(ctx context.Cont
9951003 if loginOpts != nil {
9961004 err = ociChartRepo .Login (loginOpts ... )
9971005 if err != nil {
998- return nil , fmt .Errorf ("failed to login to OCI chart repository for HelmRepository '%s': %w" , repo .Name , err )
1006+ errs = append (errs , fmt .Errorf ("failed to login to OCI chart repository for HelmRepository '%s': %w" , repo .Name , err ))
1007+ // clean up the file
1008+ if file != "" {
1009+ if err := os .Remove (file ); err != nil {
1010+ errs = append (errs , err )
1011+ }
1012+ }
1013+ return nil , kerrors .NewAggregate (errs )
9991014 }
10001015 }
10011016
0 commit comments