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

Implement defining remote git dependencies in the skaffold configuration. #5361

Merged

Conversation

gsquared94
Copy link
Collaborator

@gsquared94 gsquared94 commented Feb 5, 2021

Fixes: #5302

Description

Implements defining remote git repositories as skaffold config dependencies.

apiVersion: skaffold/v2beta12
kind: Config
requires:
- git:
    repo: https://github.com/GoogleContainerTools/skaffold
    path: examples/multi-config-microservices/leeroy-app
- git:
    repo: https://github.com/GoogleContainerTools/skaffold
    path: examples/multi-config-microservices/leeroy-web

The environment variable SKAFFOLD_REMOTE_CACHE_DIR or flag --remote-cache-dir specifies the download location for all remote repos. If undefined then it defaults to ~/.skaffold/repos.
The repo root directory name is a hash of the repo uri and the branch/ref.
Every execution of a remote module resets the cached repo to the referenced ref. The default ref is master. If master is not defined then it defaults to main.
The remote config gets treated like a local config after substituting the path with the actual path in the cache directory.

Look at the new remote-multi-config-microservices example

@gsquared94 gsquared94 requested a review from a team as a code owner February 5, 2021 20:25
@google-cla google-cla bot added the cla: yes label Feb 5, 2021
@codecov
Copy link

codecov bot commented Feb 5, 2021

Codecov Report

Merging #5361 (66d3564) into master (7b3d715) will decrease coverage by 0.03%.
The diff coverage is 63.39%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5361      +/-   ##
==========================================
- Coverage   71.58%   71.55%   -0.04%     
==========================================
  Files         394      395       +1     
  Lines       14305    14409     +104     
==========================================
+ Hits        10240    10310      +70     
- Misses       3309     3333      +24     
- Partials      756      766      +10     
Impacted Files Coverage Δ
cmd/skaffold/app/cmd/flags.go 87.50% <ø> (ø)
pkg/skaffold/config/options.go 100.00% <ø> (ø)
pkg/skaffold/schema/latest/config.go 58.82% <ø> (ø)
pkg/skaffold/git/gitutil.go 62.96% <62.96%> (ø)
cmd/skaffold/app/cmd/parse_config.go 69.81% <64.51%> (-3.69%) ⬇️
pkg/skaffold/tags/paths.go 71.66% <0.00%> (+3.33%) ⬆️
pkg/skaffold/util/tar.go 56.00% <0.00%> (+5.33%) ⬆️

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 7b3d715...66d3564. Read the comment docs.

Copy link
Contributor

@MarlonGamez MarlonGamez left a comment

Choose a reason for hiding this comment

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

Code and testing is looking really good. Have some comments on the example readme

Copy link
Contributor

@MarlonGamez MarlonGamez 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 for fixing the example :) I won't merge yet as I'm not sure if we want to get another pair of eyes on this since it's a larger PR

Copy link
Contributor

@nkubala nkubala left a comment

Choose a reason for hiding this comment

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

Every execution of a remote module resets the cached repo to the referenced ref

let's say I have one git module in my project. I run skaffold dev, and make a bunch of local changes to the cloned code which I'm seeing be redeployed to my cluster. I take a break by hitting ctrl+c, and then later start up a new skaffold dev session - all of the changes I made in my previous session are overwritten because my local cache got reset to the remote ref!

I think this should be configurable. it probably makes sense for this to be reset in some cases, but in others users might be experimenting with some changes to a dependency that they later want to commit, or at least persist. the default behavior here might even be to NOT reset the local cache to the remote ref.

cmd/skaffold/app/cmd/parse_config.go Outdated Show resolved Hide resolved
@gsquared94
Copy link
Collaborator Author

Every execution of a remote module resets the cached repo to the referenced ref

let's say I have one git module in my project. I run skaffold dev, and make a bunch of local changes to the cloned code which I'm seeing be redeployed to my cluster. I take a break by hitting ctrl+c, and then later start up a new skaffold dev session - all of the changes I made in my previous session are overwritten because my local cache got reset to the remote ref!

To decide on this behavior I think we need to decide what role a remote dependency serves. IMO it's a central store of Skaffold managed repositories. There can be multiple projects sharing the same repository akin to how a go module gets downloaded and shared by projects using them. IMO if I intend to make modification to a code and keep them I'd rather not have them in that managed store and clone them explicitly myself.

If I selectively allow reset, then I can't have multiple skaffold projects sharing this cache. WDYT?

Co-authored-by: Nick Kubala <nkubala@users.noreply.github.com>
@gsquared94
Copy link
Collaborator Author

Every execution of a remote module resets the cached repo to the referenced ref

let's say I have one git module in my project. I run skaffold dev, and make a bunch of local changes to the cloned code which I'm seeing be redeployed to my cluster. I take a break by hitting ctrl+c, and then later start up a new skaffold dev session - all of the changes I made in my previous session are overwritten because my local cache got reset to the remote ref!

To decide on this behavior I think we need to decide what role a remote dependency serves. IMO it's a central store of Skaffold managed repositories. There can be multiple projects sharing the same repository akin to how a go module gets downloaded and shared by projects using them. IMO if I intend to make modification to a code and keep them I'd rather not have them in that managed store and clone them explicitly myself.

If I selectively allow reset, then I can't have multiple skaffold projects sharing this cache. WDYT?

cc. @tejal29, @briandealwis, @marlon-gamez what do you guys think about this?

@nkubala
Copy link
Contributor

nkubala commented Feb 9, 2021

IMO if I intend to make modification to a code and keep them I'd rather not have them in that managed store and clone them explicitly myself

one of my thoughts around this was that this feature would be a good way to "trial" out a service in your application, since it's really easy to just plug-and-play any service with a skaffold.yaml. in that case we might want to allow users to make some local modifications without stomping on their changes - but the more i think about this, the more i think this is an uncommon use case.

my opinion is that we should give the ability to users to turn this auto-syncing off with a config field, but we should definitely default to resetting their local changes on every run. you make a great point that these local clones could be shared across projects, in which case local changes could cause unexpected behavior.

@MarlonGamez
Copy link
Contributor

I'm in agreement with what Gaurav is saying, and I also agree with Nick that this should be configurable as well.

cmd/skaffold/app/cmd/parse_config.go Outdated Show resolved Hide resolved
cmd/skaffold/app/cmd/parse_config.go Show resolved Hide resolved
configNameToFile map[string]string // configName -> file path
cachedRepos map[string]interface{} // git repo -> cache path or error
}

func getAllConfigs(opts config.SkaffoldOptions) ([]*latest.SkaffoldConfig, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to have these functions be methods on record?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think there's any difference either way.

pkg/skaffold/git/gitutil.go Outdated Show resolved Hide resolved
pkg/skaffold/git/gitutil.go Outdated Show resolved Hide resolved
cmd/skaffold/app/cmd/parse_config.go Outdated Show resolved Hide resolved
pkg/skaffold/schema/latest/config.go Outdated Show resolved Hide resolved
pkg/skaffold/git/gitutil_test.go Outdated Show resolved Hide resolved
cmd/skaffold/app/cmd/parse_config.go Outdated Show resolved Hide resolved
@briandealwis
Copy link
Member

I agree with @gsquared94: the local clones in ~/.skaffold/repos are shared and should be treated as read-only otherwise you risk interfering with other builds.

But @nkubala is right too: people need the ability make tweaks and overrides (viz go.mod's replace). Especially when using multi-level dependencies. Users can do local changes by using a different --remote-cache-dir (maybe this should be renamed to --git-remotes?). I wonder if we should include the ability for a top-level config to do go.mod-like replacements to override a dependency.

So I'd advocate changing the strict behaviour to logging warnings on finding unsaved work or unpublished commits.

@gsquared94 gsquared94 added the kokoro:force-run forces a kokoro re-run on a PR label Feb 10, 2021
@kokoro-team kokoro-team removed the kokoro:force-run forces a kokoro re-run on a PR label Feb 10, 2021
@gsquared94 gsquared94 merged commit 0ba3ee7 into GoogleContainerTools:master Feb 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[multi-config skaffold] Implement referencing Git repos as dependencies
5 participants