Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions test/e2e/connectivity/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,20 +253,25 @@ var _ = framework.OrderedDescribe("[group:disaster]", func() {
ginkgo.By("Waiting for DaemonSet ovs-ovn to be ready")
dsClient.RolloutStatus(ds.Name)

ginkgo.By("Getting pods of DaemonSet ovs-ovn")
pods, err = dsClient.GetPods(ds)
framework.ExpectNoError(err)

ginkgo.By("Getting newly created ovs-ovn pod running on node " + suiteCtx.Node)
for i := range pods.Items {
if pods.Items[i].Spec.NodeName == suiteCtx.Node {
pod = &pods.Items[i]
break
ginkgo.By("Waiting for newly created ovs-ovn pod running on node " + suiteCtx.Node)
pod = nil
framework.WaitUntil(2*time.Second, 2*time.Minute, func(_ context.Context) (bool, error) {
ds = dsClient.Get("ovs-ovn")
pods, err = dsClient.GetPods(ds)
if err != nil {
return false, err
}
}
framework.ExpectNotNil(pod, "no ovs-ovn pod running on node "+suiteCtx.Node)
framework.ExpectEqual(pod.Status.Phase, corev1.PodRunning)
framework.ExpectEqual(pod.Status.ContainerStatuses[0].Ready, true)
for i := range pods.Items {
if pods.Items[i].Spec.NodeName == suiteCtx.Node &&
pods.Items[i].Status.Phase == corev1.PodRunning &&
len(pods.Items[i].Status.ContainerStatuses) != 0 &&
pods.Items[i].Status.ContainerStatuses[0].Ready {
pod = &pods.Items[i]
return true, nil
}
}
Comment on lines +264 to +272
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The if condition with multiple && operators is a bit long and can be hard to read. To improve readability and maintainability, you could refactor this to first check for the pod on the correct node, and then, in a nested block, check for its readiness. This separation of concerns makes the logic clearer.

            for i := range pods.Items {
                p := &pods.Items[i]
                if p.Spec.NodeName != suiteCtx.Node {
                    continue
                }

                if p.Status.Phase == corev1.PodRunning &&
                    len(p.Status.ContainerStatuses) != 0 &&
                    p.Status.ContainerStatuses[0].Ready {
                    pod = p
                    return true, nil
                }
            }

return false, nil
}, "waiting for ovs-ovn pod on node "+suiteCtx.Node+" to be running and ready")
pod.ManagedFields = nil
framework.Logf("newly created ovs-ovn pod %s:\n%s", pod.Name, format.Object(pod, 2))
})
Expand Down
Loading