@@ -62,7 +62,6 @@ import (
6262 "github.com/fluxcd/pkg/runtime/predicates"
6363 sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
6464 "github.com/fluxcd/source-controller/pkg/git"
65- gitlibgit2 "github.com/fluxcd/source-controller/pkg/git/libgit2"
6665 "github.com/fluxcd/source-controller/pkg/git/libgit2/managed"
6766 gitstrat "github.com/fluxcd/source-controller/pkg/git/strategy"
6867
@@ -270,21 +269,18 @@ func (r *ImageUpdateAutomationReconciler) Reconcile(ctx context.Context, req ctr
270269 return failWithError (err )
271270 }
272271
273- // managed GIT transport only affects the libgit2 implementation
274- if managed .Enabled () {
275- // We set the TransportOptionsURL of this set of authentication options here by constructing
276- // a unique URL that won't clash in a multi tenant environment. This unique URL is used by
277- // libgit2 managed transports. This enables us to bypass the inbuilt credentials callback in
278- // libgit2, which is inflexible and unstable.
279- // NB: The Transport Options URL must be unique, therefore it must use the object under
280- // reconciliation details, instead of the repository it depends on.
281- if strings .HasPrefix (origin .Spec .URL , "http" ) {
282- access .auth .TransportOptionsURL = fmt .Sprintf ("http://%s/%s/%d" , auto .Name , auto .UID , auto .Generation )
283- } else if strings .HasPrefix (origin .Spec .URL , "ssh" ) {
284- access .auth .TransportOptionsURL = fmt .Sprintf ("ssh://%s/%s/%d" , auto .Name , auto .UID , auto .Generation )
285- } else {
286- return failWithError (fmt .Errorf ("git repository URL '%s' has invalid transport type, supported types are: http, https, ssh" , origin .Spec .URL ))
287- }
272+ // We set the TransportOptionsURL of this set of authentication options here by constructing
273+ // a unique URL that won't clash in a multi tenant environment. This unique URL is used by
274+ // libgit2 managed transports. This enables us to bypass the inbuilt credentials callback in
275+ // libgit2, which is inflexible and unstable.
276+ // NB: The Transport Options URL must be unique, therefore it must use the object under
277+ // reconciliation details, instead of the repository it depends on.
278+ if strings .HasPrefix (origin .Spec .URL , "http" ) {
279+ access .auth .TransportOptionsURL = fmt .Sprintf ("http://%s/%s/%d" , auto .Name , auto .UID , auto .Generation )
280+ } else if strings .HasPrefix (origin .Spec .URL , "ssh" ) {
281+ access .auth .TransportOptionsURL = fmt .Sprintf ("ssh://%s/%s/%d" , auto .Name , auto .UID , auto .Generation )
282+ } else {
283+ return failWithError (fmt .Errorf ("git repository URL '%s' has invalid transport type, supported types are: http, https, ssh" , origin .Spec .URL ))
288284 }
289285
290286 // Use the git operations timeout for the repo.
@@ -296,19 +292,17 @@ func (r *ImageUpdateAutomationReconciler) Reconcile(ctx context.Context, req ctr
296292 }
297293 defer repo .Free ()
298294
299- if managed .Enabled () {
300- // Checkout removes TransportOptions before returning, therefore this
301- // must happen after cloneInto.
302- // TODO(pjbgf): Git consolidation should improve the API workflow.
303- managed .AddTransportOptions (access .auth .TransportOptionsURL , managed.TransportOptions {
304- TargetURL : origin .Spec .URL ,
305- AuthOpts : access .auth ,
306- ProxyOptions : & libgit2.ProxyOptions {Type : libgit2 .ProxyTypeAuto },
307- Context : cloneCtx ,
308- })
295+ // Checkout removes TransportOptions before returning, therefore this
296+ // must happen after cloneInto.
297+ // TODO(pjbgf): Git consolidation should improve the API workflow.
298+ managed .AddTransportOptions (access .auth .TransportOptionsURL , managed.TransportOptions {
299+ TargetURL : origin .Spec .URL ,
300+ AuthOpts : access .auth ,
301+ ProxyOptions : & libgit2.ProxyOptions {Type : libgit2 .ProxyTypeAuto },
302+ Context : cloneCtx ,
303+ })
309304
310- defer managed .RemoveTransportOptions (access .auth .TransportOptionsURL )
311- }
305+ defer managed .RemoveTransportOptions (access .auth .TransportOptionsURL )
312306
313307 // When there's a push spec, the pushed-to branch is where commits
314308 // shall be made
@@ -554,10 +548,6 @@ func (r *ImageUpdateAutomationReconciler) getRepoAccess(ctx context.Context, rep
554548 return access , nil
555549}
556550
557- func (r repoAccess ) remoteCallbacks (ctx context.Context ) libgit2.RemoteCallbacks {
558- return gitlibgit2 .RemoteCallbacks (ctx , r .auth )
559- }
560-
561551// cloneInto clones the upstream repository at the `ref` given (which
562552// can be `nil`). It returns a `*libgit2.Repository` since that is used
563553// for committing changes.
@@ -763,12 +753,9 @@ func switchToBranch(repo *libgit2.Repository, ctx context.Context, branch string
763753 }
764754 defer origin .Free ()
765755
766- callbacks := access .remoteCallbacks (ctx )
767- if managed .Enabled () {
768- // Override callbacks with dummy ones as they are not needed within Managed Transport.
769- // However, not setting them may lead to git2go panicing.
770- callbacks = managed .RemoteCallbacks ()
771- }
756+ // Override callbacks with dummy ones as they are not needed within Managed Transport.
757+ // However, not setting them may lead to git2go panicing.
758+ callbacks := managed .RemoteCallbacks ()
772759
773760 // Force the fetching of the remote branch.
774761 err = origin .Fetch ([]string {branch }, & libgit2.FetchOptions {
@@ -866,12 +853,9 @@ func push(ctx context.Context, path, branch string, access repoAccess) error {
866853 }
867854 defer origin .Free ()
868855
869- callbacks := access .remoteCallbacks (ctx )
870- if managed .Enabled () {
871- // Override callbacks with dummy ones as they are not needed within Managed Transport.
872- // However, not setting them may lead to git2go panicing.
873- callbacks = managed .RemoteCallbacks ()
874- }
856+ // Override callbacks with dummy ones as they are not needed within Managed Transport.
857+ // However, not setting them may lead to git2go panicing.
858+ callbacks := managed .RemoteCallbacks ()
875859
876860 // calling repo.Push will succeed even if a reference update is
877861 // rejected; to detect this case, this callback is supplied.
0 commit comments