Skip to content

Commit

Permalink
GitRepo: Remove provider default value from API
Browse files Browse the repository at this point in the history
For backwards compatibility, remove the default value for GitRepository
provider. An empty provider value will still be considered as the
default provider.

Signed-off-by: Sunny <github@darkowlzz.space>
(cherry picked from commit db42b07)
  • Loading branch information
darkowlzz authored and github-actions[bot] committed Sep 26, 2024
1 parent e6e2b15 commit 0e4f558
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
9 changes: 8 additions & 1 deletion api/v1/gitrepository_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'.
Expand Down
14 changes: 6 additions & 8 deletions internal/controller/gitrepository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
}
}

Expand Down

0 comments on commit 0e4f558

Please sign in to comment.