Skip to content

Commit

Permalink
test: Report an error message when a pod fails in a cmd test
Browse files Browse the repository at this point in the history
The logic for testing for pod failure lost the reason why, so no
debug output was possible. Instead, update the one shot pod to
capture fallback logs and then have the executor report that as
the error message.

E.g.

    Jul 22 20:13:43.152: INFO: pod "test-cmd" errored trying to run the command: <nil>

because err was nil in the context it was invoked
  • Loading branch information
smarterclayton committed Jul 23, 2020
1 parent 41ac895 commit 6701996
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions test/extended/util/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net"
Expand Down Expand Up @@ -1658,9 +1659,9 @@ func RunOneShotCommandPod(
return false, nil
}

if podHasErrored(cmdPod) {
if err := podHasErrored(cmdPod); err != nil {
e2e.Logf("pod %q errored trying to run the command: %v", pod.Name, err)
return false, nil
return false, err
}
return podHasCompleted(cmdPod), nil
})
Expand Down Expand Up @@ -1693,10 +1694,13 @@ func podHasCompleted(pod *corev1.Pod) bool {
pod.Status.ContainerStatuses[0].State.Terminated.Reason == "Completed"
}

func podHasErrored(pod *corev1.Pod) bool {
return len(pod.Status.ContainerStatuses) > 0 &&
func podHasErrored(pod *corev1.Pod) error {
if len(pod.Status.ContainerStatuses) > 0 &&
pod.Status.ContainerStatuses[0].State.Terminated != nil &&
pod.Status.ContainerStatuses[0].State.Terminated.Reason == "Error"
pod.Status.ContainerStatuses[0].State.Terminated.Reason == "Error" {
return errors.New(pod.Status.ContainerStatuses[0].State.Terminated.Message)
}
return nil
}

func getPodLogs(oc *CLI, pod *corev1.Pod) (string, error) {
Expand All @@ -1722,13 +1726,14 @@ func newCommandPod(name, image, command string, args []string, volumeMounts []co
RestartPolicy: corev1.RestartPolicyOnFailure,
Containers: []corev1.Container{
{
Name: name,
Image: image,
Command: []string{command},
Args: args,
VolumeMounts: volumeMounts,
ImagePullPolicy: "Always",
Env: env,
Name: name,
Image: image,
Command: []string{command},
Args: args,
VolumeMounts: volumeMounts,
ImagePullPolicy: "Always",
Env: env,
TerminationMessagePolicy: corev1.TerminationMessageFallbackToLogsOnError,
},
},
},
Expand Down

0 comments on commit 6701996

Please sign in to comment.