From bdd420a6b66a0e75bbeb222a6efcb4f54fd5a34b Mon Sep 17 00:00:00 2001
From: Matthew Fisher <matt.fisher@microsoft.com>
Date: Thu, 18 Oct 2018 15:18:04 -0700
Subject: [PATCH] remove dirname constraint on `helm package` (#4141)

Signed-off-by: Matthew Fisher <matt.fisher@microsoft.com>
---
 cmd/helm/package.go                           |  4 ---
 cmd/helm/package_test.go                      |  6 +++++
 .../testdata/testcharts/issue1979/Chart.yaml  |  6 +++++
 .../testdata/testcharts/issue1979/README.md   | 13 ++++++++++
 .../testcharts/issue1979/extra_values.yaml    |  2 ++
 .../testcharts/issue1979/more_values.yaml     |  2 ++
 .../issue1979/templates/alpine-pod.yaml       | 25 +++++++++++++++++++
 .../testdata/testcharts/issue1979/values.yaml |  2 ++
 8 files changed, 56 insertions(+), 4 deletions(-)
 create mode 100644 cmd/helm/testdata/testcharts/issue1979/Chart.yaml
 create mode 100644 cmd/helm/testdata/testcharts/issue1979/README.md
 create mode 100644 cmd/helm/testdata/testcharts/issue1979/extra_values.yaml
 create mode 100644 cmd/helm/testdata/testcharts/issue1979/more_values.yaml
 create mode 100644 cmd/helm/testdata/testcharts/issue1979/templates/alpine-pod.yaml
 create mode 100644 cmd/helm/testdata/testcharts/issue1979/values.yaml

diff --git a/cmd/helm/package.go b/cmd/helm/package.go
index ac8b57c8c..0178af6ab 100644
--- a/cmd/helm/package.go
+++ b/cmd/helm/package.go
@@ -157,10 +157,6 @@ func (o *packageOptions) run(out io.Writer) error {
 		debug("Setting appVersion to %s", o.appVersion)
 	}
 
-	if filepath.Base(path) != ch.Name() {
-		return errors.Errorf("directory name (%s) and Chart.yaml name (%s) must match", filepath.Base(path), ch.Name())
-	}
-
 	if reqs := ch.Metadata.Requirements; reqs != nil {
 		if err := checkDependencies(ch, reqs); err != nil {
 			return err
diff --git a/cmd/helm/package_test.go b/cmd/helm/package_test.go
index f49196e3c..fb032bc4b 100644
--- a/cmd/helm/package_test.go
+++ b/cmd/helm/package_test.go
@@ -98,6 +98,12 @@ func TestPackage(t *testing.T) {
 			expect:  "",
 			hasfile: "alpine-0.1.0.tgz",
 		},
+		{
+			name:    "package testdata/testcharts/issue1979",
+			args:    []string{"testdata/testcharts/issue1979"},
+			expect:  "",
+			hasfile: "alpine-0.1.0.tgz",
+		},
 		{
 			name:    "package --destination toot",
 			args:    []string{"testdata/testcharts/alpine"},
diff --git a/cmd/helm/testdata/testcharts/issue1979/Chart.yaml b/cmd/helm/testdata/testcharts/issue1979/Chart.yaml
new file mode 100644
index 000000000..6fbb27f18
--- /dev/null
+++ b/cmd/helm/testdata/testcharts/issue1979/Chart.yaml
@@ -0,0 +1,6 @@
+description: Deploy a basic Alpine Linux pod
+home: https://k8s.io/helm
+name: alpine
+sources:
+- https://github.com/kubernetes/helm
+version: 0.1.0
diff --git a/cmd/helm/testdata/testcharts/issue1979/README.md b/cmd/helm/testdata/testcharts/issue1979/README.md
new file mode 100644
index 000000000..3c32de5db
--- /dev/null
+++ b/cmd/helm/testdata/testcharts/issue1979/README.md
@@ -0,0 +1,13 @@
+#Alpine: A simple Helm chart
+
+Run a single pod of Alpine Linux.
+
+This example was generated using the command `helm create alpine`.
+
+The `templates/` directory contains a very simple pod resource with a
+couple of parameters.
+
+The `values.yaml` file contains the default values for the
+`alpine-pod.yaml` template.
+
+You can install this example using `helm install docs/examples/alpine`.
diff --git a/cmd/helm/testdata/testcharts/issue1979/extra_values.yaml b/cmd/helm/testdata/testcharts/issue1979/extra_values.yaml
new file mode 100644
index 000000000..468bbacbc
--- /dev/null
+++ b/cmd/helm/testdata/testcharts/issue1979/extra_values.yaml
@@ -0,0 +1,2 @@
+test:
+  Name: extra-values
diff --git a/cmd/helm/testdata/testcharts/issue1979/more_values.yaml b/cmd/helm/testdata/testcharts/issue1979/more_values.yaml
new file mode 100644
index 000000000..3d21e1fed
--- /dev/null
+++ b/cmd/helm/testdata/testcharts/issue1979/more_values.yaml
@@ -0,0 +1,2 @@
+test:
+  Name: more-values
diff --git a/cmd/helm/testdata/testcharts/issue1979/templates/alpine-pod.yaml b/cmd/helm/testdata/testcharts/issue1979/templates/alpine-pod.yaml
new file mode 100644
index 000000000..ee61f2056
--- /dev/null
+++ b/cmd/helm/testdata/testcharts/issue1979/templates/alpine-pod.yaml
@@ -0,0 +1,25 @@
+apiVersion: v1
+kind: Pod
+metadata:
+  name: "{{.Release.Name}}-{{.Values.Name}}"
+  labels:
+    # The "heritage" label is used to track which tool deployed a given chart.
+    # It is useful for admins who want to see what releases a particular tool
+    # is responsible for.
+    heritage: {{.Release.Service | quote }}
+    # The "release" convention makes it easy to tie a release to all of the
+    # Kubernetes resources that were created as part of that release.
+    release: {{.Release.Name | quote }}
+    # This makes it easy to audit chart usage.
+    chart: "{{.Chart.Name}}-{{.Chart.Version}}"
+    values: {{.Values.test.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.
+  # {{default "Never" .restartPolicy}} is a slightly optimized version of the
+  # more conventional syntax: {{.restartPolicy | default "Never"}}
+  restartPolicy: {{default "Never" .Values.restartPolicy}}
+  containers:
+  - name: waiter
+    image: "alpine:3.3"
+    command: ["/bin/sleep","9000"]
diff --git a/cmd/helm/testdata/testcharts/issue1979/values.yaml b/cmd/helm/testdata/testcharts/issue1979/values.yaml
new file mode 100644
index 000000000..879d760f9
--- /dev/null
+++ b/cmd/helm/testdata/testcharts/issue1979/values.yaml
@@ -0,0 +1,2 @@
+# The pod name
+Name: my-alpine
-- 
GitLab