diff --git a/api/v1/gitrepository_types.go b/api/v1/gitrepository_types.go index bfe309871..2ed4df258 100644 --- a/api/v1/gitrepository_types.go +++ b/api/v1/gitrepository_types.go @@ -91,7 +91,6 @@ type GitRepositorySpec struct { // Provider used for authentication, can be 'azure', 'generic'. // When not specified, defaults to 'generic'. // +kubebuilder:validation:Enum=generic;azure - // +kubebuilder:default:=generic // +optional Provider string `json:"provider,omitempty"` @@ -303,6 +302,14 @@ func (in *GitRepository) GetArtifact() *Artifact { return in.Status.Artifact } +// GetProvider returns the Git authentication provider. +func (v *GitRepository) GetProvider() string { + if v.Spec.Provider == "" { + return GitProviderGeneric + } + return v.Spec.Provider +} + // GetMode returns the declared GitVerificationMode, or a ModeGitHEAD default. func (v *GitRepositoryVerification) GetMode() GitVerificationMode { if v.Mode.Valid() { diff --git a/config/crd/bases/source.toolkit.fluxcd.io_gitrepositories.yaml b/config/crd/bases/source.toolkit.fluxcd.io_gitrepositories.yaml index e7a48ee25..9d01fbd54 100644 --- a/config/crd/bases/source.toolkit.fluxcd.io_gitrepositories.yaml +++ b/config/crd/bases/source.toolkit.fluxcd.io_gitrepositories.yaml @@ -104,7 +104,6 @@ spec: pattern: ^([0-9]+(\.[0-9]+)?(ms|s|m|h))+$ type: string provider: - default: generic description: |- Provider used for authentication, can be 'azure', 'generic'. When not specified, defaults to 'generic'. diff --git a/internal/controller/gitrepository_controller.go b/internal/controller/gitrepository_controller.go index 39e43fa9d..9ecaf2866 100644 --- a/internal/controller/gitrepository_controller.go +++ b/internal/controller/gitrepository_controller.go @@ -650,14 +650,12 @@ func (r *GitRepositoryReconciler) getAuthOpts(ctx context.Context, obj *sourcev1 } // Configure provider authentication if specified in spec - if obj.Spec.Provider != "" && obj.Spec.Provider != sourcev1.GitProviderGeneric { - if obj.Spec.Provider == sourcev1.GitProviderAzure { - authOpts.ProviderOpts = &git.ProviderOptions{ - Name: obj.Spec.Provider, - AzureOpts: []azure.OptFunc{ - azure.WithAzureDevOpsScope(), - }, - } + if obj.GetProvider() == sourcev1.GitProviderAzure { + authOpts.ProviderOpts = &git.ProviderOptions{ + Name: obj.GetProvider(), + AzureOpts: []azure.OptFunc{ + azure.WithAzureDevOpsScope(), + }, } }