Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow namespace to be set by programs consuming helm. #6798

Merged
merged 3 commits into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/helm/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func runInstall(args []string, client *action.Install, valueOpts *values.Options
}
}

client.Namespace = settings.Namespace()
client.Namespace = settings.GetNamespace()
return client.Run(chartRequested, vals)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/helm/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func newLintCmd(out io.Writer) *cobra.Command {
if len(args) > 0 {
paths = args
}
client.Namespace = settings.Namespace()
client.Namespace = settings.GetNamespace()
vals, err := valueOpts.MergeValues(getter.All(settings))
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/helm/release_testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func newReleaseTestCmd(cfg *action.Configuration, out io.Writer) *cobra.Command
Long: releaseTestHelp,
Args: require.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
client.Namespace = settings.Namespace()
client.Namespace = settings.GetNamespace()
rel, runErr := client.Run(args[0])
// We only return an error if we weren't even able to get the
// release, otherwise we keep going so we can print status and logs
Expand Down
2 changes: 1 addition & 1 deletion cmd/helm/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
Long: upgradeDesc,
Args: require.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
client.Namespace = settings.Namespace()
client.Namespace = settings.GetNamespace()

if client.Version == "" && client.Devel {
debug("setting version to >0.0.0-0")
Expand Down
2 changes: 1 addition & 1 deletion pkg/action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func (c *Configuration) Init(envSettings *cli.EnvSettings, allNamespaces bool, h
}
var namespace string
if !allNamespaces {
namespace = envSettings.Namespace()
namespace = envSettings.GetNamespace()
}

var store *storage.Storage
Expand Down
17 changes: 9 additions & 8 deletions pkg/cli/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ import (

// EnvSettings describes all of the environment settings.
type EnvSettings struct {
namespace string
config genericclioptions.RESTClientGetter
configOnce sync.Once

// Namespace is the namespace used by storage drivers
Namespace string
// KubeConfig is the path to the kubeconfig file
KubeConfig string
// KubeContext is the name of the kubeconfig context.
Expand All @@ -61,7 +62,7 @@ type EnvSettings struct {
func New() *EnvSettings {

env := EnvSettings{
namespace: os.Getenv("HELM_NAMESPACE"),
Namespace: os.Getenv("HELM_NAMESPACE"),
KubeContext: os.Getenv("HELM_KUBECONTEXT"),
PluginsDirectory: envOr("HELM_PLUGINS", helmpath.DataPath("plugins")),
RegistryConfig: envOr("HELM_REGISTRY_CONFIG", helmpath.ConfigPath("registry.json")),
Expand All @@ -74,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.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", s.KubeContext, "name of the kubeconfig context to use")
fs.BoolVar(&s.Debug, "debug", s.Debug, "enable verbose output")
Expand All @@ -98,7 +99,7 @@ func (s *EnvSettings) EnvVars() map[string]string {
"HELM_REGISTRY_CONFIG": s.RegistryConfig,
"HELM_REPOSITORY_CACHE": s.RepositoryCache,
"HELM_REPOSITORY_CONFIG": s.RepositoryConfig,
"HELM_NAMESPACE": s.Namespace(),
"HELM_NAMESPACE": s.GetNamespace(),
"HELM_KUBECONTEXT": s.KubeContext,
}

Expand All @@ -110,9 +111,9 @@ func (s *EnvSettings) EnvVars() map[string]string {
}

//Namespace gets the namespace from the configuration
func (s *EnvSettings) Namespace() string {
if s.namespace != "" {
return s.namespace
func (s *EnvSettings) GetNamespace() string {
if s.Namespace != "" {
return s.Namespace
}

if ns, _, err := s.RESTClientGetter().ToRawKubeConfigLoader().Namespace(); err == nil {
Expand All @@ -124,7 +125,7 @@ func (s *EnvSettings) Namespace() string {
//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
}
4 changes: 2 additions & 2 deletions pkg/cli/environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ func TestEnvSettings(t *testing.T) {
if settings.Debug != tt.debug {
t.Errorf("expected debug %t, got %t", tt.debug, settings.Debug)
}
if settings.Namespace() != tt.ns {
t.Errorf("expected namespace %q, got %q", tt.ns, settings.Namespace())
if settings.GetNamespace() != tt.ns {
t.Errorf("expected namespace %q, got %q", tt.ns, settings.GetNamespace())
}
if settings.KubeContext != tt.kcontext {
t.Errorf("expected kube-context %q, got %q", tt.kcontext, settings.KubeContext)
Expand Down