Skip to content

Commit 1ed8459

Browse files
committed
gitrepo: Use new reason for provider misconfig
Introduce InvalidProviderConfigurationReason for Git provider github related misconfiguration. Add github provider related tests to check the status conditions reason. Rearrange and modify a test case for getAuthOpts() for provider test where a referred secret doesn't exist. This scenario is not specific to any provider. Signed-off-by: Sunny <[email protected]>
1 parent 9556a63 commit 1ed8459

File tree

3 files changed

+60
-13
lines changed

3 files changed

+60
-13
lines changed

Diff for: api/v1/condition_types.go

+4
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,8 @@ const (
111111

112112
// InvalidSTSConfigurationReason signals that the STS configurtion is invalid.
113113
InvalidSTSConfigurationReason string = "InvalidSTSConfiguration"
114+
115+
// InvalidProviderConfigurationReason signals that the provider
116+
// configuration is invalid.
117+
InvalidProviderConfigurationReason string = "InvalidProviderConfiguration"
114118
)

Diff for: internal/controller/gitrepository_controller.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ func (r *GitRepositoryReconciler) getAuthOpts(ctx context.Context, obj *sourcev1
667667
if obj.Spec.SecretRef == nil {
668668
e := serror.NewStalling(
669669
fmt.Errorf("secretRef with github app data must be specified when provider is set to github"),
670-
sourcev1.AuthenticationFailedReason,
670+
sourcev1.InvalidProviderConfigurationReason,
671671
)
672672
conditions.MarkTrue(obj, sourcev1.FetchFailedCondition, e.Reason, "%s", e)
673673
return nil, e
@@ -684,7 +684,7 @@ func (r *GitRepositoryReconciler) getAuthOpts(ctx context.Context, obj *sourcev1
684684
if appID := authData[github.AppIDKey]; len(appID) != 0 {
685685
e := serror.NewStalling(
686686
fmt.Errorf("secretRef '%s/%s' has github app data but provider is not set to github", obj.GetNamespace(), obj.Spec.SecretRef.Name),
687-
sourcev1.AuthenticationFailedReason,
687+
sourcev1.InvalidProviderConfigurationReason,
688688
)
689689
conditions.MarkTrue(obj, sourcev1.FetchFailedCondition, e.Reason, "%s", e)
690690
return nil, e

Diff for: internal/controller/gitrepository_controller_test.go

+54-11
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,50 @@ func TestGitRepositoryReconciler_reconcileSource_authStrategy(t *testing.T) {
572572
*conditions.UnknownCondition(meta.ReadyCondition, meta.ProgressingReason, "building artifact: new upstream revision 'master@sha1:<commit>'"),
573573
},
574574
},
575+
{
576+
// This test is only for verifying the failure state when using
577+
// provider auth. Protocol http is used for simplicity.
578+
name: "github provider without secret ref makes FetchFailed=True",
579+
protocol: "http",
580+
beforeFunc: func(obj *sourcev1.GitRepository) {
581+
obj.Spec.Provider = sourcev1.GitProviderGitHub
582+
conditions.MarkReconciling(obj, meta.ProgressingReason, "foo")
583+
conditions.MarkUnknown(obj, meta.ReadyCondition, meta.ProgressingReason, "foo")
584+
},
585+
want: sreconcile.ResultEmpty,
586+
wantErr: true,
587+
assertConditions: []metav1.Condition{
588+
*conditions.TrueCondition(sourcev1.FetchFailedCondition, sourcev1.InvalidProviderConfigurationReason, "secretRef with github app data must be specified when provider is set to github"),
589+
*conditions.TrueCondition(meta.ReconcilingCondition, meta.ProgressingReason, "foo"),
590+
*conditions.UnknownCondition(meta.ReadyCondition, meta.ProgressingReason, "foo"),
591+
},
592+
},
593+
{
594+
// This test is only for verifying the failure state when using
595+
// provider auth. Protocol http is used for simplicity.
596+
name: "empty provider with github app data in secret makes FetchFailed=True",
597+
protocol: "http",
598+
secret: &corev1.Secret{
599+
ObjectMeta: metav1.ObjectMeta{
600+
Name: "github-app-secret",
601+
},
602+
Data: map[string][]byte{
603+
github.AppIDKey: []byte("1111"),
604+
},
605+
},
606+
beforeFunc: func(obj *sourcev1.GitRepository) {
607+
obj.Spec.SecretRef = &meta.LocalObjectReference{Name: "github-app-secret"}
608+
conditions.MarkReconciling(obj, meta.ProgressingReason, "foo")
609+
conditions.MarkUnknown(obj, meta.ReadyCondition, meta.ProgressingReason, "foo")
610+
},
611+
want: sreconcile.ResultEmpty,
612+
wantErr: true,
613+
assertConditions: []metav1.Condition{
614+
*conditions.TrueCondition(sourcev1.FetchFailedCondition, sourcev1.InvalidProviderConfigurationReason, "secretRef '/github-app-secret' has github app data but provider is not set to github"),
615+
*conditions.TrueCondition(meta.ReconcilingCondition, meta.ProgressingReason, "foo"),
616+
*conditions.UnknownCondition(meta.ReadyCondition, meta.ProgressingReason, "foo"),
617+
},
618+
},
575619
}
576620

577621
for _, tt := range tests {
@@ -710,17 +754,6 @@ func TestGitRepositoryReconciler_getAuthOpts_provider(t *testing.T) {
710754
wantProviderOptsName: sourcev1.GitProviderGitHub,
711755
wantErr: errors.New("secretRef with github app data must be specified when provider is set to github"),
712756
},
713-
{
714-
name: "github provider with secret ref that does not exist",
715-
url: "https://github.com/org/repo.git",
716-
beforeFunc: func(obj *sourcev1.GitRepository) {
717-
obj.Spec.Provider = sourcev1.GitProviderGitHub
718-
obj.Spec.SecretRef = &meta.LocalObjectReference{
719-
Name: "githubAppSecret",
720-
}
721-
},
722-
wantErr: errors.New("failed to get secret '/githubAppSecret': secrets \"githubAppSecret\" not found"),
723-
},
724757
{
725758
name: "github provider with github app data in secret",
726759
url: "https://example.com/org/repo",
@@ -768,6 +801,16 @@ func TestGitRepositoryReconciler_getAuthOpts_provider(t *testing.T) {
768801
obj.Spec.Provider = sourcev1.GitProviderGeneric
769802
},
770803
},
804+
{
805+
name: "secret ref defined for non existing secret",
806+
url: "https://github.com/org/repo.git",
807+
beforeFunc: func(obj *sourcev1.GitRepository) {
808+
obj.Spec.SecretRef = &meta.LocalObjectReference{
809+
Name: "authSecret",
810+
}
811+
},
812+
wantErr: errors.New("failed to get secret '/authSecret': secrets \"authSecret\" not found"),
813+
},
771814
{
772815
url: "https://example.com/org/repo",
773816
name: "no provider",

0 commit comments

Comments
 (0)