Repository: helm/helm
Pull request #7387 (2020-01-13 06:34:07)

Refactored alpine-pod.yaml file to make the chart work.
Changes made to alpine-pod.yaml file in helm/cmd/helm/testdata/testcharts/alpine/templates directory to make the helm chart work according to the values.yaml file.

Signed-off-by: Etash Singh etashsingh29@gmail.com


Patch:
diff --git a/pkg/action/pull.go b/pkg/action/pull.go
index 4ff5f5c3e..b0a3d2598 100644
--- a/pkg/action/pull.go
+++ b/pkg/action/pull.go
@@ -110,21 +110,13 @@ func (p *Pull) Run(chartRef string) (string, error) {
 		if !filepath.IsAbs(ud) {
 			ud = filepath.Join(p.DestDir, ud)
 		}
-		// Let udCheck to check conflict file/dir without replacing ud when untarDir is the current directory(.).
-		udCheck := ud
-		if udCheck == "." {
-			_, udCheck = filepath.Split(chartRef)
-		} else {
-			_, chartName := filepath.Split(chartRef)
-			udCheck = filepath.Join(udCheck, chartName)
-		}
-		if _, err := os.Stat(udCheck); err != nil {
-			if err := os.MkdirAll(udCheck, 0755); err != nil {
+		if fi, err := os.Stat(ud); err != nil {
+			if err := os.MkdirAll(ud, 0755); err != nil {
 				return out.String(), errors.Wrap(err, "failed to untar (mkdir)")
 			}
 
-		} else {
-			return out.String(), errors.Errorf("failed to untar: a file or directory with the name %s already exists", udCheck)
+		} else if !fi.IsDir() {
+			return out.String(), errors.Errorf("failed to untar: %s is not a directory", ud)
 		}
 
 		return out.String(), chartutil.ExpandFile(ud, saved)


Test patch:
diff --git a/cmd/helm/pull_test.go b/cmd/helm/pull_test.go
index 1aca66100..248195774 100644
--- a/cmd/helm/pull_test.go
+++ b/cmd/helm/pull_test.go
@@ -41,10 +41,7 @@ func TestPullCmd(t *testing.T) {
 	tests := []struct {
 		name         string
 		args         string
-		existFile    string
-		existDir     string
 		wantError    bool
-		wantErrorMsg string
 		failExpect   string
 		expectFile   string
 		expectDir    bool
@@ -90,24 +87,10 @@ func TestPullCmd(t *testing.T) {
 			expectFile: "./signtest",
 			expectDir:  true,
 		},
-		{
-			name:         "Fetch untar when file with same name existed",
-			args:         "test/test1 --untar --untardir test1",
-			existFile:    "test1",
-			wantError:    true,
-			wantErrorMsg: fmt.Sprintf("failed to untar: a file or directory with the name %s already exists", filepath.Join(srv.Root(), "test1")),
-		},
-		{
-			name:         "Fetch untar when dir with same name existed",
-			args:         "test/test2 --untar --untardir test2",
-			existDir:     "test2",
-			wantError:    true,
-			wantErrorMsg: fmt.Sprintf("failed to untar: a file or directory with the name %s already exists", filepath.Join(srv.Root(), "test2")),
-		},
 		{
 			name:         "Fetch, verify, untar",
-			args:         "test/signtest --verify --keyring=testdata/helm-test-key.pub --untar --untardir signtest2",
-			expectFile:   "./signtest2",
+			args:         "test/signtest --verify --keyring=testdata/helm-test-key.pub --untar --untardir signtest",
+			expectFile:   "./signtest",
 			expectDir:    true,
 			expectVerify: true,
 		},
@@ -144,27 +127,9 @@ func TestPullCmd(t *testing.T) {
 				filepath.Join(outdir, "repositories.yaml"),
 				outdir,
 			)
-			// Create file or Dir before helm pull --untar, see: https://github.com/helm/helm/issues/7182
-			if tt.existFile != "" {
-				file := filepath.Join(outdir, tt.existFile)
-				_, err := os.Create(file)
-				if err != nil {
-					t.Fatal("err")
-				}
-			}
-			if tt.existDir != "" {
-				file := filepath.Join(outdir, tt.existDir)
-				err := os.Mkdir(file, 0755)
-				if err != nil {
-					t.Fatal(err)
-				}
-			}
 			_, out, err := executeActionCommand(cmd)
 			if err != nil {
 				if tt.wantError {
-					if tt.wantErrorMsg != "" && tt.wantErrorMsg == err.Error() {
-						t.Fatalf("Actual error %s, not equal to expected error %s", err, tt.wantErrorMsg)
-					}
 					return
 				}
 				t.Fatalf("%q reported error: %s", tt.name, err)
diff --git a/cmd/helm/testdata/testcharts/alpine/templates/alpine-pod.yaml b/cmd/helm/testdata/testcharts/alpine/templates/alpine-pod.yaml
index ae19a1127..a1a44e53f 100644
--- a/cmd/helm/testdata/testcharts/alpine/templates/alpine-pod.yaml
+++ b/cmd/helm/testdata/testcharts/alpine/templates/alpine-pod.yaml
@@ -14,7 +14,7 @@ metadata:
     app.kubernetes.io/version: {{ .Chart.AppVersion }}
     # This makes it easy to audit chart usage.
     helm.sh/chart: "{{.Chart.Name}}-{{.Chart.Version}}"
-    values: {{.Values.test.Name}}
+    values: {{.Values.Name}}
 spec:
   # This shows how to use a simple value. This will look for a passed-in value
   # called restartPolicy. If it is not found, it will use the default value.