diff --git a/cmd/helm/install_test.go b/cmd/helm/install_test.go index 7a101940f..1a6524c63 100644 --- a/cmd/helm/install_test.go +++ b/cmd/helm/install_test.go @@ -47,6 +47,12 @@ func TestInstall(t *testing.T) { cmd: "install virgil testdata/testcharts/alpine -f testdata/testcharts/alpine/extra_values.yaml", golden: "output/install-with-values-file.txt", }, + // Install, external files + { + name: "install with external files", + cmd: "install virgil testdata/testcharts/configmap --include-file external.txt=testdata/external.txt", + golden: "output/install-with-external-files.txt", + }, // Install, no hooks { name: "install without hooks", diff --git a/cmd/helm/template_test.go b/cmd/helm/template_test.go index 92dd9825e..17caeeb45 100644 --- a/cmd/helm/template_test.go +++ b/cmd/helm/template_test.go @@ -121,6 +121,11 @@ func TestTemplateCmd(t *testing.T) { wantError: true, golden: "output/template-with-invalid-yaml-debug.txt", }, + { + name: "chart with template with external file", + cmd: fmt.Sprintf("template '%s' --include-file external.txt=testdata/external.txt", "testdata/testcharts/configmap"), + golden: "output/template-with-external-file.txt", + }, } runTestCmd(t, tests) } diff --git a/cmd/helm/testdata/external.txt b/cmd/helm/testdata/external.txt new file mode 100644 index 000000000..306c8fb1c --- /dev/null +++ b/cmd/helm/testdata/external.txt @@ -0,0 +1 @@ +out-of-chart-dir \ No newline at end of file diff --git a/cmd/helm/testdata/output/install-with-external-files.txt b/cmd/helm/testdata/output/install-with-external-files.txt new file mode 100644 index 000000000..406e522a9 --- /dev/null +++ b/cmd/helm/testdata/output/install-with-external-files.txt @@ -0,0 +1,6 @@ +NAME: virgil +LAST DEPLOYED: Fri Sep 2 22:04:05 1977 +NAMESPACE: default +STATUS: deployed +REVISION: 1 +TEST SUITE: None diff --git a/cmd/helm/testdata/output/template-with-external-file.txt b/cmd/helm/testdata/output/template-with-external-file.txt new file mode 100644 index 000000000..9550768c0 --- /dev/null +++ b/cmd/helm/testdata/output/template-with-external-file.txt @@ -0,0 +1,20 @@ +--- +# Source: configmap/templates/config-map.yaml +apiVersion: v1 +kind: ConfigMap +metadata: + name: "RELEASE-NAME-" + labels: + # The "app.kubernetes.io/managed-by" 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. + app.kubernetes.io/managed-by: "Helm" + # The "app.kubernetes.io/instance" convention makes it easy to tie a release + # to all of the Kubernetes resources that were created as part of that + # release. + app.kubernetes.io/instance: "RELEASE-NAME" + app.kubernetes.io/version: 1.0 + # This makes it easy to audit chart usage. + helm.sh/chart: "configmap-0.1.0" +data: + external.txt: out-of-chart-dir diff --git a/cmd/helm/testdata/testcharts/configmap/Chart.yaml b/cmd/helm/testdata/testcharts/configmap/Chart.yaml new file mode 100644 index 000000000..0b070f43e --- /dev/null +++ b/cmd/helm/testdata/testcharts/configmap/Chart.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +appVersion: "1.0" +description: Deploy a basic Config Map from an external file +home: https://helm.sh/helm +name: configmap +sources: +- https://github.com/helm/helm +version: 0.1.0 diff --git a/cmd/helm/testdata/testcharts/configmap/external.txt b/cmd/helm/testdata/testcharts/configmap/external.txt new file mode 100644 index 000000000..a67feea79 --- /dev/null +++ b/cmd/helm/testdata/testcharts/configmap/external.txt @@ -0,0 +1 @@ +in-chart \ No newline at end of file diff --git a/cmd/helm/testdata/testcharts/configmap/templates/config-map.yaml b/cmd/helm/testdata/testcharts/configmap/templates/config-map.yaml new file mode 100644 index 000000000..d03a9d5a9 --- /dev/null +++ b/cmd/helm/testdata/testcharts/configmap/templates/config-map.yaml @@ -0,0 +1,18 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: "{{.Release.Name}}-{{.Values.Name}}" + labels: + # The "app.kubernetes.io/managed-by" 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. + app.kubernetes.io/managed-by: {{.Release.Service | quote }} + # The "app.kubernetes.io/instance" convention makes it easy to tie a release + # to all of the Kubernetes resources that were created as part of that + # release. + app.kubernetes.io/instance: {{.Release.Name | quote }} + app.kubernetes.io/version: {{ .Chart.AppVersion }} + # This makes it easy to audit chart usage. + helm.sh/chart: "{{.Chart.Name}}-{{.Chart.Version}}" +data: +{{ (.Files.Glob .Values.external).AsConfig | indent 2 }} \ No newline at end of file diff --git a/cmd/helm/testdata/testcharts/configmap/values.yaml b/cmd/helm/testdata/testcharts/configmap/values.yaml new file mode 100644 index 000000000..338d478d7 --- /dev/null +++ b/cmd/helm/testdata/testcharts/configmap/values.yaml @@ -0,0 +1 @@ +external: external.txt \ No newline at end of file diff --git a/pkg/cli/files/parser_test.go b/pkg/cli/files/parser_test.go new file mode 100644 index 000000000..08e93dd9e --- /dev/null +++ b/pkg/cli/files/parser_test.go @@ -0,0 +1,41 @@ +package files + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestParseIntoString(t *testing.T) { + need := require.New(t) + is := assert.New(t) + + dest := make(map[string]string) + goodFlag := "foo.txt=../foo.txt" + anotherFlag := " bar.txt=~/bar.txt, baz.txt=/path/to/baz.txt" + + err := ParseIntoString(goodFlag, dest) + need.NoError(err) + + err = ParseIntoString(anotherFlag, dest) + need.NoError(err) + + is.Contains(dest, "foo.txt") + is.Contains(dest, "bar.txt") + is.Contains(dest, "baz.txt") + + is.Equal(dest["foo.txt"], "../foo.txt", "foo.txt not mapped properly") + is.Equal(dest["bar.txt"], "~/bar.txt", "bar.txt not mapped properly") + is.Equal(dest["baz.txt"], "/path/to/baz.txt", "baz.txt not mapped properly") + + overwriteFlag := "foo.txt=../new_foo.txt" + err = ParseIntoString(overwriteFlag, dest) + need.NoError(err) + + is.Equal(dest["foo.txt"], "../new_foo.txt") + + badFlag := "empty.txt" + err = ParseIntoString(badFlag, dest) + is.NotNil(err) +}