Moved namespace and kubeconfig variable back to original place.

Signed-off-by: Aaron Mell <amell@lumindigital.com>
pull/6341/head
Aaron Mell 6 years ago
parent 1d66a676c8
commit 00249a3235

@ -30,21 +30,20 @@ import (
"github.com/spf13/pflag" "github.com/spf13/pflag"
"helm.sh/helm/v3/pkg/helmpath"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"helm.sh/helm/v3/pkg/helmpath"
"helm.sh/helm/v3/pkg/kube" "helm.sh/helm/v3/pkg/kube"
) )
// EnvSettings describes all of the environment settings. // EnvSettings describes all of the environment settings.
type EnvSettings struct { type EnvSettings struct {
namespace string
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.
Debug bool Debug bool
// RegistryConfig is the path to the registry config file. // RegistryConfig is the path to the registry config file.
RegistryConfig string RegistryConfig string
// RepositoryConfig is the path to the repositories file. // RepositoryConfig is the path to the repositories file.
@ -58,17 +57,12 @@ type EnvSettings struct {
var ( var (
config genericclioptions.RESTClientGetter config genericclioptions.RESTClientGetter
configOnce sync.Once configOnce sync.Once
// Namespace is the namespace scope.
namespace string
// KubeConfig is the path to the kubeconfig file.
kubeConfig string
) )
func New() *EnvSettings { func New() *EnvSettings {
namespace = os.Getenv("HELM_NAMESPACE")
env := EnvSettings{ env := EnvSettings{
namespace: os.Getenv("HELM_NAMESPACE"),
PluginsDirectory: envOr("HELM_PLUGINS", helmpath.DataPath("plugins")), PluginsDirectory: envOr("HELM_PLUGINS", helmpath.DataPath("plugins")),
RegistryConfig: envOr("HELM_REGISTRY_CONFIG", helmpath.ConfigPath("registry.json")), RegistryConfig: envOr("HELM_REGISTRY_CONFIG", helmpath.ConfigPath("registry.json")),
RepositoryConfig: envOr("HELM_REPOSITORY_CONFIG", helmpath.ConfigPath("repositories.yaml")), RepositoryConfig: envOr("HELM_REPOSITORY_CONFIG", helmpath.ConfigPath("repositories.yaml")),
@ -80,8 +74,8 @@ 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(&namespace, "namespace", "n", namespace, "namespace scope for this request") fs.StringVarP(&s.namespace, "namespace", "n", s.namespace, "namespace scope for this request")
fs.StringVar(&kubeConfig, "kubeconfig", "", "path to the kubeconfig file") fs.StringVar(&s.kubeConfig, "kubeconfig", "", "path to the kubeconfig file")
fs.StringVar(&s.KubeContext, "kube-context", "", "name of the kubeconfig context to use") fs.StringVar(&s.KubeContext, "kube-context", "", "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")
@ -109,8 +103,8 @@ func (s *EnvSettings) EnvVars() map[string]string {
//Namespace gets the namespace from the configuration //Namespace gets the namespace from the configuration
func (s *EnvSettings) Namespace() string { func (s *EnvSettings) Namespace() string {
if namespace != "" { if s.namespace != "" {
return namespace return s.namespace
} }
if ns, _, err := s.KubeConfig().ToRawKubeConfigLoader().Namespace(); err == nil { if ns, _, err := s.KubeConfig().ToRawKubeConfigLoader().Namespace(); err == nil {
@ -122,7 +116,7 @@ func (s *EnvSettings) Namespace() string {
//KubeConfig gets the kubeconfig from EnvSettings //KubeConfig gets the kubeconfig from EnvSettings
func (s *EnvSettings) KubeConfig() genericclioptions.RESTClientGetter { func (s *EnvSettings) KubeConfig() genericclioptions.RESTClientGetter {
configOnce.Do(func() { configOnce.Do(func() {
config = kube.GetConfig(kubeConfig, s.KubeContext, namespace) config = kube.GetConfig(s.kubeConfig, s.KubeContext, s.namespace)
}) })
return config return config
} }

Loading…
Cancel
Save