Modified the scope of Kubeconfig so it could be set outside an env variable.

Signed-off-by: Aaron Mell <amell@lumindigital.com>
pull/6660/head
Aaron Mell 6 years ago
parent 81b92e8c21
commit 4eca26e4e1

@ -211,9 +211,9 @@ func (c *Configuration) recordRelease(r *release.Release) {
// InitActionConfig initializes the action configuration // InitActionConfig initializes the action configuration
func (c *Configuration) Init(envSettings *cli.EnvSettings, allNamespaces bool, helmDriver string, log DebugLog) error { 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 kc.Log = log
clientset, err := kc.Factory.KubernetesClientSet() 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) panic("Unknown driver in HELM_DRIVER: " + helmDriver)
} }
c.RESTClientGetter = kubeconfig c.RESTClientGetter = getter
c.KubeClient = kc c.KubeClient = kc
c.Releases = store c.Releases = store
c.Log = log c.Log = log

@ -38,10 +38,13 @@ import (
// EnvSettings describes all of the environment settings. // EnvSettings describes all of the environment settings.
type EnvSettings struct { type EnvSettings struct {
namespace string namespace string
kubeConfig string //kubeConfig string
config genericclioptions.RESTClientGetter config genericclioptions.RESTClientGetter
configOnce sync.Once configOnce sync.Once
// KubeConfig is the path to the kubeconfig file
KubeConfig string
// KubeContext is the name of the kubeconfig context. // KubeContext is the name of the kubeconfig context.
KubeContext string KubeContext string
// Debug indicates whether or not Helm is running in Debug mode. // 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. // AddFlags binds flags to the given flagset.
func (s *EnvSettings) AddFlags(fs *pflag.FlagSet) { func (s *EnvSettings) AddFlags(fs *pflag.FlagSet) {
fs.StringVarP(&s.namespace, "namespace", "n", s.namespace, "namespace scope for this request") 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.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.BoolVar(&s.Debug, "debug", s.Debug, "enable verbose output")
fs.StringVar(&s.RegistryConfig, "registry-config", s.RegistryConfig, "path to the registry config file") 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, "HELM_KUBECONTEXT": s.KubeContext,
} }
if s.kubeConfig != "" { if s.KubeConfig != "" {
envvars["KUBECONFIG"] = s.kubeConfig envvars["KUBECONFIG"] = s.KubeConfig
} }
return envvars return envvars
@ -113,16 +116,16 @@ func (s *EnvSettings) Namespace() string {
return s.namespace return s.namespace
} }
if ns, _, err := s.KubeConfig().ToRawKubeConfigLoader().Namespace(); err == nil { if ns, _, err := s.RestClientGetter().ToRawKubeConfigLoader().Namespace(); err == nil {
return ns return ns
} }
return "default" return "default"
} }
//KubeConfig gets the kubeconfig from EnvSettings //KubeConfig gets the kubeconfig from EnvSettings
func (s *EnvSettings) KubeConfig() genericclioptions.RESTClientGetter { func (s *EnvSettings) RestClientGetter() genericclioptions.RESTClientGetter {
s.configOnce.Do(func() { 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 return s.config
} }

Loading…
Cancel
Save