Skip to content

Commit

Permalink
Removes duplicated error handling
Browse files Browse the repository at this point in the history
Signed-off-by: Paulo Gomes <[email protected]>
  • Loading branch information
Paulo Gomes committed Oct 31, 2022
1 parent 08e3069 commit 95a6360
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions controllers/gitrepository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ func (r *GitRepositoryReconciler) reconcileSource(ctx context.Context,
conditions.Delete(obj, sourcev1.SourceVerifiedCondition)
}

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

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

// Configure authentication strategy to access the source
authOpts, err := git.NewAuthOptions(*u, data)

authOpts, err := git.NewAuthOptions(*u, authData)
if err != nil {
e := serror.NewGeneric(
fmt.Errorf("failed to configure authentication options: %w", err),
Expand All @@ -483,15 +482,6 @@ func (r *GitRepositoryReconciler) reconcileSource(ctx context.Context,
conditions.MarkTrue(obj, sourcev1.FetchFailedCondition, e.Reason, e.Err.Error())
return sreconcile.ResultEmpty, e
}
if err != nil {
e := serror.NewGeneric(
fmt.Errorf("failed to configure auth strategy for Git implementation '%s': %w", obj.Spec.GitImplementation, err),
sourcev1.AuthenticationFailedReason,
)
conditions.MarkTrue(obj, sourcev1.FetchFailedCondition, e.Reason, e.Err.Error())
// Return error as the contents of the secret may change
return sreconcile.ResultEmpty, e
}

// Fetch the included artifact metadata.
artifacts, err := r.fetchIncludes(ctx, obj)
Expand Down

0 comments on commit 95a6360

Please sign in to comment.