Skip to content

Commit

Permalink
e2e: Collect data in case of a failure
Browse files Browse the repository at this point in the history
Signed-off-by: Or Shoval <[email protected]>
  • Loading branch information
oshoval committed Aug 13, 2024
1 parent ae2d7b3 commit 898db52
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/e2e/persistentips_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
package e2e

import (
"bytes"
"context"
"encoding/json"
"fmt"
"os"
"os/exec"
"time"

Expand All @@ -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
Expand Down Expand Up @@ -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
}

0 comments on commit 898db52

Please sign in to comment.