Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions pkg/collect/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ func getPodLogs(client *kubernetes.Clientset, pod corev1.Pod, name, container st
}
}

fileKey := fmt.Sprintf("%s/%s", name, pod.Name)
if container != "" {
fileKey = fmt.Sprintf("%s/%s/%s", name, pod.Name, container)
}

result := make(map[string][]byte)

req := client.CoreV1().Pods(pod.Namespace).GetLogs(pod.Name, &podLogOpts)
podLogs, err := req.Stream()
if err != nil {
Expand All @@ -137,15 +144,25 @@ func getPodLogs(client *kubernetes.Clientset, pod corev1.Pod, name, container st
if err != nil {
return nil, errors.Wrap(err, "failed to copy log")
}
result[fileKey+".log"] = buf.Bytes()

fileKey := fmt.Sprintf("%s/%s.txt", name, pod.Name)
if container != "" {
fileKey = fmt.Sprintf("%s/%s/%s.txt", name, pod.Name, container)
podLogOpts.Previous = true
req = client.CoreV1().Pods(pod.Namespace).GetLogs(pod.Name, &podLogOpts)
podLogs, err = req.Stream()
if err != nil {
// maybe fail on !kuberneteserrors.IsNotFound(err)?
return result, nil
}
defer podLogs.Close()

buf = new(bytes.Buffer)
_, err = io.Copy(buf, podLogs)
if err != nil {
return nil, errors.Wrap(err, "failed to copy previous log")
}
result[fileKey+"-previous.log"] = buf.Bytes()

return map[string][]byte{
fileKey: buf.Bytes(),
}, nil
return result, nil
}

func (l LogsOutput) Redact() (LogsOutput, error) {
Expand Down