Skip to content

feat: add multi-level-repo support to arbitrary repositories beyond just GCR and AR #6915

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

Merged
merged 1 commit into from
Dec 15, 2021
Merged

feat: add multi-level-repo support to arbitrary repositories beyond just GCR and AR #6915

merged 1 commit into from
Dec 15, 2021

Conversation

khrisrichardson
Copy link
Contributor

Fixes: #nnn
Related: Relevant tracking issues, for context
Merge before/after: N/A
Description
While the data model is a little clunky, as it would be preferable for multi-level support to be an attribute of a repository, given the one-to-one relationship of default repository to global or kube context, however, this adds configurable multi-level repository support per context.

The current behavior is that only GCR and AR support multi-level repositories, with an exemption granted if the name of the image being built has the same prefix as the default repository for the current context. Otherwise forward slashes and periods in image names are substituted with underscores.

GitLab container image registry is another repository that supports, and requires one to adhere to, multi-level image naming conventions. Permission is denied when one violates the organization/repository/nested/sub-directory naming conventions. The problem is that self-hosted registry domain names are not subject to string comparison like GCR and AR. It's easy enough to workaround this by prefixing the image name in skaffold.yaml with the default repository, but then the skaffold configuration is no longer portable. Hence this PR.

Note: The version of node was updated in the Dockerfile to support the latest version of postcss.

User facing changes (remove if N/A)
The user is now eligible to set for either the global or kube context multi-level support of the repository to which they intend to push images. The default behavior is equivalent to the behavior prior to this PR.

Follow-up Work (remove if N/A)
I was uncertain whether this feature should only be supported via config or also as a command line flag, and so there were no changes made to flags.go.

@khrisrichardson khrisrichardson requested a review from a team as a code owner November 28, 2021 16:15
@google-cla google-cla bot added the cla: yes label Nov 28, 2021
@khrisrichardson khrisrichardson changed the title update multi-level-repo business logic feat: update multi-level-repo business logic Nov 28, 2021
@khrisrichardson khrisrichardson changed the title feat: update multi-level-repo business logic feat: add multi-level-repo support to arbitrary repositories beyond just GCR and AR Dec 9, 2021
func registrySupportsMultiLevelRepos(repo string) bool {
return strings.Contains(repo, "gcr.io") || strings.Contains(repo, "-docker.pkg.dev")
func registrySupportsMultiLevelRepos(repo string, multiLevelRepo *bool) bool {
return (multiLevelRepo == nil && (strings.Contains(repo, "gcr.io") || strings.Contains(repo, "-docker.pkg.dev"))) || (multiLevelRepo != nil && *multiLevelRepo)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would keep this simpler,

  1. Always give preference to gcr.io and docker.pkg.dev by keeping returning true if strings.Contains(repo, "gcr.io") || strings.Contains(repo, "-docker.pkg.dev")
  2. Return *multiLevelRepo if not nil.

This way, users are protected against multiLevelRepo set to false by mistake for gcr.io and docker.pkg

In

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 hope this works for you. Thanks for the review @tejal29

Copy link
Contributor

Choose a reason for hiding this comment

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

The skaffold team is considering a revamp of skaffold config. One of the points discussed during this revamp was, does it makes sense to move default-repo and registry config to skaffold.yaml instead of global config.

Do you have any thots on this? Do you think moving this to skaffold.yaml will make the config more sharable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only speaking from my experience, but here are a few uses cases to consider.

  1. Developer for Open-Source Project

    While this isn't nearly as prevalent as I would like, I would find it especially useful if maintainers of open-source projects included a skaffold.yaml in place of a Makefile to actuate the building and deployment of their software.

    In this particular use case, it would make sense for there to be a default repository in the skaffold.yaml file to set a project wide standard. In all likelihood, however, this default repository wouldn't be writable by contributors. Were the notion of setting the default repository removed from the global config, some natural friction would surface as contributors of the project attempted to build with their private registries, which would require updating the skaffold.yaml to affect the results and remembering to undo the edit before committing any code changes.

    In this particular use case, the term "default" becomes overloaded since the default for the project conflicts with the default for the contributor.

    Providing a way to overlay the skaffold.yaml ala JSON or strategic merge patches similarly to kustomize without compromising the integrity of the project config could be one avenue to facilitate this use case. Again in all likelihood, a contributor could conceivably wish to set their private registry as the default across a multitude of projects, which is why the global config still has some resonance IMHO.

  2. Developer for Private Enterprise

    It's entirely possible that a developer for a private enterprise does all their development and testing against the production account using progressive rollout techniques. More power to them. A singular default repository works great in this scenario since there's only the production repository to contend with.

    The messy reality is that developers and operators may have to contend with a smattering of repositories, possibly across multiple cloud providers and/or cloud provider accounts. In this scenario a singular default repository becomes problematic, but so long as it remains possible to target a specific repository per Kubernetes context, then things should work out alright. The huge caveat there is the assumption that consumers of skaffold are necessarily deploying to Kubernetes, which is the target audience but still worthy of consideration.

  3. Operator/Consultant for Private Enterprise

    Not all software is created equal. I find myself using skaffold to build both long running daemons and CI tools (KRM functions). If images with a multitude of purposes are built from the same skaffold configuration, then it may be necessary to target a multitude of repositories from the same file. Although the requires directive provides a means to separate areas of concern into distinct skaffold configurations, IMHO that should be optional not required.

    For me personally, I like to write the CI tools so that they work in a variety of contexts (home, work, etc.) Having the flexibility to write to a multitude of repositories is key, and when building CI tools the notion of a Kubernetes context is less relevant. I happen to use the GitLab Kubernetes executor both at home and work, so maintaining the portability of images is of the utmost importance to me (thus this PR). I could imagine a consultant for a number of companies wishing to maintain this same level of portability.

    Baking the default repository into the skaffold.yaml may conflict with the desire of portability when there's no notion of Kubernetes context at hand to steer the logic.

As an aside, one thing I pondered when writing this PR was whether there shouldn't be a separate data structure in ~/.skaffold/config listing the variety of repositories and their attributes. In other words, I would ideally only need to identify that a particular repository has multi-level support once even though I may use that repository in a number of kubeContexts.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @khrisrichardson for all the thoughts. These are all valid points.
I think with the current config, the multi-level config goes well.

That said, setting expectations here.
This change won't be released for a long time. We might end up re-configuring the skaffold.yaml as part of our major config revamp and release this later in Jan or Feb.

Its upto you if you want us to commit this change on main now and then go through a refactor or,
Wait for us to design/start config revamp project and then make this feature addition.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let me know what you prefer.

Copy link
Contributor

@tejal29 tejal29 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 the change.

@tejal29 tejal29 added the kokoro:run runs the kokoro jobs on a PR label Dec 10, 2021
@kokoro-team kokoro-team removed the kokoro:run runs the kokoro jobs on a PR label Dec 10, 2021
@codecov
Copy link

codecov bot commented Dec 10, 2021

Codecov Report

Merging #6915 (497b945) into main (290280e) will decrease coverage by 1.66%.
The diff coverage is 56.96%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #6915      +/-   ##
==========================================
- Coverage   70.48%   68.82%   -1.67%     
==========================================
  Files         515      551      +36     
  Lines       23150    25319    +2169     
==========================================
+ Hits        16317    17425    +1108     
- Misses       5776     6717     +941     
- Partials     1057     1177     +120     
Impacted Files Coverage Δ
cmd/skaffold/app/cmd/deploy.go 52.00% <ø> (-1.85%) ⬇️
cmd/skaffold/app/cmd/dev.go 84.61% <0.00%> (ø)
cmd/skaffold/app/cmd/render.go 36.66% <0.00%> (-4.72%) ⬇️
cmd/skaffold/skaffold.go 0.00% <0.00%> (ø)
cmd/skaffold/app/cmd/inspect_tests.go 62.50% <14.28%> (-1.14%) ⬇️
cmd/skaffold/app/cmd/lsp.go 28.12% <28.12%> (ø)
cmd/skaffold/app/cmd/fix.go 68.85% <40.00%> (-7.62%) ⬇️
cmd/skaffold/app/cmd/lint.go 42.85% <42.85%> (ø)
cmd/skaffold/app/cmd/find_configs.go 48.88% <50.00%> (+0.24%) ⬆️
cmd/skaffold/app/skaffold.go 76.19% <70.00%> (-8.43%) ⬇️
... and 173 more

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 5933db1...497b945. Read the comment docs.

@khrisrichardson
Copy link
Contributor Author

FWIW I see similar failures when integration testing again the main branch. May I have some clarity on next steps?

@tejal29
Copy link
Contributor

tejal29 commented Dec 14, 2021

FWIW I see similar failures when integration testing again the main branch. May I have some clarity on next steps?

hmm. could be a flake.

@tejal29 tejal29 added the kokoro:force-run forces a kokoro re-run on a PR label Dec 15, 2021
@kokoro-team kokoro-team removed the kokoro:force-run forces a kokoro re-run on a PR label Dec 15, 2021
@tejal29 tejal29 added the kokoro:run runs the kokoro jobs on a PR label Dec 15, 2021
@tejal29 tejal29 merged commit 524a6b3 into GoogleContainerTools:main Dec 15, 2021
@khrisrichardson khrisrichardson deleted the multi-level-repo branch December 15, 2021 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes kokoro:run runs the kokoro jobs on a PR size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants