Skip to content

Commit 7c6a117

Browse files
aryan9600Paulo Gomes
authored andcommitted
use gitrepo implementation for git ops
Signed-off-by: Sanskar Jaiswal <[email protected]>
1 parent 26bd330 commit 7c6a117

File tree

4 files changed

+284
-247
lines changed

4 files changed

+284
-247
lines changed

controllers/imageupdateautomation_controller.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ import (
5050
apiacl "github.com/fluxcd/pkg/apis/acl"
5151
"github.com/fluxcd/pkg/apis/meta"
5252
"github.com/fluxcd/pkg/git"
53-
libgit2pkg "github.com/fluxcd/pkg/git/libgit2"
53+
"github.com/fluxcd/pkg/git/gogit"
54+
"github.com/fluxcd/pkg/git/libgit2"
5455
"github.com/fluxcd/pkg/runtime/acl"
5556
helper "github.com/fluxcd/pkg/runtime/controller"
5657
"github.com/fluxcd/pkg/runtime/events"
@@ -255,11 +256,19 @@ func (r *ImageUpdateAutomationReconciler) Reconcile(ctx context.Context, req ctr
255256
return failWithError(err)
256257
}
257258

258-
lgc, err := libgit2pkg.NewClient(tmp, authOpts)
259+
var gitClient git.RepositoryClient
260+
switch origin.Spec.GitImplementation {
261+
case sourcev1.LibGit2Implementation:
262+
gitClient, err = libgit2.NewClient(tmp, authOpts)
263+
case sourcev1.GoGitImplementation, "":
264+
gitClient, err = gogit.NewClient(tmp, authOpts)
265+
default:
266+
err = fmt.Errorf("failed to create git client; referred GitRepository has invalid implementation: %s", origin.Spec.GitImplementation)
267+
}
259268
if err != nil {
260269
return failWithError(err)
261270
}
262-
defer lgc.Close()
271+
defer gitClient.Close()
263272

264273
opts := git.CloneOptions{}
265274
if ref != nil {
@@ -272,7 +281,7 @@ func (r *ImageUpdateAutomationReconciler) Reconcile(ctx context.Context, req ctr
272281
// Use the git operations timeout for the repo.
273282
cloneCtx, cancel := context.WithTimeout(ctx, origin.Spec.Timeout.Duration)
274283
defer cancel()
275-
if _, err := lgc.Clone(cloneCtx, origin.Spec.URL, opts); err != nil {
284+
if _, err := gitClient.Clone(cloneCtx, origin.Spec.URL, opts); err != nil {
276285
return failWithError(err)
277286
}
278287

@@ -282,7 +291,7 @@ func (r *ImageUpdateAutomationReconciler) Reconcile(ctx context.Context, req ctr
282291
// Use the git operations timeout for the repo.
283292
fetchCtx, cancel := context.WithTimeout(ctx, origin.Spec.Timeout.Duration)
284293
defer cancel()
285-
if err := lgc.SwitchBranch(fetchCtx, pushBranch); err != nil {
294+
if err := gitClient.SwitchBranch(fetchCtx, pushBranch); err != nil {
286295
return failWithError(err)
287296
}
288297
}
@@ -347,7 +356,7 @@ func (r *ImageUpdateAutomationReconciler) Reconcile(ctx context.Context, req ctr
347356
// The status message depends on what happens next. Since there's
348357
// more than one way to succeed, there's some if..else below, and
349358
// early returns only on failure.
350-
if rev, err := lgc.Commit(
359+
if rev, err := gitClient.Commit(
351360
git.Commit{
352361
Author: git.Signature{
353362
Name: gitSpec.Commit.Author.Name,
@@ -372,7 +381,7 @@ func (r *ImageUpdateAutomationReconciler) Reconcile(ctx context.Context, req ctr
372381
// Use the git operations timeout for the repo.
373382
pushCtx, cancel := context.WithTimeout(ctx, origin.Spec.Timeout.Duration)
374383
defer cancel()
375-
if err := lgc.Push(pushCtx); err != nil {
384+
if err := gitClient.Push(pushCtx); err != nil {
376385
return failWithError(err)
377386
}
378387

0 commit comments

Comments
 (0)