@@ -461,7 +461,7 @@ func (r *HelmChartReconciler) buildFromHelmRepository(ctx context.Context, obj *
461
461
loginOpts []helmreg.LoginOption
462
462
)
463
463
464
- normalizedURL := strings . TrimSuffix (repo .Spec .URL , "/" )
464
+ normalizedURL := repository . NormalizeURL (repo .Spec .URL )
465
465
// Construct the Getter options from the HelmRepository data
466
466
clientOpts := []helmgetter.Option {
467
467
helmgetter .WithURL (normalizedURL ),
@@ -519,7 +519,7 @@ func (r *HelmChartReconciler) buildFromHelmRepository(ctx context.Context, obj *
519
519
}
520
520
521
521
// Initialize the chart repository
522
- var chartRepo chart .Downloader
522
+ var chartRepo repository .Downloader
523
523
switch repo .Spec .Type {
524
524
case sourcev1 .HelmRepositoryTypeOCI :
525
525
if ! helmreg .IsOCI (normalizedURL ) {
@@ -687,7 +687,13 @@ func (r *HelmChartReconciler) buildFromTarballArtifact(ctx context.Context, obj
687
687
dm := chart .NewDependencyManager (
688
688
chart .WithDownloaderCallback (r .namespacedChartRepositoryCallback (ctx , obj .GetName (), obj .GetNamespace ())),
689
689
)
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
+ }()
691
697
692
698
// Configure builder options, including any previously cached chart
693
699
opts := chart.BuildOptions {
@@ -915,16 +921,16 @@ func (r *HelmChartReconciler) garbageCollect(ctx context.Context, obj *sourcev1.
915
921
}
916
922
917
923
// 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,
919
925
// or a shim with defaults if no object could be found.
920
926
// The callback returns an object with a state, so the caller has to do the necessary cleanup.
921
927
func (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 ) {
923
929
var (
924
930
tlsConfig * tls.Config
925
931
loginOpts []helmreg.LoginOption
926
932
)
927
- normalizedURL := strings . TrimSuffix (url , "/" )
933
+ normalizedURL := repository . NormalizeURL (url )
928
934
repo , err := r .resolveDependencyRepository (ctx , url , namespace )
929
935
if err != nil {
930
936
// Return Kubernetes client errors, but ignore others
@@ -967,7 +973,7 @@ func (r *HelmChartReconciler) namespacedChartRepositoryCallback(ctx context.Cont
967
973
loginOpts = append ([]helmreg.LoginOption {}, loginOpt )
968
974
}
969
975
970
- var chartRepo chart. CleanableDownloader
976
+ var chartRepo repository. Downloader
971
977
if helmreg .IsOCI (normalizedURL ) {
972
978
registryClient , file , err := r .RegistryClientGenerator (loginOpts != nil )
973
979
if err != nil {
@@ -980,13 +986,15 @@ func (r *HelmChartReconciler) namespacedChartRepositoryCallback(ctx context.Cont
980
986
ociChartRepo , err := repository .NewOCIChartRepository (normalizedURL , repository .WithOCIGetter (r .Getters ),
981
987
repository .WithOCIGetterOptions (clientOpts ),
982
988
repository .WithOCIRegistryClient (registryClient ),
983
- repository .WithCredentialFile (file ))
989
+ repository .WithCredentialsFile (file ))
984
990
if err != nil {
991
+ errs = append (errs , fmt .Errorf ("failed to create OCI chart repository for HelmRepository '%s': %w" , repo .Name , err ))
985
992
// 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
+ }
988
997
}
989
- errs = append (errs , fmt .Errorf ("failed to create OCI chart repository for HelmRepository '%s': %w" , repo .Name , err ))
990
998
return nil , kerrors .NewAggregate (errs )
991
999
}
992
1000
@@ -995,7 +1003,14 @@ func (r *HelmChartReconciler) namespacedChartRepositoryCallback(ctx context.Cont
995
1003
if loginOpts != nil {
996
1004
err = ociChartRepo .Login (loginOpts ... )
997
1005
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 )
999
1014
}
1000
1015
}
1001
1016
0 commit comments