mirror of
https://github.com/helm/helm.git
synced 2026-04-03 16:15:46 -04:00
Merge pull request #6660 from aaronmell/Kubeconfig_scope_fix
Modified the scope of Kubeconfig so it could be set outside an env va…
This commit is contained in:
commit
3edad39e08
2 changed files with 13 additions and 11 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -39,9 +39,11 @@ import (
|
|||
// EnvSettings describes all of the environment settings.
|
||||
type EnvSettings struct {
|
||||
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 +75,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 +102,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 +115,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 {
|
||||
//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)
|
||||
s.config = kube.GetConfig(s.KubeConfig, s.KubeContext, s.namespace)
|
||||
})
|
||||
return s.config
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue