Skip to content

Commit

Permalink
test(e2e): print kube state on failure (#9164)
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Dyszkiewicz <[email protected]>
  • Loading branch information
jakubdyszkiewicz authored Feb 7, 2024
1 parent 5299ab6 commit 04bf390
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
5 changes: 4 additions & 1 deletion test/e2e_env/kubernetes/kubernetes_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ var _ = E2ESynchronizedBeforeSuite(kubernetes.SetupAndGetState, kubernetes.Resto
// Otherwise, we would close port-forward to the CP and remaining tests executed in different processes may fail.
var _ = SynchronizedAfterSuite(func() {}, func() {})

var _ = ReportAfterSuite("cp logs", kubernetes.PrintCPLogsOnFailure)
var (
_ = ReportAfterSuite("cp logs", kubernetes.PrintCPLogsOnFailure)
_ = ReportAfterSuite("kube state", kubernetes.PrintKubeState)
)

var (
_ = Describe("Virtual Probes", healthcheck.VirtualProbes, Ordered)
Expand Down
1 change: 1 addition & 0 deletions test/e2e_env/multizone/multizone_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var (
}
})
_ = ReportAfterSuite("cp logs", multizone.PrintCPLogsOnFailure)
_ = ReportAfterSuite("kube state", multizone.PrintKubeState)
)

var (
Expand Down
10 changes: 10 additions & 0 deletions test/framework/envs/kubernetes/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package kubernetes
import (
"encoding/json"

"github.com/gruntwork-io/terratest/modules/k8s"
"github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

Expand Down Expand Up @@ -82,3 +83,12 @@ func PrintCPLogsOnFailure(report ginkgo.Report) {
}
}
}

func PrintKubeState(report ginkgo.Report) {
if !report.SuiteSucceeded {
// just running it, prints the logs
if err := k8s.RunKubectlE(Cluster.GetTesting(), Cluster.GetKubectlOptions(), "get", "pods", "-A"); err != nil {
framework.Logf("could not retrieve kube pods")
}
}
}
29 changes: 22 additions & 7 deletions test/framework/envs/multizone/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"sync"

"github.com/gruntwork-io/terratest/modules/k8s"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

Expand Down Expand Up @@ -272,13 +273,27 @@ func RestoreState(bytes []byte) {
}

func PrintCPLogsOnFailure(report Report) {
for _, cluster := range append(Zones(), Global) {
Logf("\n\n\n\n\nCP logs of: " + cluster.Name())
logs, err := cluster.GetKumaCPLogs()
if err != nil {
Logf("could not retrieve cp logs")
} else {
Logf(logs)
if !report.SuiteSucceeded {
for _, cluster := range append(Zones(), Global) {
Logf("\n\n\n\n\nCP logs of: " + cluster.Name())
logs, err := cluster.GetKumaCPLogs()
if err != nil {
Logf("could not retrieve cp logs")
} else {
Logf(logs)
}
}
}
}

func PrintKubeState(report Report) {
if !report.SuiteSucceeded {
for _, cluster := range []Cluster{KubeZone1, KubeZone2} {
Logf("Kube state of cluster: " + cluster.Name())
// just running it, prints the logs
if err := k8s.RunKubectlE(cluster.GetTesting(), cluster.GetKubectlOptions(), "get", "pods", "-A"); err != nil {
framework.Logf("could not retrieve kube pods")
}
}
}
}

0 comments on commit 04bf390

Please sign in to comment.