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

Add support for setting default-repo in global config #1057

Merged
merged 18 commits into from
Oct 23, 2018

Conversation

nkubala
Copy link
Contributor

@nkubala nkubala commented Sep 27, 2018

This PR enables users to set the "default-repo" value in the skaffold
global config. This value will be substituted into all provided images
in the skaffold.yaml and k8s manifests according to certain
heuristics, allowing a better user experience for developing
applications against different image registries.

@codecov-io
Copy link

codecov-io commented Sep 27, 2018

Codecov Report

Merging #1057 into master will increase coverage by 0.11%.
The diff coverage is 54.28%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1057      +/-   ##
==========================================
+ Coverage   42.18%   42.29%   +0.11%     
==========================================
  Files          89       90       +1     
  Lines        3999     4071      +72     
==========================================
+ Hits         1687     1722      +35     
- Misses       2143     2179      +36     
- Partials      169      170       +1
Impacted Files Coverage Δ
pkg/skaffold/deploy/deploy.go 0% <ø> (-25%) ⬇️
pkg/skaffold/config/options.go 88.23% <ø> (ø) ⬆️
cmd/skaffold/app/cmd/config/set.go 50.87% <ø> (+0.87%) ⬆️
cmd/skaffold/app/cmd/config/list.go 0% <0%> (ø) ⬆️
cmd/skaffold/app/cmd/cmd.go 0% <0%> (ø) ⬆️
pkg/skaffold/deploy/kustomize.go 34.72% <0%> (-1.51%) ⬇️
cmd/skaffold/app/cmd/runner.go 0% <0%> (ø) ⬆️
pkg/skaffold/deploy/helm.go 65.56% <100%> (+2.24%) ⬆️
pkg/skaffold/util/image.go 100% <100%> (ø)
pkg/skaffold/deploy/kubectl/visitor.go 92.85% <100%> (ø) ⬆️
... and 7 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 4f78ea2...1c4111d. Read the comment docs.

Copy link
Contributor

@balopat balopat left a comment

Choose a reason for hiding this comment

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

I tried out using a context, this is going to be awesome!
However I saw two important UX issues:

  • setting the default_repo on a global level doesn't work (+ there is no "resolution" logic yet for when it is defined for a context as well globally)
  • no way to "unset" the default repo

@balopat
Copy link
Contributor

balopat commented Sep 28, 2018

Another couple of thoughts:

  1. precendence rules: we were planning to introduce the flag based and environment variable based setting of default-repo. We might want to prepare in the design to represent the precedence rules of flag > env-var > config-file/context-level > config-file/global

  2. *global config" name: I keep thinking what would be a better name, as this collides with the "skaffold config" that is describing the pipeline. Maybe this is a real config and the other one should be renamed to "pipeline"? other ideas instead of "global config": "settings", "env", "context", "preferences", "execution context", "runtime env". I like "settings", as it's similar to maven's "setting.xml" that there is a user level default location, but you can pass the location of it as well.

@nkubala nkubala force-pushed the default-repo branch 2 times, most recently from 56b26d9 to 8fe8208 Compare October 2, 2018 21:35
@nkubala
Copy link
Contributor Author

nkubala commented Oct 2, 2018

@balopat thanks for the feedback!

setting the default_repo on a global level doesn't work

Can you elaborate? It seems to work for me. skaffold config set default-repo <repo_value> --global

no way to "unset" the default repo

I'll fix this in a separate PR.

there is no "resolution" logic yet for when it is defined for a context as well globally

This part is true, I was weighing options on the best approach for this. I think the right answer here for order of precedence is:

  1. Use the CLI flag: --default-repo=<repo_value> (fyi this will be implemented shortly)
  2. Use the context-specific config value:
kube-context: gke_nkubala-demo_us-west1-a_demo-cluster
default-repo: gcr.io/nkubala-demo
  1. Fallback to the global default-repo value, if set
global:
  default-repo: gcr.io/k8s-skaffold
  1. Do nothing

WDYT?

RE: naming, I'm also of the mind that we should considering renaming the SkaffoldConfig instead of renaming this. SkaffoldSpec or SkaffoldPipeline would be my two votes. If we renamed this, I'd considering calling it either settings or preferences.

@nkubala nkubala dismissed balopat’s stale review October 17, 2018 16:38

I think I addressed all your feedback

Copy link
Contributor

@balopat balopat 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 very close, and I love using it!
I have some small nits + missing docs.
This is a really cool feature, I'd like to have it represented in our docs, but at least in all the examples:

skaffold dev --default-repo myrepo
# or
SKAFFOLD_DEFAULT_REPO=myrepo skaffold dev

// prefixes don't match, concatenate and truncate
return truncate(defaultRepo + "/" + originalImage)
}
// TODO: check defaultRepo is < 256 chars when setting
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: remove?

@@ -42,7 +42,7 @@ type Tester interface {
// FullTester should always be the ONLY implementation of the Tester interface;
// newly added testing implementations should implement the Runner interface.
type FullTester struct {
testCases *[]latest.TestCase
testCases *[]*latest.TestCase
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this change shouldn't belong to this PR

@@ -77,7 +77,7 @@ func (t FullTester) Test(ctx context.Context, out io.Writer, bRes []build.Artifa
return nil
}

func (t FullTester) runStructureTests(ctx context.Context, out io.Writer, bRes []build.Artifact, testCase latest.TestCase) error {
func (t FullTester) runStructureTests(ctx context.Context, out io.Writer, bRes []build.Artifact, testCase *latest.TestCase) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this change shouldn't belong to this PR

@@ -32,7 +32,7 @@ import (
// NewTester parses the provided test cases from the Skaffold config,
// and returns a Tester instance with all the necessary test runners
// to run all specified tests.
func NewTester(testCases *[]latest.TestCase) (Tester, error) {
func NewTester(testCases *[]*latest.TestCase) (Tester, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this change shouldn't belong to this PR

@@ -55,7 +55,7 @@ func applyProfile(config *latest.SkaffoldPipeline, profile latest.Profile) {
Kind: config.Kind,
Build: overlayProfileField(config.Build, profile.Build).(latest.BuildConfig),
Deploy: overlayProfileField(config.Deploy, profile.Deploy).(latest.DeployConfig),
Test: overlayProfileField(config.Test, profile.Test).([]latest.TestCase),
Test: overlayProfileField(config.Test, profile.Test).([]*latest.TestCase),
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this change shouldn't belong to this PR

@@ -237,7 +237,7 @@ type Artifact struct {
type Profile struct {
Name string `yaml:"name,omitempty"`
Build BuildConfig `yaml:"build,omitempty"`
Test []TestCase `yaml:"test,omitempty"`
Test []*TestCase `yaml:"test,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this change shouldn't belong to this PR

@@ -330,7 +330,7 @@ func TestRun(t *testing.T) {
},
},
},
Test: []latest.TestCase{
Test: []*latest.TestCase{
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this change shouldn't belong to this PR

@@ -140,16 +145,16 @@ func getBuilder(cfg *latest.BuildConfig, kubeContext string) (build.Builder, err
}
}

func getTester(cfg *[]latest.TestCase) (test.Tester, error) {
func getTester(cfg *[]*latest.TestCase) (test.Tester, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this change shouldn't belong to this PR

newImageName := util.SubstituteDefaultRepoIntoImage(h.defaultRepo, imageName)
build, ok := imageToBuildResult[newImageName]
if !ok {
return nil, fmt.Errorf("No build present for %s", imageName)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return nil, fmt.Errorf("No build present for %s", imageName)
return nil, fmt.Errorf("no build present for %s", imageName)

nit: errors shouldn't start capitalized https://github.com/golang/go/wiki/CodeReviewComments#error-strings

func ReadConfigForFile(filename string) (*Config, error) {
fmt.Printf("reading config for file %s\n", filename)
Copy link
Contributor

Choose a reason for hiding this comment

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

ux-nit: this feels like a bit of clutter on the screen - can we make it available only for debug logging?

@balopat
Copy link
Contributor

balopat commented Oct 23, 2018

I'll open a separate PR to address my nits, as I can't add to your branch.

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