Export namespace in cli.EnvSettings

This is useful for applications that use the Go SDK and need to set the
namespace without relying on the HELM_NAMESPACE environment variable.

Signed-off-by: Nitya Dhanushkodi <nitya@hashicorp.com>
pull/10148/head
Nitya Dhanushkodi 4 years ago
parent 9fafb4ad68
commit 17a09d60ec

@ -39,9 +39,10 @@ const defaultMaxHistory = 10
// EnvSettings describes all of the environment settings. // EnvSettings describes all of the environment settings.
type EnvSettings struct { type EnvSettings struct {
namespace string config *genericclioptions.ConfigFlags
config *genericclioptions.ConfigFlags
// KubeNamespace is the namespace to use for the Kubernetes client.
KubeNamespace string
// KubeConfig is the path to the kubeconfig file // KubeConfig is the path to the kubeconfig file
KubeConfig string KubeConfig string
// KubeContext is the name of the kubeconfig context. // KubeContext is the name of the kubeconfig context.
@ -72,7 +73,7 @@ type EnvSettings struct {
func New() *EnvSettings { func New() *EnvSettings {
env := &EnvSettings{ env := &EnvSettings{
namespace: os.Getenv("HELM_NAMESPACE"), KubeNamespace: os.Getenv("HELM_NAMESPACE"),
MaxHistory: envIntOr("HELM_MAX_HISTORY", defaultMaxHistory), MaxHistory: envIntOr("HELM_MAX_HISTORY", defaultMaxHistory),
KubeContext: os.Getenv("HELM_KUBECONTEXT"), KubeContext: os.Getenv("HELM_KUBECONTEXT"),
KubeToken: os.Getenv("HELM_KUBETOKEN"), KubeToken: os.Getenv("HELM_KUBETOKEN"),
@ -89,7 +90,7 @@ func New() *EnvSettings {
// bind to kubernetes config flags // bind to kubernetes config flags
env.config = &genericclioptions.ConfigFlags{ env.config = &genericclioptions.ConfigFlags{
Namespace: &env.namespace, Namespace: &env.KubeNamespace,
Context: &env.KubeContext, Context: &env.KubeContext,
BearerToken: &env.KubeToken, BearerToken: &env.KubeToken,
APIServer: &env.KubeAPIServer, APIServer: &env.KubeAPIServer,
@ -103,7 +104,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.KubeNamespace, "KubeNamespace", "n", s.KubeNamespace, "KubeNamespace 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.StringVar(&s.KubeToken, "kube-token", s.KubeToken, "bearer token used for authentication") fs.StringVar(&s.KubeToken, "kube-token", s.KubeToken, "bearer token used for authentication")

Loading…
Cancel
Save