Repository: helm/helm
Pull request #10230 (2021-10-08 15:10:28)

add SetNamespace method for EnvSettings, in order to set namespace in helm sdk
add SetNamespace method for EnvSettings, in order to set namespace in helm sdk

Signed-off-by: yxxhero <aiopsclub@163.com>

<!--  Thanks for sending a pull request!  Here are some tips for you:
1. Make sure to read the Contributing Guide before submitting your PR: https://github.com/helm/helm/blob/main/CONTRIBUTING.md
2. If this PR closes another issue, add 'closes #<issue number>' somewhere in the PR summary. GitHub will automatically close that issue when this PR gets merged. Alternatively, adding 'refs #<issue number>' will not close the issue, but help provide the reviewer more context.-->

**What this PR does / why we need it**:
fix https://github.com/helm/helm/issues/10215
**Special notes for your reviewer**:
add SetNamespace method for EnvSettings, in order to set namespace in helm sdk
**If applicable**:
- [ ] this PR contains documentation
- [x] this PR contains unit tests
- [x] this PR has been tested for backwards compatibility



Patch:
diff --git a/cmd/helm/show.go b/cmd/helm/show.go
index ef45a6019..ee56e4666 100644
--- a/cmd/helm/show.go
+++ b/cmd/helm/show.go
@@ -33,7 +33,7 @@ This command consists of multiple subcommands to display information about a cha
 
 const showAllDesc = `
 This command inspects a chart (directory, file, or URL) and displays all its content
-(values.yaml, Chart.yaml, README)
+(values.yaml, Charts.yaml, README)
 `
 
 const showValuesDesc = `
@@ -43,7 +43,7 @@ of the values.yaml file
 
 const showChartDesc = `
 This command inspects a chart (directory, file, or URL) and displays the contents
-of the Chart.yaml file
+of the Charts.yaml file
 `
 
 const readmeChartDesc = `
diff --git a/pkg/action/dependency.go b/pkg/action/dependency.go
index 3265f1f17..6a284d762 100644
--- a/pkg/action/dependency.go
+++ b/pkg/action/dependency.go
@@ -193,7 +193,7 @@ func (d *Dependency) printDependencies(chartpath string, out io.Writer, c *chart
 }
 
 // printMissing prints warnings about charts that are present on disk, but are
-// not in Chart.yaml.
+// not in Charts.yaml.
 func (d *Dependency) printMissing(chartpath string, out io.Writer, reqs []*chart.Dependency) {
 	folder := filepath.Join(chartpath, "charts/*")
 	files, err := filepath.Glob(folder)
diff --git a/pkg/cli/environment.go b/pkg/cli/environment.go
index ee60d981f..7e3933cc6 100644
--- a/pkg/cli/environment.go
+++ b/pkg/cli/environment.go
@@ -180,6 +180,11 @@ func (s *EnvSettings) Namespace() string {
 	return "default"
 }
 
+// SetNamespace sets the namespace in the configuration
+func (s *EnvSettings) SetNamespace(namespace string) {
+	s.namespace = namespace
+}
+
 // RESTClientGetter gets the kubeconfig from EnvSettings
 func (s *EnvSettings) RESTClientGetter() genericclioptions.RESTClientGetter {
 	return s.config


Test patch:
diff --git a/pkg/cli/environment_test.go b/pkg/cli/environment_test.go
index 31ba7a237..1c3dc815e 100644
--- a/pkg/cli/environment_test.go
+++ b/pkg/cli/environment_test.go
@@ -25,6 +25,20 @@ import (
 	"github.com/spf13/pflag"
 )
 
+func TestSetNamespace(t *testing.T) {
+	settings := New()
+
+	if settings.namespace != "" {
+		t.Errorf("Expected empty namespace, got %s", settings.namespace)
+	}
+
+	settings.SetNamespace("testns")
+	if settings.namespace != "testns" {
+		t.Errorf("Expected namespace testns, got %s", settings.namespace)
+	}
+
+}
+
 func TestEnvSettings(t *testing.T) {
 	tests := []struct {
 		name string