Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Azure DevOps SCM Provider Generator; add branchNormalized to SCM Generator template fields. #9283

Merged
merged 11 commits into from
Jun 15, 2022

Conversation

brinchm
Copy link
Contributor

@brinchm brinchm commented May 3, 2022

Adds Azure DevOps SCM provider generator. For organizations that use Azure DevOps as their SCM, this will enable ApplicationSets to deploy applications based on repos and branches while in the development phase.

The pull request also contains an enhancement to SCMProviderGenerator.GenerateParams: branchNormalized. This aids in generating applications with unique names:

template:
    metadata: 
      name: "{{repository}}-{{branchNormalized}}{{sha}}"

Closes #9280
Signed-off-by: brinchm christer.brinchmann@gmail.com

Note on DCO:

If the DCO action in the integration test fails, one or more of your commits are not signed off. Please click on the Details link next to the DCO action for instructions on how to resolve this.

Checklist:

  • Either (a) I've created an enhancement proposal and discussed it with the community, (b) this is a bug fix, or (c) this does not need to be in the release notes.
  • The title of the PR states what changed and the related issues number (used for the release note).
  • I've included "Closes [ISSUE #]" or "Fixes [ISSUE #]" in the description to automatically close the associated issue.
  • I've updated both the CLI and UI to expose my feature, or I plan to submit a second PR with them.
  • Does this PR require documentation updates?
  • I've updated documentation as required by this PR.
  • Optional. My organization is added to USERS.md.
  • I have signed off all my commits as required by DCO
  • I have written unit and/or e2e tests for my change. PRs without these are unlikely to be merged.
  • My build is green (troubleshooting builds).

brinchm added 4 commits May 3, 2022 13:00
Signed-off-by: Christer Brinchmann <christer.brinchmann@gmail.com>
Signed-off-by: Christer Brinchmann <christer.brinchmann@gmail.com>
Signed-off-by: Christer Brinchmann <christer.brinchmann@gmail.com>
Signed-off-by: Christer Brinchmann <christer.brinchmann@gmail.com>
@codecov
Copy link

codecov bot commented May 3, 2022

Codecov Report

Merging #9283 (5a407bf) into master (a66046e) will increase coverage by 0.08%.
The diff coverage is 68.96%.

@@            Coverage Diff             @@
##           master    #9283      +/-   ##
==========================================
+ Coverage   45.76%   45.85%   +0.08%     
==========================================
  Files         225      226       +1     
  Lines       26565    26675     +110     
==========================================
+ Hits        12157    12231      +74     
- Misses      12751    12783      +32     
- Partials     1657     1661       +4     
Impacted Files Coverage Δ
...is/applicationset/v1alpha1/applicationset_types.go 34.69% <ø> (ø)
applicationset/generators/scm_provider.go 37.64% <50.00%> (-2.62%) ⬇️
...plicationset/services/scm_provider/azure_devops.go 71.56% <71.56%> (ø)
util/settings/settings.go 48.16% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a66046e...5a407bf. Read the comment docs.

@crenshaw-dev crenshaw-dev self-requested a review May 3, 2022 17:41
@crenshaw-dev
Copy link
Member

Thanks for the PR @brinchm! Will review ASAP.

hasPath, err := provider.RepoHasPath(ctx, repo, path)

if testCase.returnError {
assert.Error(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious! why we have this as a check? both the scenario error or noerror as passing test case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried covering the cases where azure devops returns an error signaling that the requested path doesn't exist (which is fine; maybe the path isn't there in the specified branch, so the return is false, nil), and also where azure devops returns other errors. In that latter case, I expect RepoHasPath to actually return an error.

But if the intent of the test cases is not clear I can try rewriting the test cases or possibly doing a new "Azure Devops Failed" test.

Copy link
Contributor

@rishabh625 rishabh625 May 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably we should segregate it with two names, one positive and other negative

Copy link
Member

@crenshaw-dev crenshaw-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome! Most of the comments are style nits. There are a couple comments that are more impactful.

applicationset/services/scm_provider/azure_devops.go Outdated Show resolved Hide resolved
applicationset/services/scm_provider/azure_devops.go Outdated Show resolved Hide resolved
applicationset/services/scm_provider/azure_devops.go Outdated Show resolved Hide resolved
applicationset/services/scm_provider/azure_devops.go Outdated Show resolved Hide resolved
applicationset/services/scm_provider/azure_devops.go Outdated Show resolved Hide resolved
applicationset/services/scm_provider/azure_devops_test.go Outdated Show resolved Hide resolved
applicationset/services/scm_provider/azure_devops_test.go Outdated Show resolved Hide resolved
applicationset/services/scm_provider/azure_devops_test.go Outdated Show resolved Hide resolved
brinchm added 4 commits May 24, 2022 13:42
Signed-off-by: Christer Brinchmann <christer.brinchmann@gmail.com>
Signed-off-by: Christer Brinchmann <christer.brinchmann@gmail.com>
Signed-off-by: Christer Brinchmann <christer.brinchmann@gmail.com>
…getting default branch.

Signed-off-by: Christer Brinchmann <christer.brinchmann@gmail.com>
@brinchm brinchm requested a review from crenshaw-dev May 27, 2022 07:54
Copy link
Member

@crenshaw-dev crenshaw-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few more tiny nitpicks. @rishabh625 can you give this one a final look?

pkg/apis/applicationset/v1alpha1/applicationset_types.go Outdated Show resolved Hide resolved
pkg/apis/applicationset/v1alpha1/applicationset_types.go Outdated Show resolved Hide resolved
if err != nil {
if wrappedError, isWrappedError := err.(azuredevops.WrappedError); isWrappedError && wrappedError.TypeKey != nil {
if *wrappedError.TypeKey == AzureDevOpsErrorsTypeKeyValues.GitRepositoryNotFound {
return repos, nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this error should be bubbled up. Is this ignored because it applies to disabled repos? If it applies to more than than, should we log a warning?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GitRepository returned from the Azure DevOps Golang library doesn't include info indicating if a repo is disabled, but the REST API it calls, does.

When retrieving branches for a disabled repo, the WrappedError contains the GitRepositoryNotFoundException text. For this situation, I chose to ignore the error and just return an empty slice.

I'll need to give this some thought; The GetRepositories call is quite simple, so a GET could be issued directly to the REST API... Might work, but it seems like a suboptimal solution.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, reinventing the wheel there would stink. I'm okay merging as-is. I don't think this will catch transient errors and accidentally delete Apps or anything nefarious like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks :)
The feature branch has one conflict in go.mod and some 129 commits behind master. I'll do a merge and push asap.

brinchm added 3 commits June 10, 2022 14:00
Signed-off-by: Christer Brinchmann <christer.brinchmann@gmail.com>
Signed-off-by: Christer Brinchmann <christer.brinchmann@gmail.com>
Signed-off-by: Christer Brinchmann <christer.brinchmann@gmail.com>
Copy link
Member

@crenshaw-dev crenshaw-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for seeing this through!

@crenshaw-dev crenshaw-dev merged commit 56eb095 into argoproj:master Jun 15, 2022
@brinchm
Copy link
Contributor Author

brinchm commented Jun 15, 2022

Thank you, likewise! Happy to contribute :)

@brinchm brinchm deleted the feat/scmprovider-azuredevops branch June 15, 2022 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SCM Provider Generator: Add Azure DevOps provider
3 participants