mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-18 02:50:30 +00:00
e2e: retry getting Pods before executing commands
On occasion the Pods have not been (re)started before they get listed. This can result in an empty list. It can occur during RBD testing where Pods are restarted before `uname` is executed. In case the Pods are not available yet, the test will fail with the "podlist is empty" error. By adding a retry when the list of Pods is empty, the tests should become a little more stable. Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
parent
9f08cb7ea0
commit
bfef0279a7
26
e2e/pod.go
26
e2e/pod.go
@ -91,13 +91,31 @@ func waitForDaemonSets(name, ns string, c kubernetes.Interface, t int) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func findPodAndContainerName(f *framework.Framework, ns, cn string, opt *metav1.ListOptions) (string, string, error) {
|
func findPodAndContainerName(f *framework.Framework, ns, cn string, opt *metav1.ListOptions) (string, string, error) {
|
||||||
podList, err := f.PodClientNS(ns).List(context.TODO(), *opt)
|
timeout := time.Duration(deployTimeout) * time.Minute
|
||||||
if err != nil {
|
|
||||||
return "", "", err
|
var (
|
||||||
|
podList *v1.PodList
|
||||||
|
listErr error
|
||||||
|
)
|
||||||
|
err := wait.PollImmediate(poll, timeout, func() (bool, error) {
|
||||||
|
podList, listErr = f.PodClientNS(ns).List(context.TODO(), *opt)
|
||||||
|
if listErr != nil {
|
||||||
|
if isRetryableAPIError(listErr) {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return false, fmt.Errorf("failed to list Pods: %w", listErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(podList.Items) == 0 {
|
if len(podList.Items) == 0 {
|
||||||
return "", "", errors.New("podlist is empty")
|
// retry in case the pods have not been (re)started yet
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return true, nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return "", "", fmt.Errorf("failed to find pod for %v: %w", opt, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if cn != "" {
|
if cn != "" {
|
||||||
|
Loading…
Reference in New Issue
Block a user