@@ -143,11 +143,8 @@ type HelmChartReconciler struct {
143143 patchOptions []patch.Option
144144}
145145
146- // RegistryClientGeneratorFunc is a function that returns a registry client
147- // and an optional file name.
148- // The file is used to store the registry client credentials.
149- // The caller is responsible for deleting the file.
150- type RegistryClientGeneratorFunc func (tlsConfig * tls.Config , isLogin , insecure bool ) (* helmreg.Client , string , error )
146+ // RegistryClientGeneratorFunc is a function that returns a registry client.
147+ type RegistryClientGeneratorFunc func (tlsConfig * tls.Config , isLogin , insecure bool ) (* helmreg.Client , error )
151148
152149func (r * HelmChartReconciler ) SetupWithManager (ctx context.Context , mgr ctrl.Manager ) error {
153150 return r .SetupWithManagerAndOptions (ctx , mgr , HelmChartReconcilerOptions {})
@@ -552,11 +549,7 @@ func (r *HelmChartReconciler) buildFromHelmRepository(ctx context.Context, obj *
552549 return chartRepoConfigErrorReturn (err , obj )
553550 }
554551
555- // with this function call, we create a temporary file to store the credentials if needed.
556- // this is needed because otherwise the credentials are stored in ~/.docker/config.json.
557- // TODO@souleb: remove this once the registry move to Oras v2
558- // or rework to enable reusing credentials to avoid the unneccessary handshake operations
559- registryClient , credentialsFile , err := r .RegistryClientGenerator (clientOpts .TlsConfig , clientOpts .MustLoginToRegistry (), repo .Spec .Insecure )
552+ registryClient , err := r .RegistryClientGenerator (clientOpts .TlsConfig , clientOpts .MustLoginToRegistry (), repo .Spec .Insecure )
560553 if err != nil {
561554 e := serror .NewGeneric (
562555 fmt .Errorf ("failed to construct Helm client: %w" , err ),
@@ -566,15 +559,6 @@ func (r *HelmChartReconciler) buildFromHelmRepository(ctx context.Context, obj *
566559 return sreconcile .ResultEmpty , e
567560 }
568561
569- if credentialsFile != "" {
570- defer func () {
571- if err := os .Remove (credentialsFile ); err != nil {
572- r .eventLogf (ctx , obj , corev1 .EventTypeWarning , meta .FailedReason ,
573- "failed to delete temporary credentials file: %s" , err )
574- }
575- }()
576- }
577-
578562 var verifiers []soci.Verifier
579563 if obj .Spec .Verify != nil {
580564 provider := obj .Spec .Verify .Provider
@@ -1026,39 +1010,34 @@ func (r *HelmChartReconciler) namespacedChartRepositoryCallback(ctx context.Cont
10261010
10271011 var chartRepo repository.Downloader
10281012 if helmreg .IsOCI (normalizedURL ) {
1029- registryClient , credentialsFile , err := r .RegistryClientGenerator (clientOpts .TlsConfig , clientOpts .MustLoginToRegistry (), obj .Spec .Insecure )
1013+ registryClient , err := r .RegistryClientGenerator (clientOpts .TlsConfig , clientOpts .MustLoginToRegistry (), obj .Spec .Insecure )
10301014 if err != nil {
10311015 return nil , fmt .Errorf ("failed to create registry client: %w" , err )
10321016 }
10331017
1034- var errs []error
10351018 // Tell the chart repository to use the OCI client with the configured getter
10361019 getterOpts = append (getterOpts , helmgetter .WithRegistryClient (registryClient ))
10371020 ociChartRepo , err := repository .NewOCIChartRepository (normalizedURL , repository .WithOCIGetter (r .Getters ),
10381021 repository .WithOCIGetterOptions (getterOpts ),
10391022 repository .WithOCIRegistryClient (registryClient ),
1040- repository .WithCertificatesStore (certsTmpDir ),
1041- repository .WithCredentialsFile (credentialsFile ))
1023+ repository .WithCertificatesStore (certsTmpDir ))
10421024 if err != nil {
1043- errs = append (errs , fmt .Errorf ("failed to create OCI chart repository: %w" , err ))
1044- // clean up the credentialsFile
1045- if credentialsFile != "" {
1046- if err := os .Remove (credentialsFile ); err != nil {
1047- errs = append (errs , err )
1048- }
1049- }
1050- return nil , kerrors .NewAggregate (errs )
1025+ return nil , fmt .Errorf ("failed to create OCI chart repository: %w" , err )
10511026 }
10521027
10531028 // If login options are configured, use them to login to the registry
10541029 // The OCIGetter will later retrieve the stored credentials to pull the chart
10551030 if clientOpts .MustLoginToRegistry () {
10561031 err = ociChartRepo .Login (clientOpts .RegLoginOpts ... )
10571032 if err != nil {
1058- errs = append (errs , fmt .Errorf ("failed to login to OCI chart repository: %w" , err ))
1059- // clean up the credentialsFile
1060- errs = append (errs , ociChartRepo .Clear ())
1061- return nil , kerrors .NewAggregate (errs )
1033+ err = fmt .Errorf ("failed to login to OCI chart repository: %w" , err )
1034+ if clearErr := ociChartRepo .Clear (); clearErr != nil {
1035+ var errs []error
1036+ errs = append (errs , err )
1037+ errs = append (errs , clearErr )
1038+ return nil , kerrors .NewAggregate (errs )
1039+ }
1040+ return nil , err
10621041 }
10631042 }
10641043
0 commit comments