e2e: use Ginkgo context

All code must use the context from Ginkgo when doing API calls or polling for a
change, otherwise the code would not return immediately when the test gets
aborted.
This commit is contained in:
Patrick Ohly
2022-12-12 10:11:10 +01:00
parent bf1d1dfd0f
commit 2f6c4f5eab
418 changed files with 11489 additions and 11369 deletions

View File

@@ -92,7 +92,7 @@ var _ = common.SIGDescribe("ClusterDns [Feature:Example]", func() {
for i := range namespaces {
var err error
namespaceName := fmt.Sprintf("dnsexample%d", i)
namespaces[i], err = f.CreateNamespace(namespaceName, nil)
namespaces[i], err = f.CreateNamespace(ctx, namespaceName, nil)
framework.ExpectNoError(err, "failed to create namespace: %s", namespaceName)
}
@@ -106,21 +106,21 @@ var _ = common.SIGDescribe("ClusterDns [Feature:Example]", func() {
// wait for objects
for _, ns := range namespaces {
e2eresource.WaitForControlledPodsRunning(c, ns.Name, backendName, api.Kind("ReplicationController"))
e2enetwork.WaitForService(c, ns.Name, backendName, true, framework.Poll, framework.ServiceStartTimeout)
e2eresource.WaitForControlledPodsRunning(ctx, c, ns.Name, backendName, api.Kind("ReplicationController"))
framework.ExpectNoError(e2enetwork.WaitForService(ctx, c, ns.Name, backendName, true, framework.Poll, framework.ServiceStartTimeout))
}
// it is not enough that pods are running because they may be set to running, but
// the application itself may have not been initialized. Just query the application.
for _, ns := range namespaces {
label := labels.SelectorFromSet(labels.Set(map[string]string{"name": backendName}))
options := metav1.ListOptions{LabelSelector: label.String()}
pods, err := c.CoreV1().Pods(ns.Name).List(context.TODO(), options)
pods, err := c.CoreV1().Pods(ns.Name).List(ctx, options)
framework.ExpectNoError(err, "failed to list pods in namespace: %s", ns.Name)
err = e2epod.PodsResponding(c, ns.Name, backendName, false, pods)
err = e2epod.PodsResponding(ctx, c, ns.Name, backendName, false, pods)
framework.ExpectNoError(err, "waiting for all pods to respond")
framework.Logf("found %d backend pods responding in namespace %s", len(pods.Items), ns.Name)
err = waitForServiceResponding(c, ns.Name, backendName)
err = waitForServiceResponding(ctx, c, ns.Name, backendName)
framework.ExpectNoError(err, "waiting for the service to respond")
}
@@ -134,7 +134,7 @@ var _ = common.SIGDescribe("ClusterDns [Feature:Example]", func() {
// This code is probably unnecessary, but let's stay on the safe side.
label := labels.SelectorFromSet(labels.Set(map[string]string{"name": backendName}))
options := metav1.ListOptions{LabelSelector: label.String()}
pods, err := c.CoreV1().Pods(namespaces[0].Name).List(context.TODO(), options)
pods, err := c.CoreV1().Pods(namespaces[0].Name).List(ctx, options)
if err != nil || pods == nil || len(pods.Items) == 0 {
framework.Failf("no running pods found")
@@ -155,7 +155,7 @@ var _ = common.SIGDescribe("ClusterDns [Feature:Example]", func() {
// wait until the pods have been scheduler, i.e. are not Pending anymore. Remember
// that we cannot wait for the pods to be running because our pods terminate by themselves.
for _, ns := range namespaces {
err := e2epod.WaitForPodNotPending(c, ns.Name, frontendName)
err := e2epod.WaitForPodNotPending(ctx, c, ns.Name, frontendName)
framework.ExpectNoError(err)
}
@@ -168,17 +168,17 @@ var _ = common.SIGDescribe("ClusterDns [Feature:Example]", func() {
})
// waitForServiceResponding waits for the service to be responding.
func waitForServiceResponding(c clientset.Interface, ns, name string) error {
func waitForServiceResponding(ctx context.Context, c clientset.Interface, ns, name string) error {
ginkgo.By(fmt.Sprintf("trying to dial the service %s.%s via the proxy", ns, name))
return wait.PollImmediate(framework.Poll, RespondingTimeout, func() (done bool, err error) {
return wait.PollImmediateWithContext(ctx, framework.Poll, RespondingTimeout, func(ctx context.Context) (done bool, err error) {
proxyRequest, errProxy := e2eservice.GetServicesProxyRequest(c, c.CoreV1().RESTClient().Get())
if errProxy != nil {
framework.Logf("Failed to get services proxy request: %v:", errProxy)
return false, nil
}
ctx, cancel := context.WithTimeout(context.Background(), framework.SingleCallTimeout)
ctx, cancel := context.WithTimeout(ctx, framework.SingleCallTimeout)
defer cancel()
body, err := proxyRequest.Namespace(ns).