|
5 | 5 | "bytes" |
6 | 6 | "context" |
7 | 7 | "fmt" |
8 | | - "path" |
9 | 8 | "path/filepath" |
10 | 9 | "regexp" |
11 | 10 | "sync" |
@@ -214,27 +213,10 @@ func (c *CollectLonghorn) Collect(progressChan chan<- interface{}) (CollectorRes |
214 | 213 | } |
215 | 214 | output.SaveResult(c.BundlePath, settingsKey, bytes.NewBuffer(settingsB)) |
216 | 215 |
|
217 | | - // logs of all pods in namespace |
218 | | - logsCollectorSpec := &troubleshootv1beta2.Logs{ |
219 | | - Selector: []string{""}, |
220 | | - Namespace: ns, |
221 | | - } |
222 | | - |
223 | | - rbacErrors := c.GetRBACErrors() |
224 | | - logsCollector := &CollectLogs{logsCollectorSpec, c.BundlePath, c.Namespace, c.ClientConfig, c.Client, c.Context, nil, rbacErrors} |
225 | | - |
226 | | - logs, err := logsCollector.Collect(progressChan) |
| 216 | + err = c.collectLonghornLogs(ns, output, progressChan) |
227 | 217 | if err != nil { |
228 | 218 | return nil, errors.Wrap(err, "collect longhorn logs") |
229 | 219 | } |
230 | | - logsDir := GetLonghornLogsDirectory(ns) |
231 | | - for srcFilename, _ := range logs { |
232 | | - dstFileName := path.Join(logsDir, srcFilename) |
233 | | - err := copyResult(logs, output, c.BundlePath, srcFilename, dstFileName) |
234 | | - if err != nil { |
235 | | - logger.Printf("Failed to copy file %s; %v", srcFilename, err) |
236 | | - } |
237 | | - } |
238 | 220 |
|
239 | 221 | // https://longhorn.io/docs/1.1.1/advanced-resources/data-recovery/corrupted-replica/ |
240 | 222 |
|
@@ -307,6 +289,29 @@ func (c *CollectLonghorn) Collect(progressChan chan<- interface{}) (CollectorRes |
307 | 289 | return output, nil |
308 | 290 | } |
309 | 291 |
|
| 292 | +func (c *CollectLonghorn) collectLonghornLogs(namespace string, results CollectorResult, progressChan chan<- interface{}) error { |
| 293 | + // logs of all pods in namespace |
| 294 | + logsCollectorSpec := &troubleshootv1beta2.Logs{ |
| 295 | + Selector: []string{""}, |
| 296 | + Name: GetLonghornLogsDirectory(namespace), // Logs (symlinks) will be stored in this directory |
| 297 | + Namespace: namespace, |
| 298 | + } |
| 299 | + |
| 300 | + rbacErrors := c.GetRBACErrors() |
| 301 | + logsCollector := &CollectLogs{logsCollectorSpec, c.BundlePath, namespace, c.ClientConfig, c.Client, c.Context, nil, rbacErrors} |
| 302 | + |
| 303 | + logs, err := logsCollector.Collect(progressChan) |
| 304 | + if err != nil { |
| 305 | + return err |
| 306 | + } |
| 307 | + |
| 308 | + // Add logs collector results to the rest of |
| 309 | + // the longhorn collector results for later consumption |
| 310 | + results.AddResult(logs) |
| 311 | + |
| 312 | + return nil |
| 313 | +} |
| 314 | + |
310 | 315 | func GetLonghornNodesDirectory(namespace string) string { |
311 | 316 | return fmt.Sprintf("longhorn/%s/nodes", namespace) |
312 | 317 | } |
|
0 commit comments