-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Print logs and events on test failure (#2347)
Problem: When the tests fail we don't have any outputs from the containers or the k8s events. Solution: Print logs and outputs on failure.
- Loading branch information
Showing
6 changed files
with
94 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package framework | ||
|
||
import ( | ||
"fmt" | ||
|
||
core "k8s.io/api/core/v1" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
func GetLogs(rm ResourceManager, namespace string, releaseName string) string { | ||
var returnLogs string | ||
pods, err := rm.GetPods(namespace, client.MatchingLabels{ | ||
"app.kubernetes.io/instance": releaseName, | ||
}) | ||
if err != nil { | ||
return fmt.Sprintf("failed to get pods: %v", err) | ||
} | ||
|
||
for _, pod := range pods { | ||
for _, container := range pod.Spec.Containers { | ||
returnLogs += fmt.Sprintf("Logs for container %s:\n", container.Name) | ||
logs, err := rm.GetPodLogs(pod.Namespace, pod.Name, &core.PodLogOptions{ | ||
Container: container.Name, | ||
}) | ||
if err != nil { | ||
returnLogs += fmt.Sprintf(" failed to get logs: %v\n", err) | ||
continue | ||
} | ||
returnLogs += fmt.Sprintf(" %s\n", logs) | ||
} | ||
} | ||
return returnLogs | ||
} | ||
|
||
func GetEvents(rm ResourceManager, namespace string) string { | ||
var returnEvents string | ||
events, err := rm.GetEvents(namespace) | ||
if err != nil { | ||
return fmt.Sprintf("failed to get events: %v", err) | ||
} | ||
|
||
eventGroups := make(map[string][]core.Event) | ||
for _, event := range events.Items { | ||
eventGroups[event.InvolvedObject.Name] = append(eventGroups[event.InvolvedObject.Name], event) | ||
} | ||
|
||
for name, events := range eventGroups { | ||
returnEvents += fmt.Sprintf("Events for %s:\n", name) | ||
for _, event := range events { | ||
returnEvents += fmt.Sprintf(" %s\n", event.Message) | ||
} | ||
returnEvents += "\n" | ||
} | ||
return returnEvents | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eo pipefail | ||
set -o pipefail | ||
|
||
source scripts/vars.env | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eo pipefail | ||
set -o pipefail | ||
|
||
source scripts/vars.env | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters