From 898db523b0337419a1ca53483f28b79ef1f253f2 Mon Sep 17 00:00:00 2001 From: Or Shoval Date: Tue, 13 Aug 2024 12:32:07 +0300 Subject: [PATCH] e2e: Collect data in case of a failure Signed-off-by: Or Shoval --- test/e2e/persistentips_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/e2e/persistentips_test.go b/test/e2e/persistentips_test.go index 6d22ac7c..9e306ec4 100644 --- a/test/e2e/persistentips_test.go +++ b/test/e2e/persistentips_test.go @@ -20,9 +20,11 @@ package e2e import ( + "bytes" "context" "encoding/json" "fmt" + "os" "os/exec" "time" @@ -41,6 +43,14 @@ import ( ) var _ = Describe("Persistent IPs", func() { + JustAfterEach(func() { + if CurrentGinkgoTestDescription().Failed { + By("Test failed, collecting logs and artifacts") + podsStatus, stderr, err := kubectl("get", "pods", "-A") + fmt.Printf("kubectl get pods:\n%v\nerror:\n%v\n", podsStatus+stderr, err) + } + }) + When("network attachment definition created with allowPersistentIPs=true", func() { var ( td testenv.TestData @@ -297,3 +307,12 @@ func removeFinalizersPatch() ([]byte, error) { } return json.Marshal(patch) } + +func kubectl(command ...string) (string, string, error) { + var stdout, stderr bytes.Buffer + cmd := exec.Command(os.Getenv("KUBECTL"), command...) + cmd.Stderr = &stderr + cmd.Stdout = &stdout + err := cmd.Run() + return stdout.String(), stderr.String(), err +}