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

@@ -75,8 +75,8 @@ var _ = SIGDescribe("Container Lifecycle Hook", func() {
e2epod.NewAgnhostContainer("container-handle-https-request", nil, httpsPorts, httpsArgs...),
)
ginkgo.BeforeEach(func() {
node, err := e2enode.GetRandomReadySchedulableNode(f.ClientSet)
ginkgo.BeforeEach(func(ctx context.Context) {
node, err := e2enode.GetRandomReadySchedulableNode(ctx, f.ClientSet)
framework.ExpectNoError(err)
targetNode = node.Name
nodeSelection := e2epod.NodeSelection{}
@@ -85,16 +85,16 @@ var _ = SIGDescribe("Container Lifecycle Hook", func() {
podClient = e2epod.NewPodClient(f)
ginkgo.By("create the container to handle the HTTPGet hook request.")
newPod := podClient.CreateSync(podHandleHookRequest)
newPod := podClient.CreateSync(ctx, podHandleHookRequest)
targetIP = newPod.Status.PodIP
targetURL = targetIP
if strings.Contains(targetIP, ":") {
targetURL = fmt.Sprintf("[%s]", targetIP)
}
})
testPodWithHook := func(podWithHook *v1.Pod) {
testPodWithHook := func(ctx context.Context, podWithHook *v1.Pod) {
ginkgo.By("create the pod with lifecycle hook")
podClient.CreateSync(podWithHook)
podClient.CreateSync(ctx, podWithHook)
const (
defaultHandler = iota
httpsHandler
@@ -107,13 +107,13 @@ var _ = SIGDescribe("Container Lifecycle Hook", func() {
handlerContainer = httpsHandler
}
}
gomega.Eventually(func() error {
return podClient.MatchContainerOutput(podHandleHookRequest.Name, podHandleHookRequest.Spec.Containers[handlerContainer].Name,
gomega.Eventually(ctx, func(ctx context.Context) error {
return podClient.MatchContainerOutput(ctx, podHandleHookRequest.Name, podHandleHookRequest.Spec.Containers[handlerContainer].Name,
`GET /echo\?msg=poststart`)
}, postStartWaitTimeout, podCheckInterval).Should(gomega.BeNil())
}
ginkgo.By("delete the pod with lifecycle hook")
podClient.DeleteSync(podWithHook.Name, *metav1.NewDeleteOptions(15), e2epod.DefaultPodDeletionTimeout)
podClient.DeleteSync(ctx, podWithHook.Name, *metav1.NewDeleteOptions(15), e2epod.DefaultPodDeletionTimeout)
if podWithHook.Spec.Containers[0].Lifecycle.PreStop != nil {
ginkgo.By("check prestop hook")
if podWithHook.Spec.Containers[0].Lifecycle.PreStop.HTTPGet != nil {
@@ -121,8 +121,8 @@ var _ = SIGDescribe("Container Lifecycle Hook", func() {
handlerContainer = httpsHandler
}
}
gomega.Eventually(func() error {
return podClient.MatchContainerOutput(podHandleHookRequest.Name, podHandleHookRequest.Spec.Containers[handlerContainer].Name,
gomega.Eventually(ctx, func(ctx context.Context) error {
return podClient.MatchContainerOutput(ctx, podHandleHookRequest.Name, podHandleHookRequest.Spec.Containers[handlerContainer].Name,
`GET /echo\?msg=prestop`)
}, preStopWaitTimeout, podCheckInterval).Should(gomega.BeNil())
}
@@ -142,7 +142,7 @@ var _ = SIGDescribe("Container Lifecycle Hook", func() {
}
podWithHook := getPodWithHook("pod-with-poststart-exec-hook", imageutils.GetE2EImage(imageutils.Agnhost), lifecycle)
testPodWithHook(podWithHook)
testPodWithHook(ctx, podWithHook)
})
/*
Release: v1.9
@@ -158,7 +158,7 @@ var _ = SIGDescribe("Container Lifecycle Hook", func() {
},
}
podWithHook := getPodWithHook("pod-with-prestop-exec-hook", imageutils.GetE2EImage(imageutils.Agnhost), lifecycle)
testPodWithHook(podWithHook)
testPodWithHook(ctx, podWithHook)
})
/*
Release: v1.9
@@ -180,7 +180,7 @@ var _ = SIGDescribe("Container Lifecycle Hook", func() {
nodeSelection := e2epod.NodeSelection{}
e2epod.SetAffinity(&nodeSelection, targetNode)
e2epod.SetNodeSelection(&podWithHook.Spec, nodeSelection)
testPodWithHook(podWithHook)
testPodWithHook(ctx, podWithHook)
})
/*
Release : v1.23
@@ -203,7 +203,7 @@ var _ = SIGDescribe("Container Lifecycle Hook", func() {
nodeSelection := e2epod.NodeSelection{}
e2epod.SetAffinity(&nodeSelection, targetNode)
e2epod.SetNodeSelection(&podWithHook.Spec, nodeSelection)
testPodWithHook(podWithHook)
testPodWithHook(ctx, podWithHook)
})
/*
Release : v1.9
@@ -225,7 +225,7 @@ var _ = SIGDescribe("Container Lifecycle Hook", func() {
nodeSelection := e2epod.NodeSelection{}
e2epod.SetAffinity(&nodeSelection, targetNode)
e2epod.SetNodeSelection(&podWithHook.Spec, nodeSelection)
testPodWithHook(podWithHook)
testPodWithHook(ctx, podWithHook)
})
/*
Release : v1.23
@@ -248,7 +248,7 @@ var _ = SIGDescribe("Container Lifecycle Hook", func() {
nodeSelection := e2epod.NodeSelection{}
e2epod.SetAffinity(&nodeSelection, targetNode)
e2epod.SetNodeSelection(&podWithHook.Spec, nodeSelection)
testPodWithHook(podWithHook)
testPodWithHook(ctx, podWithHook)
})
})
})