Skip to content

Commit

Permalink
Merge pull request #1627 from fluxcd/backport-1626-to-release/v1.4.x
Browse files Browse the repository at this point in the history
[release/v1.4.x] GitRepo: Remove provider default value from API
  • Loading branch information
darkowlzz authored Sep 26, 2024
2 parents e6e2b15 + 0e4f558 commit a485ed4
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 a485ed4

Please sign in to comment.