Skip to content

Commit

Permalink
fix: flaky e2e test (#1400)
Browse files Browse the repository at this point in the history
  • Loading branch information
banjoh authored Dec 20, 2023
1 parent f44a3d3 commit 3012b87
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/collect/goldpinger.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (c *CollectGoldpinger) runPodAndCollectGPResults(progressChan chan<- interf

var terminationError *corev1.ContainerStateTerminated
for _, status := range pod.Status.ContainerStatuses {
if status.Name == collectorContainerName {
if status.Name == collectorContainerName && status.State.Terminated != nil {
if status.State.Terminated.ExitCode != 0 {
terminationError = status.State.Terminated
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/collect/run_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,13 +467,17 @@ func deletePod(ctx context.Context, client *kubernetes.Clientset, pod *corev1.Po
})
if err != nil {
zeroGracePeriod := int64(0)
klog.V(2).Infof("Pod %s forcefully deleted after reaching the maximum wait time of %d seconds", pod.Name, constants.MAX_TIME_TO_WAIT_FOR_POD_DELETION/time.Second)
klog.V(2).Infof("Forcefully deleting pod %s after reaching the maximum wait time of %d seconds due to err=%v",
pod.Name, constants.MAX_TIME_TO_WAIT_FOR_POD_DELETION/time.Second, err,
)
if err := client.CoreV1().Pods(pod.Namespace).Delete(context.Background(), pod.Name, metav1.DeleteOptions{
GracePeriodSeconds: &zeroGracePeriod,
}); err != nil {
klog.Errorf("Failed to wait for pod %s deletion: %v", pod.Name, err)
klog.Errorf("Forced deletion of pod %s failed: %v", pod.Name, err)
return
}
klog.V(2).Infof("Pod %s in %s namespace has been deleted", pod.Name, pod.Namespace)
} else {
klog.V(2).Infof("Pod %s in %s namespace has been deleted", pod.Name, pod.Namespace)
}
}
9 changes: 7 additions & 2 deletions test/e2e/support-bundle/goldpinger_collector_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func Test_GoldpingerCollector(t *testing.T) {
}).
Assess("collect and analyse goldpinger pings", func(ctx context.Context, t *testing.T, c *envconf.Config) context.Context {
var out bytes.Buffer
var stdErr bytes.Buffer

namespace := c.Namespace()
supportBundleName := "goldpinger-test"
Expand All @@ -64,9 +65,13 @@ func Test_GoldpingerCollector(t *testing.T) {
tarPath := filepath.Join(t.TempDir(), fmt.Sprintf("%s.tar.gz", supportBundleName))
cmd := exec.CommandContext(ctx, sbBinary(), specPath, "--interactive=false", "-v=2", fmt.Sprintf("-o=%s", tarPath))
cmd.Stdout = &out
cmd.Stderr = &stdErr
err = cmd.Run()
t.Log(out.String())
require.NoError(t, err)
if err != nil {
t.Logf("Stdout: %s\n", out.String())
t.Logf("Stderr: %s\n", stdErr.String())
t.Fatal(err)
}

analysisJSON, err := readFileFromTar(tarPath, fmt.Sprintf("%s/analysis.json", supportBundleName))
require.NoError(t, err)
Expand Down

0 comments on commit 3012b87

Please sign in to comment.