Skip to content

Commit dbea000

Browse files
authored
Merge pull request #2005 from carolynvs/debug-statements
Make runtime manifest log output debug messages
2 parents 4e10c4d + 3affbb1 commit dbea000

1 file changed

Lines changed: 23 additions & 8 deletions

File tree

pkg/runtime/runtime-manifest.go

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -504,11 +504,15 @@ func (m *RuntimeManifest) createOutputsDir() error {
504504
func (m *RuntimeManifest) unpackStateBag() error {
505505
_, err := m.FileSystem.Open(statePath)
506506
if os.IsNotExist(err) || len(m.StateBag) == 0 {
507-
fmt.Fprintln(m.Out, "No existing bundle state to unpack")
507+
if m.Debug {
508+
fmt.Fprintln(m.Err, "No existing bundle state to unpack")
509+
}
508510
return nil
509511
}
510512

511-
fmt.Fprintln(m.Out, "Unpacking bundle state...")
513+
if m.Debug {
514+
fmt.Fprintln(m.Err, "Unpacking bundle state...")
515+
}
512516
// Unpack the state file and copy its contents to where the bundle expects them
513517
// state var name -> path in bundle
514518
stateFiles := make(map[string]string, len(m.StateBag))
@@ -519,7 +523,9 @@ func (m *RuntimeManifest) unpackStateBag() error {
519523
unpackStateFile := func(tr *tar.Reader, header *tar.Header) error {
520524
name := strings.TrimPrefix(header.Name, "porter-state/")
521525
dest := stateFiles[name]
522-
fmt.Fprintln(m.Out, " -", name, "->", dest)
526+
if m.Debug {
527+
fmt.Fprintln(m.Err, " -", name, "->", dest)
528+
}
523529

524530
f, err := os.OpenFile(dest, os.O_CREATE|os.O_RDWR, os.FileMode(header.Mode))
525531
if err != nil {
@@ -577,14 +583,19 @@ func (m *RuntimeManifest) Finalize() error {
577583

578584
// Pack each state variable into /porter/state/tgz.
579585
func (m *RuntimeManifest) packStateBag() error {
580-
fmt.Fprintln(m.Out, "Packing bundle state...")
586+
if m.Debug {
587+
fmt.Fprintln(m.Err, "Packing bundle state...")
588+
}
589+
581590
packStateFile := func(tw *tar.Writer, s manifest.StateVariable) error {
582591
fi, err := m.FileSystem.Stat(s.Path)
583592
if os.IsNotExist(err) {
584593
return nil
585594
}
586595

587-
fmt.Fprintln(m.Out, " -", s.Path)
596+
if m.Debug {
597+
fmt.Fprintln(m.Err, " -", s.Path)
598+
}
588599
header, err := tar.FileInfoHeader(fi, fi.Name())
589600
if err != nil {
590601
return errors.Wrapf(err, "error creating tar header for state variable %s from path %s", s.Name, s.Path)
@@ -632,8 +643,10 @@ func (m *RuntimeManifest) packStateBag() error {
632643
// and if they can be bound, i.e. they grab a file from the bundle's filesystem,
633644
// apply the output.
634645
func (m *RuntimeManifest) applyUnboundBundleOutputs() error {
635-
if len(m.Outputs) > 0 {
636-
fmt.Fprintln(m.Out, "Collecting bundle outputs...")
646+
if len(m.bundle.Outputs) > 0 {
647+
if m.Debug {
648+
fmt.Fprintln(m.Err, "Collecting bundle outputs...")
649+
}
637650
}
638651

639652
var bigErr *multierror.Error
@@ -651,7 +664,9 @@ func (m *RuntimeManifest) applyUnboundBundleOutputs() error {
651664
}
652665

653666
// Print the output that we've collected
654-
fmt.Fprintln(m.Out, " -", name)
667+
if m.Debug {
668+
fmt.Fprintln(m.Err, " -", name)
669+
}
655670
if _, hasOutput := outputs[name]; !hasOutput {
656671
// Use the path as originally defined in the manifest
657672
// TODO(carolynvs): When we switch to driving everything completely

0 commit comments

Comments
 (0)