Merge pull request #118977 from dims/copy-container-logs-for-easier-debugging

Copy container logs for easier debugging
This commit is contained in:
Kubernetes Prow Robot 2023-06-29 12:09:43 -07:00 committed by GitHub
commit 3180aa4272
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -207,22 +207,31 @@ func getTestArtifacts(host, testDir string) error {
if err := os.MkdirAll(logPath, 0755); err != nil {
return fmt.Errorf("failed to create log directory %q: %w", logPath, err)
}
// Copy logs to artifacts/hostname
// Copy logs (if any) to artifacts/hostname
if _, err := SSH(host, "ls", fmt.Sprintf("%s:%s/results/*.log", GetHostnameOrIP(host), testDir)); err == nil {
if _, err := runSSHCommand(host, "scp", "-r", fmt.Sprintf("%s:%s/results/*.log", GetHostnameOrIP(host), testDir), logPath); err != nil {
return err
}
}
// Copy json files (if any) to artifacts.
if _, err := SSH(host, "ls", fmt.Sprintf("%s/results/*.json", testDir)); err == nil {
if _, err = runSSHCommand(host, "scp", "-r", fmt.Sprintf("%s:%s/results/*.json", GetHostnameOrIP(host), testDir), *resultsDir); err != nil {
return err
}
}
// Copy junit results (if any) to artifacts
if _, err := SSH(host, "ls", fmt.Sprintf("%s/results/junit*", testDir)); err == nil {
// Copy junit (if any) to the top of artifacts
if _, err = runSSHCommand(host, "scp", fmt.Sprintf("%s:%s/results/junit*", GetHostnameOrIP(host), testDir), *resultsDir); err != nil {
return err
}
}
// Copy container logs to artifacts/hostname
if _, err := SSH(host, "chmod", "-R", "a+r", "/var/log/pods"); err == nil {
if _, err = runSSHCommand(host, "scp", "-r", fmt.Sprintf("%s:/var/log/pods/", GetHostnameOrIP(host)), logPath); err != nil {
return err
}
}
return nil
}