Commit da950c5c authored by Steven E. Harris's avatar Steven E. Harris

Separate manifests with document boundary markers

In order to allow the stream emitted by "helm init --debug" to be fed
back into "kubectl create/apply -f", use YAML starting and ending
document boundary markers instead of blank lines to separate the
individual manifests.
parent 890b6f56
...@@ -145,27 +145,58 @@ func (i *initCmd) run() error { ...@@ -145,27 +145,58 @@ func (i *initCmd) run() error {
i.opts.ImageSpec = i.image i.opts.ImageSpec = i.image
if flagDebug { if flagDebug {
var mfs string writeYAMLManifest := func(apiVersion, kind, body string, first, last bool) error {
w := i.out
if !first {
// YAML starting document boundary marker
if _, err := fmt.Fprintln(w, "---"); err != nil {
return err
}
}
if _, err := fmt.Fprintln(w, "apiVersion:", apiVersion); err != nil {
return err
}
if _, err := fmt.Fprintln(w, "kind:", kind); err != nil {
return err
}
if _, err := fmt.Fprint(w, body); err != nil {
return err
}
if !last {
return nil
}
// YAML ending document boundary marker
_, err := fmt.Fprintln(w, "...")
return err
}
var body string
var err error var err error
// write deployment manifest // write Deployment manifest
if mfs, err = installer.DeploymentManifest(&i.opts); err != nil { if body, err = installer.DeploymentManifest(&i.opts); err != nil {
return err
}
if err := writeYAMLManifest("extensions/v1beta1", "Deployment", body, true, false); err != nil {
return err return err
} }
fmt.Fprintln(i.out, fmt.Sprintf("apiVersion: extensions/v1beta1\nkind: Deployment\n%s", mfs))
// write service manifest // write Service manifest
if mfs, err = installer.ServiceManifest(i.namespace); err != nil { if body, err = installer.ServiceManifest(i.namespace); err != nil {
return err
}
if err := writeYAMLManifest("v1", "Service", body, false, !i.opts.EnableTLS); err != nil {
return err return err
} }
fmt.Fprintln(i.out, fmt.Sprintf("apiVersion: v1\nkind: Service\n%s", mfs))
// write secret manifest // write Secret manifest
if i.opts.EnableTLS { if i.opts.EnableTLS {
if mfs, err = installer.SecretManifest(&i.opts); err != nil { if body, err = installer.SecretManifest(&i.opts); err != nil {
return err
}
if err := writeYAMLManifest("v1", "Secret", body, false, true); err != nil {
return err return err
} }
fmt.Fprintln(i.out, fmt.Sprintf("apiVersion: v1\nkind: Secret\n%s", mfs))
} }
} }
......
...@@ -156,13 +156,19 @@ func TestInitCmd_dryRun(t *testing.T) { ...@@ -156,13 +156,19 @@ func TestInitCmd_dryRun(t *testing.T) {
if err := cmd.run(); err != nil { if err := cmd.run(); err != nil {
t.Fatal(err) t.Fatal(err)
} }
if len(fc.Actions()) != 0 { if got := len(fc.Actions()); got != 0 {
t.Error("expected no server calls") t.Errorf("expected no server calls, got %d", got)
} }
docs := bytes.Split(buf.Bytes(), []byte("\n---"))
if got, want := len(docs), 2; got != want {
t.Fatalf("Expected document count of %d, got %d", want, got)
}
for _, doc := range docs {
var y map[string]interface{} var y map[string]interface{}
if err := yaml.Unmarshal(buf.Bytes(), &y); err != nil { if err := yaml.Unmarshal(doc, &y); err != nil {
t.Errorf("Expected parseable YAML, got %q\n\t%s", buf.String(), err) t.Errorf("Expected parseable YAML, got %q\n\t%s", doc, err)
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment