From b009bf7dc4ea62962f239643be591d931eac7b1a Mon Sep 17 00:00:00 2001 From: Matt Butcher Date: Thu, 4 Aug 2016 15:53:41 -0600 Subject: [PATCH] fix(helm): fix inspect command to not panic Helm can now inspect a chart if the values.yaml file is not present or is empty. --- cmd/helm/inspect.go | 9 +++---- cmd/helm/inspect_test.go | 13 ++++++++++ .../testdata/testcharts/novals/Chart.yaml | 6 +++++ cmd/helm/testdata/testcharts/novals/README.md | 13 ++++++++++ .../novals/templates/alpine-pod.yaml | 26 +++++++++++++++++++ 5 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 cmd/helm/testdata/testcharts/novals/Chart.yaml create mode 100644 cmd/helm/testdata/testcharts/novals/README.md create mode 100644 cmd/helm/testdata/testcharts/novals/templates/alpine-pod.yaml diff --git a/cmd/helm/inspect.go b/cmd/helm/inspect.go index 2e43f0e7a..8d9948b6f 100644 --- a/cmd/helm/inspect.go +++ b/cmd/helm/inspect.go @@ -130,11 +130,10 @@ func (i *inspectCmd) run() error { fmt.Fprintln(i.out, string(cf)) } - if i.output == both { - fmt.Fprintln(i.out, "---") - } - - if i.output == valuesOnly || i.output == both { + if (i.output == valuesOnly || i.output == both) && chrt.Values != nil { + if i.output == both { + fmt.Fprintln(i.out, "---") + } fmt.Fprintln(i.out, chrt.Values.Raw) } diff --git a/cmd/helm/inspect_test.go b/cmd/helm/inspect_test.go index 24c4a895e..bbd9c6199 100644 --- a/cmd/helm/inspect_test.go +++ b/cmd/helm/inspect_test.go @@ -61,4 +61,17 @@ func TestInspect(t *testing.T) { t.Errorf("Expected\n%q\nGot\n%q\n", expect[i], got) } } + + // Regression tests for missing values. See issue #1024. + b.Reset() + insp = &inspectCmd{ + chartpath: "testdata/testcharts/novals", + output: "values", + out: b, + } + insp.run() + if b.Len() != 0 { + t.Errorf("expected empty values buffer, got %q", b.String()) + } + } diff --git a/cmd/helm/testdata/testcharts/novals/Chart.yaml b/cmd/helm/testdata/testcharts/novals/Chart.yaml new file mode 100644 index 000000000..ce1a81da6 --- /dev/null +++ b/cmd/helm/testdata/testcharts/novals/Chart.yaml @@ -0,0 +1,6 @@ +description: Deploy a basic Alpine Linux pod +home: https://k8s.io/helm +name: novals +sources: +- https://github.com/kubernetes/helm +version: 0.2.0 diff --git a/cmd/helm/testdata/testcharts/novals/README.md b/cmd/helm/testdata/testcharts/novals/README.md new file mode 100644 index 000000000..3c32de5db --- /dev/null +++ b/cmd/helm/testdata/testcharts/novals/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/novals/templates/alpine-pod.yaml b/cmd/helm/testdata/testcharts/novals/templates/alpine-pod.yaml new file mode 100644 index 000000000..c15ab8efc --- /dev/null +++ b/cmd/helm/testdata/testcharts/novals/templates/alpine-pod.yaml @@ -0,0 +1,26 @@ +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}}" + annotations: + "helm.sh/created": {{.Release.Time.Seconds | quote }} +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"]