@@ -143,11 +143,8 @@ type HelmChartReconciler struct {
143
143
patchOptions []patch.Option
144
144
}
145
145
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 )
151
148
152
149
func (r * HelmChartReconciler ) SetupWithManager (ctx context.Context , mgr ctrl.Manager ) error {
153
150
return r .SetupWithManagerAndOptions (ctx , mgr , HelmChartReconcilerOptions {})
@@ -552,11 +549,7 @@ func (r *HelmChartReconciler) buildFromHelmRepository(ctx context.Context, obj *
552
549
return chartRepoConfigErrorReturn (err , obj )
553
550
}
554
551
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 )
560
553
if err != nil {
561
554
e := serror .NewGeneric (
562
555
fmt .Errorf ("failed to construct Helm client: %w" , err ),
@@ -566,15 +559,6 @@ func (r *HelmChartReconciler) buildFromHelmRepository(ctx context.Context, obj *
566
559
return sreconcile .ResultEmpty , e
567
560
}
568
561
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
-
578
562
var verifiers []soci.Verifier
579
563
if obj .Spec .Verify != nil {
580
564
provider := obj .Spec .Verify .Provider
@@ -1026,39 +1010,34 @@ func (r *HelmChartReconciler) namespacedChartRepositoryCallback(ctx context.Cont
1026
1010
1027
1011
var chartRepo repository.Downloader
1028
1012
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 )
1030
1014
if err != nil {
1031
1015
return nil , fmt .Errorf ("failed to create registry client: %w" , err )
1032
1016
}
1033
1017
1034
- var errs []error
1035
1018
// Tell the chart repository to use the OCI client with the configured getter
1036
1019
getterOpts = append (getterOpts , helmgetter .WithRegistryClient (registryClient ))
1037
1020
ociChartRepo , err := repository .NewOCIChartRepository (normalizedURL , repository .WithOCIGetter (r .Getters ),
1038
1021
repository .WithOCIGetterOptions (getterOpts ),
1039
1022
repository .WithOCIRegistryClient (registryClient ),
1040
- repository .WithCertificatesStore (certsTmpDir ),
1041
- repository .WithCredentialsFile (credentialsFile ))
1023
+ repository .WithCertificatesStore (certsTmpDir ))
1042
1024
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 )
1051
1026
}
1052
1027
1053
1028
// If login options are configured, use them to login to the registry
1054
1029
// The OCIGetter will later retrieve the stored credentials to pull the chart
1055
1030
if clientOpts .MustLoginToRegistry () {
1056
1031
err = ociChartRepo .Login (clientOpts .RegLoginOpts ... )
1057
1032
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
1062
1041
}
1063
1042
}
1064
1043
0 commit comments