From 4eca26e4e1d4b44302390b794d56f795775d3a20 Mon Sep 17 00:00:00 2001 From: Aaron Mell Date: Mon, 14 Oct 2019 13:14:14 -0500 Subject: [PATCH 1/2] Modified the scope of Kubeconfig so it could be set outside an env variable. Signed-off-by: Aaron Mell --- pkg/action/action.go | 6 +++--- pkg/cli/environment.go | 19 +++++++++++-------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/pkg/action/action.go b/pkg/action/action.go index a36454321..71edf7bd5 100644 --- a/pkg/action/action.go +++ b/pkg/action/action.go @@ -211,9 +211,9 @@ func (c *Configuration) recordRelease(r *release.Release) { // InitActionConfig initializes the action configuration func (c *Configuration) Init(envSettings *cli.EnvSettings, allNamespaces bool, helmDriver string, log DebugLog) error { - kubeconfig := envSettings.KubeConfig() + getter := envSettings.RestClientGetter() - kc := kube.New(kubeconfig) + kc := kube.New(getter) kc.Log = log clientset, err := kc.Factory.KubernetesClientSet() @@ -243,7 +243,7 @@ func (c *Configuration) Init(envSettings *cli.EnvSettings, allNamespaces bool, h panic("Unknown driver in HELM_DRIVER: " + helmDriver) } - c.RESTClientGetter = kubeconfig + c.RESTClientGetter = getter c.KubeClient = kc c.Releases = store c.Log = log diff --git a/pkg/cli/environment.go b/pkg/cli/environment.go index 041b2f841..6958c04a9 100644 --- a/pkg/cli/environment.go +++ b/pkg/cli/environment.go @@ -38,10 +38,13 @@ import ( // EnvSettings describes all of the environment settings. type EnvSettings struct { - namespace string - kubeConfig string + namespace string + //kubeConfig string config genericclioptions.RESTClientGetter configOnce sync.Once + + // KubeConfig is the path to the kubeconfig file + KubeConfig string // KubeContext is the name of the kubeconfig context. KubeContext string // Debug indicates whether or not Helm is running in Debug mode. @@ -73,7 +76,7 @@ func New() *EnvSettings { // AddFlags binds flags to the given flagset. func (s *EnvSettings) AddFlags(fs *pflag.FlagSet) { fs.StringVarP(&s.namespace, "namespace", "n", s.namespace, "namespace scope for this request") - fs.StringVar(&s.kubeConfig, "kubeconfig", "", "path to the kubeconfig file") + fs.StringVar(&s.KubeConfig, "kubeconfig", "", "path to the kubeconfig file") fs.StringVar(&s.KubeContext, "kube-context", s.KubeContext, "name of the kubeconfig context to use") fs.BoolVar(&s.Debug, "debug", s.Debug, "enable verbose output") fs.StringVar(&s.RegistryConfig, "registry-config", s.RegistryConfig, "path to the registry config file") @@ -100,8 +103,8 @@ func (s *EnvSettings) EnvVars() map[string]string { "HELM_KUBECONTEXT": s.KubeContext, } - if s.kubeConfig != "" { - envvars["KUBECONFIG"] = s.kubeConfig + if s.KubeConfig != "" { + envvars["KUBECONFIG"] = s.KubeConfig } return envvars @@ -113,16 +116,16 @@ func (s *EnvSettings) Namespace() string { return s.namespace } - if ns, _, err := s.KubeConfig().ToRawKubeConfigLoader().Namespace(); err == nil { + if ns, _, err := s.RestClientGetter().ToRawKubeConfigLoader().Namespace(); err == nil { return ns } return "default" } //KubeConfig gets the kubeconfig from EnvSettings -func (s *EnvSettings) KubeConfig() genericclioptions.RESTClientGetter { +func (s *EnvSettings) RestClientGetter() genericclioptions.RESTClientGetter { s.configOnce.Do(func() { - s.config = kube.GetConfig(s.kubeConfig, s.KubeContext, s.namespace) + s.config = kube.GetConfig(s.KubeConfig, s.KubeContext, s.namespace) }) return s.config } From 6a98d1f1d209c7a96a0df250e05070a9932e089f Mon Sep 17 00:00:00 2001 From: Aaron Mell Date: Mon, 14 Oct 2019 11:46:06 -0500 Subject: [PATCH 2/2] Code Review Changes Signed-off-by: Aaron Mell --- pkg/action/action.go | 2 +- pkg/cli/environment.go | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/action/action.go b/pkg/action/action.go index 71edf7bd5..28d88c3ed 100644 --- a/pkg/action/action.go +++ b/pkg/action/action.go @@ -211,7 +211,7 @@ func (c *Configuration) recordRelease(r *release.Release) { // InitActionConfig initializes the action configuration func (c *Configuration) Init(envSettings *cli.EnvSettings, allNamespaces bool, helmDriver string, log DebugLog) error { - getter := envSettings.RestClientGetter() + getter := envSettings.RESTClientGetter() kc := kube.New(getter) kc.Log = log diff --git a/pkg/cli/environment.go b/pkg/cli/environment.go index 6958c04a9..28e7873be 100644 --- a/pkg/cli/environment.go +++ b/pkg/cli/environment.go @@ -38,8 +38,7 @@ import ( // EnvSettings describes all of the environment settings. type EnvSettings struct { - namespace string - //kubeConfig string + namespace string config genericclioptions.RESTClientGetter configOnce sync.Once @@ -116,14 +115,14 @@ func (s *EnvSettings) Namespace() string { return s.namespace } - if ns, _, err := s.RestClientGetter().ToRawKubeConfigLoader().Namespace(); err == nil { + if ns, _, err := s.RESTClientGetter().ToRawKubeConfigLoader().Namespace(); err == nil { return ns } return "default" } -//KubeConfig gets the kubeconfig from EnvSettings -func (s *EnvSettings) RestClientGetter() genericclioptions.RESTClientGetter { +//RESTClientGetter gets the kubeconfig from EnvSettings +func (s *EnvSettings) RESTClientGetter() genericclioptions.RESTClientGetter { s.configOnce.Do(func() { s.config = kube.GetConfig(s.KubeConfig, s.KubeContext, s.namespace) })