Merge pull request #2210 from seh/include-yaml-doc-boundary-markers

Separate manifests printed by "helm init" with YAML document boundary markers
pull/2217/head
Matt Butcher 8 years ago committed by GitHub
commit 94f712ab4d

@ -145,27 +145,58 @@ func (i *initCmd) run() error {
i.opts.ImageSpec = i.image
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
// write deployment manifest
if mfs, err = installer.DeploymentManifest(&i.opts); err != nil {
// write Deployment manifest
if body, err = installer.DeploymentManifest(&i.opts); err != nil {
return err
}
if err := writeYAMLManifest("extensions/v1beta1", "Deployment", body, true, false); err != nil {
return err
}
fmt.Fprintln(i.out, fmt.Sprintf("apiVersion: extensions/v1beta1\nkind: Deployment\n%s", mfs))
// write service manifest
if mfs, err = installer.ServiceManifest(i.namespace); err != nil {
// write Service manifest
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
}
fmt.Fprintln(i.out, fmt.Sprintf("apiVersion: v1\nkind: Service\n%s", mfs))
// write secret manifest
// write Secret manifest
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
}
fmt.Fprintln(i.out, fmt.Sprintf("apiVersion: v1\nkind: Secret\n%s", mfs))
}
}

@ -156,13 +156,19 @@ func TestInitCmd_dryRun(t *testing.T) {
if err := cmd.run(); err != nil {
t.Fatal(err)
}
if len(fc.Actions()) != 0 {
t.Error("expected no server calls")
if got := len(fc.Actions()); got != 0 {
t.Errorf("expected no server calls, got %d", got)
}
var y map[string]interface{}
if err := yaml.Unmarshal(buf.Bytes(), &y); err != nil {
t.Errorf("Expected parseable YAML, got %q\n\t%s", buf.String(), err)
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{}
if err := yaml.Unmarshal(doc, &y); err != nil {
t.Errorf("Expected parseable YAML, got %q\n\t%s", doc, err)
}
}
}

Loading…
Cancel
Save