Fix missing longhorn logs

This commit is contained in:
Ethan Mosbaugh
2022-04-01 14:13:32 -07:00
parent fe5dd3ee8f
commit 0cfd431274
3 changed files with 9 additions and 5 deletions

View File

@@ -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"):

View File

@@ -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/

View File

@@ -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")
}