Skip to content

Commit e87997c

Browse files
author
Paulo Gomes
committed
Use serror.NewStalling() and small PR fixes
This ensures that the event, notification and log are configured correctly. Signed-off-by: Paulo Gomes <[email protected]>
1 parent 6b04907 commit e87997c

File tree

2 files changed

+13
-27
lines changed

2 files changed

+13
-27
lines changed

controllers/gitrepository_controller.go

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ func (r *GitRepositoryReconciler) reconcileSource(ctx context.Context,
442442
conditions.Delete(obj, sourcev1.SourceVerifiedCondition)
443443
}
444444

445-
var data map[string][]byte
445+
var authData map[string][]byte
446446
if obj.Spec.SecretRef != nil {
447447
// Attempt to retrieve secret
448448
name := types.NamespacedName{
@@ -459,7 +459,7 @@ func (r *GitRepositoryReconciler) reconcileSource(ctx context.Context,
459459
// Return error as the world as observed may change
460460
return sreconcile.ResultEmpty, e
461461
}
462-
data = secret.Data
462+
authData = secret.Data
463463
}
464464

465465
u, err := url.Parse(obj.Spec.URL)
@@ -473,8 +473,7 @@ func (r *GitRepositoryReconciler) reconcileSource(ctx context.Context,
473473
}
474474

475475
// Configure authentication strategy to access the source
476-
authOpts, err := git.NewAuthOptions(*u, data)
477-
476+
authOpts, err := git.NewAuthOptions(*u, authData)
478477
if err != nil {
479478
e := serror.NewGeneric(
480479
fmt.Errorf("failed to configure authentication options: %w", err),
@@ -483,15 +482,6 @@ func (r *GitRepositoryReconciler) reconcileSource(ctx context.Context,
483482
conditions.MarkTrue(obj, sourcev1.FetchFailedCondition, e.Reason, e.Err.Error())
484483
return sreconcile.ResultEmpty, e
485484
}
486-
if err != nil {
487-
e := serror.NewGeneric(
488-
fmt.Errorf("failed to configure auth strategy for Git implementation '%s': %w", obj.Spec.GitImplementation, err),
489-
sourcev1.AuthenticationFailedReason,
490-
)
491-
conditions.MarkTrue(obj, sourcev1.FetchFailedCondition, e.Reason, e.Err.Error())
492-
// Return error as the contents of the secret may change
493-
return sreconcile.ResultEmpty, e
494-
}
495485

496486
// Fetch the included artifact metadata.
497487
artifacts, err := r.fetchIncludes(ctx, obj)
@@ -771,17 +761,17 @@ func (r *GitRepositoryReconciler) gitCheckout(ctx context.Context,
771761
switch obj.Spec.GitImplementation {
772762
case sourcev1.LibGit2Implementation:
773763
gitReader, err = libgit2.NewClient(dir, authOpts)
774-
case sourcev1.GoGitImplementation, "":
764+
case sourcev1.GoGitImplementation:
775765
gitReader, err = gogit.NewClient(dir, authOpts)
776766
default:
777767
err = fmt.Errorf("invalid Git implementation: %s", obj.Spec.GitImplementation)
778768
}
779769
if err != nil {
780770
// Do not return err as recovery without changes is impossible.
781-
e := &serror.Stalling{
782-
Err: fmt.Errorf("failed to create Git client for implementation '%s': %w", obj.Spec.GitImplementation, err),
783-
Reason: sourcev1.GitOperationFailedReason,
784-
}
771+
e := serror.NewStalling(
772+
fmt.Errorf("failed to create Git client for implementation '%s': %w", obj.Spec.GitImplementation, err),
773+
sourcev1.GitOperationFailedReason,
774+
)
785775
conditions.MarkTrue(obj, sourcev1.FetchFailedCondition, e.Reason, e.Err.Error())
786776
return nil, e
787777
}

go.mod

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,15 @@ require (
2727
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.1.0
2828
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.4.1
2929
github.com/Masterminds/semver/v3 v3.1.1
30-
// github.com/ProtonMail/go-crypto is a fork of golang.org/x/crypto
31-
// maintained by the ProtonMail team to continue to support the openpgp
32-
// module, after the Go team decided to no longer maintain it.
33-
// When in doubt (and not using openpgp), use /x/crypto.
34-
github.com/ProtonMail/go-crypto v0.0.0-20220930113650-c6815a8c17ad // indirect
3530
github.com/cyphar/filepath-securejoin v0.2.3
3631
github.com/distribution/distribution/v3 v3.0.0-20221019080424-fb2188868d77
3732
github.com/docker/cli v20.10.20+incompatible
3833
github.com/docker/go-units v0.5.0
39-
github.com/elazarl/goproxy v0.0.0-20221015165544-a0805db90819 // indirect
40-
github.com/fluxcd/gitkit v0.6.0 // indirect
4134
github.com/fluxcd/pkg/apis/meta v0.17.0
4235
github.com/fluxcd/pkg/git v0.6.1
4336
github.com/fluxcd/pkg/git/gogit v0.0.0-20221026111216-11a3405b2580
4437
github.com/fluxcd/pkg/git/libgit2 v0.0.0-20221026111216-11a3405b2580
4538
github.com/fluxcd/pkg/gittestserver v0.7.0
46-
github.com/fluxcd/pkg/gitutil v0.2.0 // indirect
4739
github.com/fluxcd/pkg/helmtestserver v0.9.0
4840
github.com/fluxcd/pkg/lockedfile v0.1.0
4941
github.com/fluxcd/pkg/masktoken v0.2.0
@@ -72,7 +64,6 @@ require (
7264
github.com/sirupsen/logrus v1.9.0
7365
github.com/spf13/pflag v1.0.5
7466
golang.org/x/crypto v0.1.0
75-
golang.org/x/net v0.1.0 // indirect
7667
golang.org/x/sync v0.1.0
7768
google.golang.org/api v0.100.0
7869
gotest.tools v2.2.0+incompatible
@@ -110,6 +101,7 @@ require (
110101
github.com/Masterminds/sprig/v3 v3.2.2 // indirect
111102
github.com/Masterminds/squirrel v1.5.3 // indirect
112103
github.com/Microsoft/go-winio v0.6.0 // indirect
104+
github.com/ProtonMail/go-crypto v0.0.0-20220930113650-c6815a8c17ad // indirect
113105
github.com/Shopify/logrus-bugsnag v0.0.0-20171204204709-577dee27f20d // indirect
114106
github.com/ThalesIgnite/crypto11 v1.2.5 // indirect
115107
github.com/acomagu/bufpipe v1.0.3 // indirect
@@ -175,6 +167,7 @@ require (
175167
github.com/docker/go-metrics v0.0.1 // indirect
176168
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 // indirect
177169
github.com/dustin/go-humanize v1.0.0 // indirect
170+
github.com/elazarl/goproxy v0.0.0-20221015165544-a0805db90819 // indirect
178171
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
179172
github.com/emirpasic/gods v1.18.1 // indirect
180173
github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1 // indirect
@@ -184,7 +177,9 @@ require (
184177
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
185178
github.com/fatih/color v1.13.0 // indirect
186179
github.com/felixge/httpsnoop v1.0.3 // indirect
180+
github.com/fluxcd/gitkit v0.6.0 // indirect
187181
github.com/fluxcd/pkg/apis/acl v0.1.0 // indirect
182+
github.com/fluxcd/pkg/gitutil v0.2.0 // indirect
188183
github.com/fluxcd/pkg/http/transport v0.1.0 // indirect
189184
github.com/fsnotify/fsnotify v1.5.4 // indirect
190185
github.com/fullstorydev/grpcurl v1.8.7 // indirect
@@ -377,6 +372,7 @@ require (
377372
go.uber.org/zap v1.23.0 // indirect
378373
golang.org/x/exp v0.0.0-20220823124025-807a23277127 // indirect
379374
golang.org/x/mod v0.6.0 // indirect
375+
golang.org/x/net v0.1.0 // indirect
380376
golang.org/x/oauth2 v0.1.0 // indirect
381377
golang.org/x/sys v0.1.0 // indirect
382378
golang.org/x/term v0.1.0 // indirect

0 commit comments

Comments
 (0)