Skip to content

Commit

Permalink
Merge pull request #4017 from tcordeu/e2e_pod_logs
Browse files Browse the repository at this point in the history
🌱 Collect pods logs from workload clusters in E2E tests
  • Loading branch information
k8s-ci-robot authored Dec 17, 2020
2 parents 7d01abe + 380ef5d commit dadd7bd
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/framework/docker_logcollector.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ package framework
import (
"context"
"fmt"
"io/ioutil"
"os"
osExec "os/exec"
"path/filepath"
"strings"

Expand Down Expand Up @@ -54,6 +56,35 @@ func (k DockerLogCollector) CollectMachineLog(ctx context.Context, managementClu
return execOnContainer(containerName, f, command, args...)
}
}
copyDirFn := func(containerDir, dirName string) func() error {
return func() error {
f, err := ioutil.TempFile("", containerName)
if err != nil {
return err
}

tempfileName := f.Name()
outputDir := filepath.Join(outputPath, dirName)

defer os.Remove(tempfileName)

err = execOnContainer(
containerName,
f,
"tar", "--hard-dereference", "--dereference", "--directory", containerDir, "--create", "--file", "-", ".",
)
if err != nil {
return err
}

err = os.MkdirAll(outputDir, os.ModePerm)
if err != nil {
return err
}

return osExec.Command("tar", "--extract", "--file", tempfileName, "--directory", outputDir).Run()
}
}
return errors.AggregateConcurrent([]func() error{
execToPathFn(
"journal.log",
Expand All @@ -79,6 +110,7 @@ func (k DockerLogCollector) CollectMachineLog(ctx context.Context, managementClu
"containerd.log",
"journalctl", "--no-pager", "--output=short-precise", "-u", "containerd.service",
),
copyDirFn("/var/log/pods", "pods"),
})
}

Expand Down

0 comments on commit dadd7bd

Please sign in to comment.