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: new repo resolver logic to fetch info from a gcbrepov2 #9283

Merged

Conversation

renzodavid9
Copy link
Contributor

@renzodavid9 renzodavid9 commented Jan 29, 2024

Related: #9236

Description

  • New logic to fetch the information related with a given Cloud Build repository v2
  • Includes new cloud.google.com/go/cloudbuild library to manage connection with GCB repos v2

Follow-up Work (remove if N/A)

  • Update the Skaffold schema to add the new fields to map a GCB Repository V2 dependency
  • Update the config parser to retrieve the repo + clone URI from gcbrepov2.GetRepoInfo when a GCB Repository V2 is configured in the skaffold.yaml file
  • We'll be using the logic in https://github.com/GoogleContainerTools/skaffold/blob/main/pkg/skaffold/git/gitutil.go#L92 to clone the repository once we have the proper oauth URI from the gcbrepov2.GetRepoInfo function; we'll need to update the parameters to receive a new type of object that supports both, the repo + clone repo URI

Copy link

codecov bot commented Jan 29, 2024

Codecov Report

Attention: 295 lines in your changes are missing coverage. Please review.

Comparison is base (290280e) 70.48% compared to head (bab5cfb) 63.59%.
Report is 1106 commits behind head on main.

Files Patch % Lines
cmd/skaffold/app/cmd/exec.go 16.32% 40 Missing and 1 partial ⚠️
cmd/skaffold/app/cmd/filter.go 47.27% 22 Missing and 7 partials ⚠️
cmd/skaffold/app/cmd/lsp.go 28.12% 23 Missing ⚠️
cmd/skaffold/app/cmd/verify.go 23.33% 23 Missing ⚠️
cmd/skaffold/app/cmd/fix.go 51.16% 17 Missing and 4 partials ⚠️
cmd/skaffold/app/cmd/inspect_job_manifest_paths.go 60.00% 15 Missing and 1 partial ⚠️
cmd/skaffold/app/cmd/inspect_namespaces.go 50.00% 13 Missing and 1 partial ⚠️
...md/skaffold/app/cmd/inspect_config_dependencies.go 45.83% 12 Missing and 1 partial ⚠️
cmd/skaffold/app/cmd/lint.go 42.85% 12 Missing ⚠️
cmd/skaffold/app/cmd/inspect_build_env.go 60.71% 11 Missing ⚠️
... and 21 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9283      +/-   ##
==========================================
- Coverage   70.48%   63.59%   -6.90%     
==========================================
  Files         515      635     +120     
  Lines       23150    32773    +9623     
==========================================
+ Hits        16317    20841    +4524     
- Misses       5776    10328    +4552     
- Partials     1057     1604     +547     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@renzodavid9 renzodavid9 marked this pull request as ready for review January 29, 2024 19:44

var RepositoryManagerClient = repositoryManagerClient

func GetRepoInfo(ctx context.Context, gcpProject, gcpRegion, gcpConnectionName, gcpRepoName string) (repoURI string, readAccessToken string, err error) {
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 finding the current design of this function a bit difficult to follow. For a feature requiring multiple PRs, a top-down approach might make it easier to visualize how everything fits together. Though bottom-up approaches ensure solid unit tests, top-down can be more conducive to getting everyone on the same page – but I understand this preference can be subjective.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, it makes sense for the understanding of the full picture. I added a few more comments in the description of this PR aiming to clarify the next steps + full idea here. If you think is fine, we can keep this PR as it is, and we can use the top-down approach for future feature developments so we can express the full intention in a single PR, what do you think? Thanks 😄!

gcpConnection string
gcpRepo string
expectedGitRepo string
expectedToken string
Copy link
Contributor

Choose a reason for hiding this comment

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

no non-zero values for test

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 changed the structure of the unit tests, also taking into account that now this package has the logic to build the oauth2 format. Let me know how it looks. Thanks!


var RepositoryManagerClient = repositoryManagerClient

func GetRepoInfo(ctx context.Context, gcpProject, gcpRegion, gcpConnectionName, gcpRepoName string) (repoURI string, readAccessToken string, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we use a struct for (repoURI string, readAccessToken string) , or we can also construct the uri with token here

https://oauth2:<token>@<repo>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it! I changed it to return a struct as you suggested. The struct contains two fields, the CloneRepoURI with the oauth2 format, and the URI without the token. The reason to return both is to use the CloneRepoURI to execute all the needed git commands (clone, fetch, etc), and the URI for the errors we print so we don't show the token in the execution logs. The idea is to re use the logic that we already have in pkg/skaffold/git/gitutil.go to trigger the repo download/sync. Let me know what do you think.

@renzodavid9 renzodavid9 merged commit db98603 into GoogleContainerTools:main Feb 2, 2024
14 checks passed
@renzodavid9 renzodavid9 deleted the issue-9236-gcbrepov2-logic branch February 2, 2024 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants