From 0cfd43127441ae3bdb5aa31d191cabf3a6261393 Mon Sep 17 00:00:00 2001 From: Ethan Mosbaugh Date: Fri, 1 Apr 2022 14:13:32 -0700 Subject: [PATCH] Fix missing longhorn logs --- pkg/collect/ceph.go | 2 +- pkg/collect/longhorn.go | 10 +++++++--- pkg/collect/result.go | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/collect/ceph.go b/pkg/collect/ceph.go index 5f9febdc..a5aef42d 100644 --- a/pkg/collect/ceph.go +++ b/pkg/collect/ceph.go @@ -133,8 +133,8 @@ func cephCommandExec(ctx context.Context, c *Collector, cephCollector *troublesh return errors.Wrap(err, "failed to exec command") } + pathPrefix := GetCephCollectorFilepath(cephCollector.CollectorName, cephCollector.Namespace) for srcFilename, _ := range results { - pathPrefix := GetCephCollectorFilepath(cephCollector.CollectorName, cephCollector.Namespace) var dstFileName string switch { case strings.HasSuffix(srcFilename, "-stdout.txt"): diff --git a/pkg/collect/longhorn.go b/pkg/collect/longhorn.go index 50595676..b492e1d2 100644 --- a/pkg/collect/longhorn.go +++ b/pkg/collect/longhorn.go @@ -5,6 +5,7 @@ import ( "bytes" "context" "fmt" + "path" "path/filepath" "regexp" "sync" @@ -205,9 +206,12 @@ func Longhorn(c *Collector, longhornCollector *troubleshootv1beta2.Longhorn) (Co return nil, errors.Wrap(err, "collect longhorn logs") } logsDir := GetLonghornLogsDirectory(ns) - for key, log := range logs { - key = filepath.Join(logsDir, key) - output.SaveResult(c.BundlePath, key, bytes.NewBuffer(log)) + for srcFilename, _ := range logs { + dstFileName := path.Join(logsDir, srcFilename) + err := copyResult(logs, output, c.BundlePath, srcFilename, dstFileName) + if err != nil { + logger.Printf("Failed to copy file %s; %v", srcFilename, err) + } } // https://longhorn.io/docs/1.1.1/advanced-resources/data-recovery/corrupted-replica/ diff --git a/pkg/collect/result.go b/pkg/collect/result.go index 822203ee..7e49d93d 100644 --- a/pkg/collect/result.go +++ b/pkg/collect/result.go @@ -95,7 +95,7 @@ func (r CollectorResult) GetReader(bundlePath string, relativePath string) (io.R } filename := filepath.Join(bundlePath, relativePath) - f, err := os.Open(filename) + f, err := os.Open(filename) // does this ever close? if err != nil { return nil, errors.Wrap(err, "failed to open file") }