func (h *Hvnr) RetrieveLogs(parallelDownloads int, target string, includeConfigFiles bool) error {
	if absolute, err := filepath.Abs(target); err == nil {
		target = absolute
	}
	type task struct {
		assignment string
		pod        *corev1.Pod
		baseDir    string
	}
	tasks := make(chan *task)
	errors := []error{}
	var wg sync.WaitGroup
	wg.Add(parallelDownloads)
	for i := 0; i < parallelDownloads; i++ {
		go func() {
			defer wg.Done()
			for task := range tasks {
				switch task.assignment {
				case "known-logs":
					for _, err := range h.retrieveFilesFromPod(task.pod, task.baseDir, logFinds) {
						switch err {
						case io.EOF, gzip.ErrHeader, gzip.ErrChecksum:
							continue
						}
						if err != nil {
							errors = append(errors, err)
						}
					}
				case "config-files":
					for _, err := range h.retrieveFilesFromPod(task.pod, task.baseDir, cfgFinds) {
						switch err {
						case io.EOF, gzip.ErrHeader, gzip.ErrChecksum:
							continue
						}
						if err != nil {
							errors = append(errors, err)
						}
					}
				case "container-logs":
					errors = append(
						errors,
						h.retrieveContainerLogs(task.pod, task.baseDir)...,
					)
				case "describe-pods":
					if err := h.writeDescribePodToDisk(task.pod, task.baseDir); err != nil {
						errors = append(errors, err)
					}
				case "store-yaml":
					if err := h.saveDeploymentYAML(task.pod, task.baseDir); err != nil {
						errors = append(errors, err)
					}
				}
			}
		}()
	}
	pods, err := h.ListPods()
	if err != nil {
		return err
	}
	sort.Slice(pods, func(i, j int) bool {
		return pods[i].CreationTimestamp.
			After(pods[j].CreationTimestamp.Time)
	})
	var clusterName = h.ClusterName()
	for idx := range pods {
		pod := pods[idx]
		baseDir := filepath.Join(
			target,
			LogDirName,
			clusterName,
			pod.Namespace,
		)
		if err := createDirectory(filepath.Join(baseDir, pod.Name)); err != nil {
			return err
		}
		tasks <- &task{
			assignment: "describe-pods",
			pod:        pod,
			baseDir:    baseDir,
		}
		tasks <- &task{
			assignment: "store-yaml",
			pod:        pod,
			baseDir:    baseDir,
		}
		tasks <- &task{
			assignment: "container-logs",
			pod:        pod,
			baseDir:    filepath.Join(baseDir, pod.Name, "container-logs"),
		}
		if pod.Status.Phase == corev1.PodRunning {
			tasks <- &task{
				assignment: "known-logs",
				pod:        pod,
				baseDir:    filepath.Join(baseDir, pod.Name, "container-filesystem"),
			}
			if includeConfigFiles {
				tasks <- &task{
					assignment: "config-files",
					pod:        pod,
					baseDir:    filepath.Join(baseDir, pod.Name, "container-filesystem"),
				}
			}
		}
	}
	close(tasks)
	wg.Wait()
	if len(errors) > 0 {
		return wrap.Errors(errors, "failed to retrieve logs from cluster")
	}
	return nil
}
RetrieveLogs downloads log and configuration files from some well known location of all the pods
of all the namespaces and stored them in the local file system.
package havener
import (
	"archive/tar"
	"bytes"
	"compress/gzip"
	"context"
	"fmt"
	"io"
	"io/ioutil"
	"os"
	"path/filepath"
	"sort"
	"strconv"
	"strings"
	"sync"
	"github.com/gonvenience/wrap"
	corev1 "k8s.io/api/core/v1"
	"k8s.io/apimachinery/pkg/runtime/schema"
	"k8s.io/cli-runtime/pkg/printers"
	"k8s.io/client-go/rest"
)
const LogDirName = "retrieved-logs"
var logFinds = []string{
	"find var/vcap/sys -type f -name '*.log' -size +0c 2>/dev/null",
	"find var/vcap/sys -type f -name '*.log.*' -size +0c 2>/dev/null",
	"find var/vcap/monit -type f -size +0c 2>/dev/null",
	"find var/log -type f -size +0c 2>/dev/null",
}
var cfgFinds = []string{
	"find var/vcap/jobs -type f -size +0c 2>/dev/null",
	"find etc/nginx -type f -size +0c 2>/dev/null",
	"find opt/fissile -type f -size +0c 2>/dev/null",
}
const retrieveScript = `
#!/bin/sh
FILES="$(cd / && %s)"
if [ ! -z "${FILES}" ]; then
  (cd / && ls -1Sr ${FILES}) | while read -r FILENAME; do
    case "${FILENAME}" in
      *log)
        echo "${FILENAME}"
        ;;
      *)
        case "$(file --brief --mime-type "${FILENAME}")" in
          text/*)
            echo "${FILENAME}"
            ;;
        esac
        ;;
    esac
  done | GZIP=-9 tar --create --gzip --file=- --files-from=- || true
fi
`
func createDirectory(path string) error {
	if _, err := os.Stat(path); err != nil {
		if err := os.MkdirAll(path, 0755); err != nil {
			return err
		}
	}
	return nil
}