feat(helm): Add map of cmds that req actionConfig

Most commands unrelated to release do not require actionConfig. This
provides a way to differentiate between commands that use it and those
that do not, so that a user doesn't need to worry about their kubeconfig
if they are running `helm version` for example.

Signed-off-by: Jorge Gasca <jorge.ignacio.gasca@gmail.com>
pull/6915/head
Jorge Gasca 6 years ago
parent 43acbfe86d
commit 8ab20b4c77

@ -67,10 +67,16 @@ func main() {
actionConfig := new(action.Configuration)
cmd := newRootCmd(actionConfig, os.Stdout, os.Args[1:])
if err := actionConfig.Init(settings.RESTClientGetter(), settings.Namespace(), os.Getenv("HELM_DRIVER"), debug); err != nil {
debug("%+v", err)
subCmd, _, err := cmd.Find(os.Args[1:])
if err != nil {
os.Exit(1)
}
actionConfigRequired := action.ActionConfigRequired(subCmd.Use)
if actionConfigRequired {
if err := actionConfig.Init(settings.RESTClientGetter(), settings.Namespace(), os.Getenv("HELM_DRIVER"), debug); err != nil {
log.Fatalf("%+v", err)
}
}
if err := cmd.Execute(); err != nil {
debug("%+v", err)

@ -244,3 +244,44 @@ func (c *Configuration) Init(getter genericclioptions.RESTClientGetter, namespac
return nil
}
func ActionConfigRequired(command string) bool {
var actionConfigRequired = map[string]bool{
// release commands
"get": true,
"history": true,
"install": true,
"list": true,
"releaseTest": true,
"rollback": true,
"status": true,
"template": true,
"uninstall": true,
"upgrade": true,
//registry commands
"registry": true,
"chart": true,
// chart commands
"create": false,
"dependency": false,
"pull": false,
"show": false,
"lint": false,
"package": false,
"repo": false,
"search": false,
"verify": false,
"completion": false,
"env": false,
"plugin": false,
"version": false,
"docs": false,
//root
"helm": false,
}
return actionConfigRequired[command]
}

Loading…
Cancel
Save