@@ -445,16 +445,18 @@ func (r *HelmChartReconciler) reconcileSource(ctx context.Context, obj *sourcev1
445
445
// object, and returns early.
446
446
func (r * HelmChartReconciler ) buildFromHelmRepository (ctx context.Context , obj * sourcev1.HelmChart ,
447
447
repo * sourcev1.HelmRepository , b * chart.Build ) (sreconcile.Result , error ) {
448
- var tlsConfig * tls.Config
448
+ var (
449
+ tlsConfig * tls.Config
450
+ logOpts []registry.LoginOption
451
+ )
449
452
450
453
// Construct the Getter options from the HelmRepository data
451
454
clientOpts := []helmgetter.Option {
452
455
helmgetter .WithURL (repo .Spec .URL ),
453
456
helmgetter .WithTimeout (repo .Spec .Timeout .Duration ),
454
457
helmgetter .WithPassCredentialsAll (repo .Spec .PassCredentials ),
455
458
}
456
- secret , err := r .getHelmRepositorySecret (ctx , repo )
457
- if secret != nil || err != nil {
459
+ if secret , err := r .getHelmRepositorySecret (ctx , repo ); secret != nil || err != nil {
458
460
if err != nil {
459
461
e := & serror.Event {
460
462
Err : fmt .Errorf ("failed to get secret '%s': %w" , repo .Spec .SecretRef .Name , err ),
@@ -488,13 +490,27 @@ func (r *HelmChartReconciler) buildFromHelmRepository(ctx context.Context, obj *
488
490
// Requeue as content of secret might change
489
491
return sreconcile .ResultEmpty , e
490
492
}
493
+
494
+ // Build registryClient options from secret
495
+ logOpt , err := loginOptionFromSecret (* secret )
496
+ if err != nil {
497
+ e := & serror.Event {
498
+ Err : fmt .Errorf ("failed to configure Helm client with secret data: %w" , err ),
499
+ Reason : sourcev1 .AuthenticationFailedReason ,
500
+ }
501
+ conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , e .Err .Error ())
502
+ // Requeue as content of secret might change
503
+ return sreconcile .ResultEmpty , e
504
+ }
505
+
506
+ logOpts = append ([]registry.LoginOption {}, logOpt )
491
507
}
492
508
493
509
// Initialize the chart repository
494
510
var chartRepo chart.Remote
495
511
if repo .Spec .Type == sourcev1 .HelmRepositoryTypeOCI {
496
512
if ! registry .IsOCI (repo .Spec .URL ) {
497
- err = fmt .Errorf ("invalid OCI registry URL: %s" , repo .Spec .URL )
513
+ err : = fmt .Errorf ("invalid OCI registry URL: %s" , repo .Spec .URL )
498
514
return chartRepoErrorReturn (err , obj )
499
515
}
500
516
// Tell the chart repository to use the OCI client with the configured getter
@@ -507,15 +523,7 @@ func (r *HelmChartReconciler) buildFromHelmRepository(ctx context.Context, obj *
507
523
508
524
// If login options are configured, use them to login to the registry
509
525
// The OCIGetter will later retrieve the stored credentials to pull the chart
510
- if secret != nil {
511
- // Construct actual options
512
- logOpt , err := loginOptionFromSecret (* secret )
513
- if err != nil {
514
- return chartRepoErrorReturn (err , obj )
515
- }
516
-
517
- logOpts := append ([]registry.LoginOption {}, logOpt )
518
-
526
+ if logOpts != nil {
519
527
// create a temporary file to store the credentials
520
528
// this is needed because otherwise the credentials are stored in ~/.docker/config.json.
521
529
// TODO@souleb: remove this once the registry move to Oras v2
@@ -535,7 +543,7 @@ func (r *HelmChartReconciler) buildFromHelmRepository(ctx context.Context, obj *
535
543
}
536
544
} else {
537
545
var httpChartRepo * repository.ChartRepository
538
- httpChartRepo , err = repository .NewChartRepository (repo .Spec .URL , r .Storage .LocalPath (* repo .GetArtifact ()), r .Getters , tlsConfig , clientOpts ,
546
+ httpChartRepo , err : = repository .NewChartRepository (repo .Spec .URL , r .Storage .LocalPath (* repo .GetArtifact ()), r .Getters , tlsConfig , clientOpts ,
539
547
repository .WithMemoryCache (r .Storage .LocalPath (* repo .GetArtifact ()), r .Cache , r .TTL , func (event string ) {
540
548
r .IncCacheEvents (event , obj .Name , obj .Namespace )
541
549
}))
0 commit comments