-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Global skaffold config #896
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
a8b0c8c
to
7593f24
Compare
cmd/skaffold/app/cmd/config_test.go
Outdated
} | ||
} | ||
|
||
// func TestSetConfig(t *testing.T) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
cmd/skaffold/app/cmd/config/flags.go
Outdated
|
||
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") |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the config also?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
cmd/skaffold/app/cmd/config/util.go
Outdated
} | ||
_, err = os.Stat(configFile) | ||
// TODO(nkubala): create default config? | ||
if err != nil { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
integration/run_test.go
Outdated
} | ||
} | ||
|
||
func randomString() string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
cmd/skaffold/app/cmd/config/util.go
Outdated
yaml "gopkg.in/yaml.v2" | ||
) | ||
|
||
const defaultConfigLocation = ".skaffold/config" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 :)
…ing global config entry
a45dcf0
to
4c7d8ac
Compare
There was a problem hiding this 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
Folder now gets autocreated along with config file if it doesn't exist
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.
Updated config value with context is now logged to the user |
6dec2f1
to
b9faaf7
Compare
cmd/skaffold/app/cmd/config/set.go
Outdated
RunE: func(cmd *cobra.Command, args []string) error { | ||
resolveKubectlContext() | ||
err := setConfigValue(args[0], args[1]) | ||
if err == nil { |
There was a problem hiding this comment.
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])
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
cmd/skaffold/app/cmd/config/util.go
Outdated
yaml "gopkg.in/yaml.v2" | ||
) | ||
|
||
const defaultConfigLocation = ".skaffold/config" |
There was a problem hiding this comment.
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?
cmd/skaffold/app/cmd/config/util.go
Outdated
context, err := context.CurrentContext() | ||
if err != nil { | ||
logrus.Warn(errors.Wrap(err, "retrieving current kubectl context")) | ||
kubecontext = "default" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
cmd/skaffold/app/cmd/config/util.go
Outdated
func resolveConfigFile() error { | ||
if configFile != "" { | ||
// we had a config provided as a flag, expand it and return | ||
if !filepath.IsAbs(configFile) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
49a84f2
to
b4bee87
Compare
This is a second variant on #886. Main differences:
Setting global values in the config is done through the
--global
flag, i.e.skaffold config set default-repo my-global-repo --global
.--kubecontext all
to show all config values, a--all
flag is added to thelist
command.skaffold config list --all
Opening this PR to show what this implementation would look like.