@@ -455,33 +455,6 @@ func (r *GitRepositoryReconciler) reconcileSource(ctx context.Context,
455
455
return sreconcile .ResultEmpty , e
456
456
}
457
457
458
- repositoryURL := obj .Spec .URL
459
- // managed GIT transport only affects the libgit2 implementation
460
- if managed .Enabled () && obj .Spec .GitImplementation == sourcev1 .LibGit2Implementation {
461
- // At present only HTTP connections have the ability to define remote options.
462
- // Although this can be easily extended by ensuring that the fake URL below uses the
463
- // target ssh scheme, and the libgit2/managed/ssh.go pulls that information accordingly.
464
- //
465
- // This is due to the fact the key libgit2 remote callbacks do not take place for HTTP
466
- // whilst most still work for SSH.
467
- if strings .HasPrefix (repositoryURL , "http" ) {
468
- // Due to the lack of the callback feature, a fake target URL is created to allow
469
- // for the smart sub transport be able to pick the options specific for this
470
- // GitRepository object.
471
- // The URL should use unique information that do not collide in a multi tenant
472
- // deployment.
473
- repositoryURL = fmt .Sprintf ("http://%s/%s/%d" , obj .Name , obj .UID , obj .Generation )
474
- managed .AddTransportOptions (repositoryURL ,
475
- managed.TransportOptions {
476
- TargetURL : obj .Spec .URL ,
477
- CABundle : authOpts .CAFile ,
478
- })
479
-
480
- // We remove the options from memory, to avoid accumulating unused options over time.
481
- defer managed .RemoveTransportOptions (repositoryURL )
482
- }
483
- }
484
-
485
458
// Fetch the included artifact metadata.
486
459
artifacts , err := r .fetchIncludes (ctx , obj )
487
460
if err != nil {
@@ -503,7 +476,7 @@ func (r *GitRepositoryReconciler) reconcileSource(ctx context.Context,
503
476
optimizedClone = true
504
477
}
505
478
506
- c , err := r .gitCheckout (ctx , obj , repositoryURL , authOpts , dir , optimizedClone )
479
+ c , err := r .gitCheckout (ctx , obj , authOpts , dir , optimizedClone )
507
480
if err != nil {
508
481
return sreconcile .ResultEmpty , err
509
482
}
@@ -537,7 +510,7 @@ func (r *GitRepositoryReconciler) reconcileSource(ctx context.Context,
537
510
538
511
// If we can't skip the reconciliation, checkout again without any
539
512
// optimization.
540
- c , err := r .gitCheckout (ctx , obj , repositoryURL , authOpts , dir , false )
513
+ c , err := r .gitCheckout (ctx , obj , authOpts , dir , false )
541
514
if err != nil {
542
515
return sreconcile .ResultEmpty , err
543
516
}
@@ -729,7 +702,7 @@ func (r *GitRepositoryReconciler) reconcileInclude(ctx context.Context,
729
702
// gitCheckout builds checkout options with the given configurations and
730
703
// performs a git checkout.
731
704
func (r * GitRepositoryReconciler ) gitCheckout (ctx context.Context ,
732
- obj * sourcev1.GitRepository , repoURL string , authOpts * git.AuthOptions , dir string , optimized bool ) (* git.Commit , error ) {
705
+ obj * sourcev1.GitRepository , authOpts * git.AuthOptions , dir string , optimized bool ) (* git.Commit , error ) {
733
706
// Configure checkout strategy.
734
707
checkoutOpts := git.CheckoutOptions {RecurseSubmodules : obj .Spec .RecurseSubmodules }
735
708
if ref := obj .Spec .Reference ; ref != nil {
@@ -755,15 +728,34 @@ func (r *GitRepositoryReconciler) gitCheckout(ctx context.Context,
755
728
Err : fmt .Errorf ("failed to configure checkout strategy for Git implementation '%s': %w" , obj .Spec .GitImplementation , err ),
756
729
Reason : sourcev1 .GitOperationFailedReason ,
757
730
}
758
- conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , e .Err .Error ())
759
731
// Do not return err as recovery without changes is impossible.
760
732
return nil , e
761
733
}
762
734
735
+ // managed GIT transport only affects the libgit2 implementation
736
+ if managed .Enabled () && obj .Spec .GitImplementation == sourcev1 .LibGit2Implementation {
737
+ // We set the TransportOptionsURL of this set of authentication options here by constructing
738
+ // a unique URL that won't clash in a multi tenant environment. This unique URL is used by
739
+ // libgit2 managed transports. This enables us to bypass the inbuilt credentials callback in
740
+ // libgit2, which is inflexible and unstable.
741
+ if strings .HasPrefix (obj .Spec .URL , "http" ) {
742
+ authOpts .TransportOptionsURL = fmt .Sprintf ("http://%s/%s/%d" , obj .Name , obj .UID , obj .Generation )
743
+ } else if strings .HasPrefix (obj .Spec .URL , "ssh" ) {
744
+ authOpts .TransportOptionsURL = fmt .Sprintf ("ssh://%s/%s/%d" , obj .Name , obj .UID , obj .Generation )
745
+ } else {
746
+ e := & serror.Stalling {
747
+ Err : fmt .Errorf ("git repository URL has invalid transport type: '%s'" , obj .Spec .URL ),
748
+ Reason : sourcev1 .URLInvalidReason ,
749
+ }
750
+ return nil , e
751
+ }
752
+ }
753
+
763
754
// Checkout HEAD of reference in object
764
755
gitCtx , cancel := context .WithTimeout (ctx , obj .Spec .Timeout .Duration )
765
756
defer cancel ()
766
- commit , err := checkoutStrategy .Checkout (gitCtx , dir , repoURL , authOpts )
757
+
758
+ commit , err := checkoutStrategy .Checkout (gitCtx , dir , obj .Spec .URL , authOpts )
767
759
if err != nil {
768
760
e := serror .NewGeneric (
769
761
fmt .Errorf ("failed to checkout and determine revision: %w" , err ),
0 commit comments