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