diff --git a/cmd/helm/init.go b/cmd/helm/init.go index 2982e95d2..fe5b40cc0 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 55b62d284..2e26652bf 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 29c39f4f3..3e315e2a4 100644 --- a/cmd/helm/installer/options.go +++ b/cmd/helm/installer/options.go @@ -78,7 +78,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 @@ -114,23 +114,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 de4ee75fe..5198f3c07 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 outputFormat 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