diff --git a/cmd/helm/init.go b/cmd/helm/init.go index 54d2513cf..aaafae8fd 100644 --- a/cmd/helm/init.go +++ b/cmd/helm/init.go @@ -200,7 +200,7 @@ func (i *initCmd) run() error { case "json": var out bytes.Buffer jsonb, err := yaml.ToJSON([]byte(body)) - if err := json.Indent(&out, jsonb, "", " "); err != nil { + if err != nil { return err } tm := []byte("{\"apiVersion\":\"extensions/v1beta1\",\"kind\":\"Deployment\",") diff --git a/cmd/helm/init_test.go b/cmd/helm/init_test.go index e4622dad4..292fee748 100644 --- a/cmd/helm/init_test.go +++ b/cmd/helm/init_test.go @@ -35,6 +35,8 @@ import ( "k8s.io/client-go/pkg/apis/extensions/v1beta1" testcore "k8s.io/client-go/testing" + "encoding/json" + "k8s.io/helm/cmd/helm/installer" "k8s.io/helm/pkg/helm/helmpath" ) @@ -302,3 +304,53 @@ func TestInitCmd_tlsOptions(t *testing.T) { } } } + +// TestInitCmd_output tests that init -o formats are unmarshal-able +func TestInitCmd_output(t *testing.T) { + // This is purely defensive in this case. + home, err := ioutil.TempDir("", "helm_home") + if err != nil { + t.Fatal(err) + } + dbg := settings.Debug + settings.Debug = true + defer func() { + os.Remove(home) + settings.Debug = dbg + }() + fc := fake.NewSimpleClientset() + tests := []struct { + expectF func([]byte, interface{}) error + expectName string + }{ + { + json.Unmarshal, + "json", + }, + { + yaml.Unmarshal, + "yaml", + }, + } + for _, s := range tests { + var buf bytes.Buffer + cmd := &initCmd{ + out: &buf, + home: helmpath.Home(home), + kubeClient: fc, + opts: installer.Options{Output: installer.OutputFormat(s.expectName)}, + namespace: v1.NamespaceDefault, + } + if err := cmd.run(); err != nil { + t.Fatal(err) + } + if got := len(fc.Actions()); got != 0 { + t.Errorf("expected no server calls, got %d", got) + } + d := &v1beta1.Deployment{} + if err = s.expectF(buf.Bytes(), &d); err != nil { + t.Errorf("error unmarshalling init %s output %s %s", s.expectName, err, string(buf.Bytes())) + } + } + +} diff --git a/cmd/helm/installer/options.go b/cmd/helm/installer/options.go index 0e65d72d8..90511497c 100644 --- a/cmd/helm/installer/options.go +++ b/cmd/helm/installer/options.go @@ -77,7 +77,7 @@ type Options struct { NodeSelectors string // Output dumps the Tiller manifest in the specified format (e.g. JSON) but skips Helm/Tiller installation - Output outputFormat + Output OutputFormat // Set merges additional values into the Tiller Deployment manifest Values []string @@ -113,23 +113,23 @@ func (opts *Options) valuesMap(m map[string]interface{}) (map[string]interface{} return m, nil } -type outputFormat string +type OutputFormat string -func (f *outputFormat) String() string { +func (f *OutputFormat) String() string { return string(*f) } -func (f *outputFormat) Type() string { - return "outputFormat" +func (f *OutputFormat) Type() string { + return "OutputFormat" } const ( - fmtJSON outputFormat = "json" + fmtJSON OutputFormat = "json" fmtYAML = "yaml" ) -func (f *outputFormat) Set(s string) error { - for _, of := range []outputFormat{fmtJSON, fmtYAML} { +func (f *OutputFormat) Set(s string) error { + for _, of := range []OutputFormat{fmtJSON, fmtYAML} { if s == string(of) { *f = of return nil diff --git a/docs/helm/helm_init.md b/docs/helm/helm_init.md index 949018ed7..9e962f952 100644 --- a/docs/helm/helm_init.md +++ b/docs/helm/helm_init.md @@ -39,7 +39,7 @@ helm init --local-repo-url string URL for local repository (default "http://127.0.0.1:8879/charts") --net-host install tiller with net=host --node-selectors string labels to specify the node on which tiller is installed (app=tiller,helm=rocks) - -o, --output string skip installation and output tiller's manifest in specified format (json or yaml) + -o, --output OutputFormat skip installation and output tiller's manifest in specified format (json or yaml) --service-account string name of service account --set stringArray set values for the Tiller Deployment manifest (can specify multiple or separate values with commas: key1=val1,key2=val2) --skip-refresh do not refresh (download) the local repository cache @@ -66,4 +66,4 @@ helm init ### SEE ALSO * [helm](helm.md) - The Helm package manager for Kubernetes. -###### Auto generated by spf13/cobra on 16-Jun-2017 +###### Auto generated by spf13/cobra on 19-Jun-2017