e2e: consolidate pod response checking

This renames PodsResponding to WaitForPodsResponding for the sake of
consistency and adds a timeout parameter. That is necessary because some other
users of NewProxyResponseChecker used a much lower timeout (2min vs. 15min).

Besides simplifying some code, it also makes it easier to rewrite
ProxyResponseChecker because it only gets used in WaitForPodsResponding.
This commit is contained in:
Patrick Ohly 2023-01-20 13:07:42 +01:00
parent 89a5d6d8af
commit c3266cde77
5 changed files with 11 additions and 23 deletions

View File

@ -27,7 +27,6 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors" apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
utilrand "k8s.io/apimachinery/pkg/util/rand" utilrand "k8s.io/apimachinery/pkg/util/rand"
@ -528,13 +527,7 @@ func TestReplicationControllerServeImageOrFail(ctx context.Context, f *framework
// Verify that something is listening. // Verify that something is listening.
framework.Logf("Trying to dial the pod") framework.Logf("Trying to dial the pod")
retryTimeout := 2 * time.Minute framework.ExpectNoError(e2epod.WaitForPodsResponding(ctx, f.ClientSet, f.Namespace.Name, name, true, 2*time.Minute, pods))
retryInterval := 5 * time.Second
label := labels.SelectorFromSet(labels.Set(map[string]string{"name": name}))
err = wait.PollWithContext(ctx, retryInterval, retryTimeout, e2epod.NewProxyResponseChecker(f.ClientSet, f.Namespace.Name, label, name, true, pods).CheckAllResponses)
if err != nil {
framework.Failf("Did not get expected responses within the timeout period of %.2f seconds.", retryTimeout.Seconds())
}
} }
// 1. Create a quota restricting pods in the current namespace to 2. // 1. Create a quota restricting pods in the current namespace to 2.

View File

@ -225,13 +225,7 @@ func testReplicaSetServeImageOrFail(ctx context.Context, f *framework.Framework,
// Verify that something is listening. // Verify that something is listening.
framework.Logf("Trying to dial the pod") framework.Logf("Trying to dial the pod")
retryTimeout := 2 * time.Minute framework.ExpectNoError(e2epod.WaitForPodsResponding(ctx, f.ClientSet, f.Namespace.Name, name, true, 2*time.Minute, pods))
retryInterval := 5 * time.Second
label := labels.SelectorFromSet(labels.Set(map[string]string{"name": name}))
err = wait.PollWithContext(ctx, retryInterval, retryTimeout, e2epod.NewProxyResponseChecker(f.ClientSet, f.Namespace.Name, label, name, true, pods).CheckAllResponses)
if err != nil {
framework.Failf("Did not get expected responses within the timeout period of %.2f seconds.", retryTimeout.Seconds())
}
} }
// 1. Create a quota restricting pods in the current namespace to 2. // 1. Create a quota restricting pods in the current namespace to 2.

View File

@ -204,10 +204,7 @@ func podRunningMaybeResponding(ctx context.Context, c clientset.Interface, ns, n
return fmt.Errorf("failed to wait for pods running: %v", e) return fmt.Errorf("failed to wait for pods running: %v", e)
} }
if checkResponding { if checkResponding {
err = PodsResponding(ctx, c, ns, name, wantName, pods) return WaitForPodsResponding(ctx, c, ns, name, wantName, podRespondingTimeout, pods)
if err != nil {
return fmt.Errorf("failed to wait for pods responding: %v", err)
}
} }
return nil return nil
} }

View File

@ -582,10 +582,14 @@ func WaitForPodNotFoundInNamespace(ctx context.Context, c clientset.Interface, p
} }
// PodsResponding waits for the pods to response. // PodsResponding waits for the pods to response.
func PodsResponding(ctx context.Context, c clientset.Interface, ns, name string, wantName bool, pods *v1.PodList) error { func WaitForPodsResponding(ctx context.Context, c clientset.Interface, ns string, controllerName string, wantName bool, timeout time.Duration, pods *v1.PodList) error {
if timeout == 0 {
timeout = podRespondingTimeout
}
ginkgo.By("trying to dial each unique pod") ginkgo.By("trying to dial each unique pod")
label := labels.SelectorFromSet(labels.Set(map[string]string{"name": name})) label := labels.SelectorFromSet(labels.Set(map[string]string{"name": controllerName}))
err := wait.PollImmediateWithContext(ctx, framework.PollInterval(), podRespondingTimeout, NewProxyResponseChecker(c, ns, label, name, wantName, pods).CheckAllResponses)
err := wait.PollImmediateWithContext(ctx, framework.PollInterval(), timeout, NewProxyResponseChecker(c, ns, label, controllerName, wantName, pods).CheckAllResponses)
return maybeTimeoutError(err, "waiting for pods to be responsive") return maybeTimeoutError(err, "waiting for pods to be responsive")
} }

View File

@ -116,7 +116,7 @@ var _ = common.SIGDescribe("ClusterDns [Feature:Example]", func() {
options := metav1.ListOptions{LabelSelector: label.String()} options := metav1.ListOptions{LabelSelector: label.String()}
pods, err := c.CoreV1().Pods(ns.Name).List(ctx, options) pods, err := c.CoreV1().Pods(ns.Name).List(ctx, options)
framework.ExpectNoError(err, "failed to list pods in namespace: %s", ns.Name) framework.ExpectNoError(err, "failed to list pods in namespace: %s", ns.Name)
err = e2epod.PodsResponding(ctx, c, ns.Name, backendName, false, pods) err = e2epod.WaitForPodsResponding(ctx, c, ns.Name, backendName, false, 0, pods)
framework.ExpectNoError(err, "waiting for all pods to respond") framework.ExpectNoError(err, "waiting for all pods to respond")
framework.Logf("found %d backend pods responding in namespace %s", len(pods.Items), ns.Name) framework.Logf("found %d backend pods responding in namespace %s", len(pods.Items), ns.Name)