Repository: helm/helm (go)

Issue:
helm 3.0.3 not rendering <CHARTNAME> in values file when using starters
We use some starters for creating some helm charts automatically in our CI/CD pipelines.

Let's image that we have a test starter with these two files among others:

* Chart.yaml:
```yaml
apiVersion: v2
description: <CHARTNAME> helm chart
name: <CHARTNAME>
version: 0.0.1
```
* values.yaml:
```yaml
# Chart example
#
<CHARTNAME>:
  port: 8080
  environment:

resources: {}
```
When creating the Chart with helm **v3.0.2**:

```shell
$ helm version
version.BuildInfo{Version:"v3.0.2", GitCommit:"19e47ee3283ae98139d98460de796c1be1e3975f", GitTreeState:"clean", GoVersion:"go1.13.5"}

$ helm create -p test example
Creating example
```
The chart and value files are rendered like this:

```shell
$ cat example/Chart.yaml
apiVersion: v2
appVersion: 0.1.0
description: A Helm chart for Kubernetes
name: example
type: application
version: 0.1.0

$ cat example/values.yaml
example:
  environment: null
  port: 50051
resources: {}
```
That it is the expected behavior.

When creating the chart with helm **v3.0.3**:

```shell
$ helm version
version.BuildInfo{Version:"v3.0.3", GitCommit:"ac925eb7279f4a6955df663a0128044a8a6b7593", GitTreeState:"clean", GoVersion:"go1.13.6"}

$ helm create -p test example
Creating example
```
The output files
```shell
$ cat example/Chart.yaml
apiVersion: v2
appVersion: 0.1.0
description: A Helm chart for Kubernetes
name: example
type: application
version: 0.1.0

$ cat example/values.yaml
# Chart example
#
<CHARTNAME>:
  port: 50051
  environment:

resources: {}
```

That it is not the expected behavior, I would expect in the values file  that `<CHARTNAME>` would be rendered to `example`.

Pull request:
Fixes issue where <CHARTNAME> is left in starter values file
This is a leftover bug from #7201.

Closes #7532

Patch:
diff --git a/pkg/chartutil/create.go b/pkg/chartutil/create.go
index 496f20166..24eb1e277 100644
--- a/pkg/chartutil/create.go
+++ b/pkg/chartutil/create.go
@@ -445,6 +445,15 @@ func CreateFrom(chartfile *chart.Metadata, dest, src string) error {
 	}
 	schart.Values = m
 
+	// SaveDir looks for the file values.yaml when saving rather than the values
+	// key in order to preserve the comments in the YAML. The name placeholder
+	// needs to be replaced on that file.
+	for _, f := range schart.Raw {
+		if f.Name == ValuesfileName {
+			f.Data = transform(string(f.Data), schart.Name())
+		}
+	}
+
 	return SaveDir(schart, dest)
 }
 


Test patch:
diff --git a/pkg/chartutil/create_test.go b/pkg/chartutil/create_test.go
index 82fde586c..d2a3b0a20 100644
--- a/pkg/chartutil/create_test.go
+++ b/pkg/chartutil/create_test.go
@@ -17,6 +17,7 @@ limitations under the License.
 package chartutil
 
 import (
+	"bytes"
 	"io/ioutil"
 	"os"
 	"path/filepath"
@@ -105,5 +106,14 @@ func TestCreateFrom(t *testing.T) {
 		if _, err := os.Stat(filepath.Join(dir, f)); err != nil {
 			t.Errorf("Expected %s file: %s", f, err)
 		}
+
+		// Check each file to make sure <CHARTNAME> has been replaced
+		b, err := ioutil.ReadFile(filepath.Join(dir, f))
+		if err != nil {
+			t.Errorf("Unable to read file %s: %s", f, err)
+		}
+		if bytes.Contains(b, []byte("<CHARTNAME>")) {
+			t.Errorf("File %s contains <CHARTNAME>", f)
+		}
 	}
 }