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

@@ -42,7 +42,7 @@ const (
)
// proxyPostRequest performs a post on a node proxy endpoint given the nodename and rest client.
func proxyPostRequest(c clientset.Interface, node, endpoint string, port int) (restclient.Result, error) {
func proxyPostRequest(ctx context.Context, c clientset.Interface, node, endpoint string, port int) (restclient.Result, error) {
// proxy tends to hang in some cases when Node is not ready. Add an artificial timeout for this call. #22165
var result restclient.Result
finished := make(chan struct{}, 1)
@@ -52,13 +52,15 @@ func proxyPostRequest(c clientset.Interface, node, endpoint string, port int) (r
SubResource("proxy").
Name(fmt.Sprintf("%v:%v", node, port)).
Suffix(endpoint).
Do(context.TODO())
Do(ctx)
finished <- struct{}{}
}()
select {
case <-finished:
return result, nil
case <-ctx.Done():
return restclient.Result{}, nil
case <-time.After(proxyTimeout):
return restclient.Result{}, nil
}
@@ -70,7 +72,7 @@ var _ = SIGDescribe("Checkpoint Container [NodeFeature:CheckpointContainer]", fu
ginkgo.It("will checkpoint a container out of a pod", func(ctx context.Context) {
ginkgo.By("creating a target pod")
podClient := e2epod.NewPodClient(f)
pod := podClient.CreateSync(&v1.Pod{
pod := podClient.CreateSync(ctx, &v1.Pod{
ObjectMeta: metav1.ObjectMeta{Name: "checkpoint-container-pod"},
Spec: v1.PodSpec{
Containers: []v1.Container{
@@ -85,7 +87,7 @@ var _ = SIGDescribe("Checkpoint Container [NodeFeature:CheckpointContainer]", fu
})
p, err := podClient.Get(
context.TODO(),
ctx,
pod.Name,
metav1.GetOptions{},
)
@@ -105,6 +107,7 @@ var _ = SIGDescribe("Checkpoint Container [NodeFeature:CheckpointContainer]", fu
pod.Spec.NodeName,
)
result, err := proxyPostRequest(
ctx,
f.ClientSet,
pod.Spec.NodeName,
fmt.Sprintf(