Skip to content

Global skaffold config #896

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 9 commits into from
Aug 30, 2018
Merged

Conversation

nkubala
Copy link
Contributor

@nkubala nkubala commented Aug 13, 2018

This is a second variant on #886. Main differences:

  • changes the structure of the config to have a top-level "global" section, followed by any number of context-specific config entries, inspired by @balopat. Example:
global: 
  default-repo: gcr.io/myrepo1/
kubecontexts:
   - kubectx: minikube
         default_repo: gcr.io/myrepo2/
   - kubectx: my_dev_gke
         default_repo: gcr.io/myrepo2/

Setting global values in the config is done through the --global flag, i.e. skaffold config set default-repo my-global-repo --global.

  • disallows setting config values for multiple contexts at a time
  • instead of specifying --kubecontext all to show all config values, a --all flag is added to the list command. skaffold config list --all

Opening this PR to show what this implementation would look like.

@codecov-io
Copy link

codecov-io commented Aug 23, 2018

Codecov Report

Merging #896 into master will decrease coverage by 0.29%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #896     +/-   ##
=========================================
- Coverage   43.58%   43.28%   -0.3%     
=========================================
  Files          62       63      +1     
  Lines        2611     2629     +18     
=========================================
  Hits         1138     1138             
- Misses       1354     1372     +18     
  Partials      119      119
Impacted Files Coverage Δ
pkg/skaffold/util/util.go 43.2% <0%> (-6.09%) ⬇️
cmd/skaffold/app/cmd/config.go 0% <0%> (ø)
cmd/skaffold/app/cmd/cmd.go 0% <0%> (ø) ⬆️

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 64c97a9...b4bee87. Read the comment docs.

@nkubala nkubala changed the title [WIP] Global skaffold config, version 2 Global skaffold config Aug 23, 2018
@balopat balopat self-assigned this Aug 23, 2018
}
}

// func TestSetConfig(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

do you want to remove this block or still hack on it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

whoops, nope I wrote this as an integration test so I'll remove it


func AddConfigFlags(cmd *cobra.Command) {
cmd.Flags().StringVarP(&configFile, "config", "c", "", "path to skaffold config")
cmd.Flags().StringVarP(&kubectx, "kubectx", "k", "", "kubectl context to set values against")
Copy link
Contributor

Choose a reason for hiding this comment

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

re: ahmet's comment from before that this isn't a standard term, just the name of his tool. change to kube-context?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah I'm fine with that

}

type ContextConfig struct {
Kubectx string `yaml:"kubectx,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

in the config also?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}
_, err = os.Stat(configFile)
// TODO(nkubala): create default config?
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

should check if os.IsNotExist or if regular error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

decided to use os.OpenFile here to create a default if it doesn't exist

}
}

func randomString() string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

perfect

@@ -1160,10 +1152,10 @@
"github.com/pkg/errors",
"github.com/sirupsen/logrus",
"github.com/spf13/cobra",
"github.com/spf13/pflag",
Copy link
Contributor

Choose a reason for hiding this comment

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

where is this dependency coming from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is just an artifact added by the dep solver. the actual pflag dependency didn't change here

yaml "gopkg.in/yaml.v2"
)

const defaultConfigLocation = ".skaffold/config"
Copy link
Contributor

Choose a reason for hiding this comment

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

will this work on windows?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it should, I see windows-specific logic in github.com/mitchellh/go-homedir which is what I'm using here along with filepath.Join

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need to do a filepath.Join() on this? Should it be .skaffold\config on windows?

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 catch, I should have thought about that when I responded :)

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 played around with the UX:

  • if the folder is not created it throws errors in all the subcommands
  • no list for possible configs - would be helpful instead of just providing a "this is not a default config"
  • no feedback around which context I set the value for - it would be great to have the feedback when I set the config regarding what I changed as it can be surprising

@nkubala
Copy link
Contributor Author

nkubala commented Aug 27, 2018

@balopat

  • if the folder is not created it throws errors in all the subcommands

Folder now gets autocreated along with config file if it doesn't exist

  • no list for possible configs - would be helpful instead of just providing a "this is not a default config"

Most other config management CLIs don't do this (kubectl, gcloud, etc.) since it requires introspecting about the config struct at runtime. I could add this but I think it's probably better to just document it somewhere and use that as a reference.

  • no feedback around which context I set the value for - it would be great to have the feedback when I set the config regarding what I changed as it can be surprising

Updated config value with context is now logged to the user

@balopat
Copy link
Contributor

balopat commented Aug 29, 2018

@nkubala - this lgtm - let's wait for @dgageot and @r2d4 with the merge

@r2d4 r2d4 self-assigned this Aug 29, 2018
RunE: func(cmd *cobra.Command, args []string) error {
resolveKubectlContext()
err := setConfigValue(args[0], args[1])
if err == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

might be more idiomatic to do

if err != nil {
  return err
}
logConfigChangeForUser(out, args[0], args[1])

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 actually had this before and changed it, because it's one less line to do it this way: the way you described you also need to do a return nil afterwards. curious to hear your opinion on this

Copy link
Contributor

Choose a reason for hiding this comment

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

slight preference for the return nil, but up to you

yaml "gopkg.in/yaml.v2"
)

const defaultConfigLocation = ".skaffold/config"
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need to do a filepath.Join() on this? Should it be .skaffold\config on windows?

context, err := context.CurrentContext()
if err != nil {
logrus.Warn(errors.Wrap(err, "retrieving current kubectl context"))
kubecontext = "default"
Copy link
Contributor

Choose a reason for hiding this comment

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

add this as a constant somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually I reworked this logic to fall back to the global values (not a "default" context) if one isn't set, thanks for pointing this out. updated

func resolveConfigFile() error {
if configFile != "" {
// we had a config provided as a flag, expand it and return
if !filepath.IsAbs(configFile) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why does this need to be an absolute path? add the reasoning as a comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks, this was from some previous logic which I removed a while back so I'll take this out


package config

type Config struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

add a docstring here so its clear this is unrelated to SkaffoldConfig

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@nkubala nkubala merged commit 61a96ad into GoogleContainerTools:master Aug 30, 2018
@nkubala nkubala deleted the global_config_v2 branch August 30, 2018 01:21
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.

4 participants