From 8ab20b4c77d8ee79431984b3803901a5796961f7 Mon Sep 17 00:00:00 2001 From: Jorge Gasca Date: Fri, 8 Nov 2019 12:02:36 -0500 Subject: [PATCH] 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 --- cmd/helm/helm.go | 10 ++++++++-- pkg/action/action.go | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/cmd/helm/helm.go b/cmd/helm/helm.go index 2c3c9e401..00768c7c8 100644 --- a/cmd/helm/helm.go +++ b/cmd/helm/helm.go @@ -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) diff --git a/pkg/action/action.go b/pkg/action/action.go index 48d6bf742..159b5cce3 100644 --- a/pkg/action/action.go +++ b/pkg/action/action.go @@ -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] +}