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

[Stash] Implement gitprovider interfaces #114

Merged
merged 2 commits into from
Oct 25, 2021

Conversation

souleb
Copy link
Member

@souleb souleb commented Oct 11, 2021

#102

Signed-off-by: Soule BA [email protected]

Description

Adds full implementation of gitprovider interfaces.

With this PR comes:

  • user and org repositories creation
  • support for deploy keys, commits, branches and Pull requests
  • reconciling of repositories, deploy keys and team access
  • support for paging with a default maxPages of 6 pages and 25 entries per page. Can be configured with en Env var

** the git client clone on disk. In the future shall be in-memory.

Test results

https://github.com/souleb/go-git-providers/runs/3964397313?check_suite_focus=true

@souleb souleb mentioned this pull request Oct 11, 2021
13 tasks
@souleb souleb force-pushed the go-stash-provider-implem branch from a267817 to 7c83923 Compare October 11, 2021 14:44
Interfaces.

Get and list is implemented for  orgs(stash projects) and groups(stash teams) and users

The missing implementations return "not implemented" for the moment as
agreed.

Signed-off-by: Soule BA <[email protected]>
@souleb souleb force-pushed the go-stash-provider-implem branch 2 times, most recently from 23a0397 to 8b2a757 Compare October 11, 2021 16:11
Copy link
Contributor

@bigkevmcd bigkevmcd left a comment

Choose a reason for hiding this comment

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

Nothing too big in here, there are inherent scaling issues that concern me tho' but they're broad problems that need to be tackled.

gitprovider/repositoryref.go Outdated Show resolved Hide resolved
gitprovider/repositoryref.go Outdated Show resolved Hide resolved
gitprovider/repositoryref.go Outdated Show resolved Hide resolved
stash/auth.go Outdated Show resolved Hide resolved
stash/auth.go Outdated Show resolved Hide resolved
stash/auth.go Outdated Show resolved Hide resolved
stash/client_organization_teams.go Outdated Show resolved Hide resolved
teams := make([]gitprovider.Team, len(apiObjs))
for i, apiObj := range apiObjs {
// Get detailed information about individual teams (including members).
// Slug is validated to be non-nil in ListGroupMembers.
Copy link
Contributor

Choose a reason for hiding this comment

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

I have to be honest, this is very expensive to do...

You are making n+1 queries to get the list of teams, without any pagination or limits.

Copy link
Member Author

@souleb souleb Oct 16, 2021

Choose a reason for hiding this comment

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

N+1 call yes, but the call to get teams is paginated. Then for each team the call to get permissions also is paginated. Page numbers is set to c.maxPages and is 6 by default. The default limit is set to 25 entries per page.

Copy link
Member Author

Choose a reason for hiding this comment

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

As discussed, removed maxPages. I kept a limit of 25 entries per page

stash/client_organizations.go Show resolved Hide resolved
stash/auth_test.go Outdated Show resolved Hide resolved
@souleb souleb force-pushed the go-stash-provider-implem branch 3 times, most recently from b85e279 to 5294401 Compare October 20, 2021 13:55
stash/git.go Outdated Show resolved Hide resolved
stash/git_test.go Outdated Show resolved Hide resolved
return &list.Paging, nil
})
if err != nil {
return nil, err
Copy link
Contributor

Choose a reason for hiding this comment

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

What does the error look like here if this fails?

Copy link
Member Author

Choose a reason for hiding this comment

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

It returns the first error encountered, be it request error or unmarshalling. I probably should use the multierror to get all pages errors.

stash/integration_organization_test.go Outdated Show resolved Hide resolved
stash/integration_repositories_user_test.go Outdated Show resolved Hide resolved
stash/integration_suite_test.go Outdated Show resolved Hide resolved
stash/projects.go Outdated Show resolved Hide resolved
stash/stash.go Outdated Show resolved Hide resolved
stash/stash.go Outdated Show resolved Hide resolved
stash/resource_deploykey.go Outdated Show resolved Hide resolved
@souleb souleb force-pushed the go-stash-provider-implem branch 4 times, most recently from 3d9f65b to 84cfc44 Compare October 21, 2021 13:20
Add client to create keys, commit, create branches and pull
requests for the repositories.

Add capabilities for reconciling repositories, deploy keys and teams access.

Signed-off-by: Soule BA <[email protected]>
@souleb souleb force-pushed the go-stash-provider-implem branch from 84cfc44 to 3a0139f Compare October 21, 2021 13:23
Copy link
Contributor

@bigkevmcd bigkevmcd left a comment

Choose a reason for hiding this comment

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

Looks ok to me, I am worried about cost of fetching some of the data but this is a systemic failing and not specific to this PR.

@@ -187,3 +188,23 @@ func (s *GroupsService) ListGroupMembers(ctx context.Context, groupName string,

return m, nil
}

// AllGroupMembers retrieves all group members.
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a blocker for this branch, but all the functions that are very costly like this should probably have a comment warning of this?

// Create a new repo
repo, err := client.UserRepositories().Create(ctx, repoRef, gitprovider.RepositoryInfo{
Description: gitprovider.StringVar(defaultDescription),
// Default visibility is private, no need to set this at least now
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confused by this comment, it says there's no need to set it, but it appears to set it?

Copy link
Contributor

@bigkevmcd bigkevmcd left a comment

Choose a reason for hiding this comment

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

I'm approving this for now, but I think we need to reconsider how go-git-providers gets data like this, there are too many "load all the pages of Object, then load all Objects individually" without controls in place to limit the requests, or warnings that this is extremely expensive.

Copy link
Member

@stefanprodan stefanprodan left a comment

Choose a reason for hiding this comment

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

LGTM

Thanks @souleb for all the hard work and thanks @bigkevmcd for the review 🏅

PS. Currently we don't use the List functions in flux bootstrap, we act on a single repo and deploy key. Going to merge this so we can move forward with the Stash implementation, but we should create an issue and address the pagination problem for all providers.

@stefanprodan stefanprodan merged commit 544681a into fluxcd:main Oct 25, 2021
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.

3 participants