Skip to content

Commit ed7f7ce

Browse files
committed
fix race conditions in polling functions
Signed-off-by: Omer Aplatony <[email protected]>
1 parent 80ed375 commit ed7f7ce

File tree

6 files changed

+25
-25
lines changed

6 files changed

+25
-25
lines changed

staging/src/k8s.io/apiextensions-apiserver/test/integration/apiapproval_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ func TestAPIApproval(t *testing.T) {
7373
t.Fatal(err)
7474
}
7575
err = wait.PollUntilContextTimeout(context.Background(), 100*time.Millisecond, 30*time.Second, true, func(ctx context.Context) (bool, error) {
76-
approvedKubeAPI, err = apiExtensionClient.ApiextensionsV1().CustomResourceDefinitions().Get(ctx, approvedKubeAPI.Name, metav1.GetOptions{})
77-
if err != nil {
78-
return false, err
76+
approvedKubeAPI, getErr := apiExtensionClient.ApiextensionsV1().CustomResourceDefinitions().Get(ctx, approvedKubeAPI.Name, metav1.GetOptions{})
77+
if getErr != nil {
78+
return false, getErr
7979
}
8080
if approvedKubeAPIApproved := findCRDCondition(approvedKubeAPI, apiextensionsv1.KubernetesAPIApprovalPolicyConformant); approvedKubeAPIApproved == nil || approvedKubeAPIApproved.Status != apiextensionsv1.ConditionTrue {
8181
t.Log(approvedKubeAPIApproved)

staging/src/k8s.io/apiextensions-apiserver/test/integration/conversion/conversion_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,12 @@ func testWebhookConverter(t *testing.T, watchCache bool) {
220220

221221
// wait until new webhook is called the first time
222222
if err := wait.PollUntilContextTimeout(context.Background(), time.Millisecond*100, wait.ForeverTestTimeout, true, func(ctx context.Context) (done bool, err error) {
223-
_, err = ctc.versionedClient(marker.GetNamespace(), "v1alpha1").Get(ctx, marker.GetName(), metav1.GetOptions{})
223+
_, getErr := ctc.versionedClient(marker.GetNamespace(), "v1alpha1").Get(ctx, marker.GetName(), metav1.GetOptions{})
224224
select {
225225
case <-upCh:
226226
return true, nil
227227
default:
228-
t.Logf("Waiting for webhook to become effective, getting marker object: %v", err)
228+
t.Logf("Waiting for webhook to become effective, getting marker object: %v", getErr)
229229
return false, nil
230230
}
231231
}); err != nil {

staging/src/k8s.io/apiextensions-apiserver/test/integration/conversion/webhook.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ func StartConversionWebhookServer(handler http.Handler) (func(), *apiextensionsv
6565

6666
// StartTLS returns immediately, there is a small chance of a race to avoid.
6767
if err := wait.PollUntilContextTimeout(context.Background(), time.Millisecond*100, wait.ForeverTestTimeout, true, func(ctx context.Context) (done bool, err error) {
68-
_, err = webhookServer.Client().Get(webhookServer.URL) // even a 404 is fine
69-
return err == nil, nil
68+
_, getErr := webhookServer.Client().Get(webhookServer.URL) // even a 404 is fine
69+
return getErr == nil, nil
7070
}); err != nil {
7171
webhookServer.Close()
7272
return nil, nil, err

staging/src/k8s.io/apiextensions-apiserver/test/integration/listtype_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,15 @@ func TestListTypes(t *testing.T) {
210210

211211
t.Logf("Updating again with invalid values, eventually successfully due to ratcheting logic")
212212
err = wait.PollUntilContextTimeout(context.Background(), time.Millisecond*100, wait.ForeverTestTimeout, true, func(ctx context.Context) (bool, error) {
213-
_, err = fooClient.Update(ctx, modifiedInstance, metav1.UpdateOptions{})
214-
if err == nil {
215-
return true, err
213+
_, updateErr := fooClient.Update(ctx, modifiedInstance, metav1.UpdateOptions{})
214+
if updateErr == nil {
215+
return true, nil
216216
}
217-
if errors.IsInvalid(err) {
217+
if errors.IsInvalid(updateErr) {
218218
// wait until modifiedInstance becomes valid again
219219
return false, nil
220220
}
221-
return false, err
221+
return false, updateErr
222222
})
223223
if err != nil {
224224
t.Fatalf("unexpected error: %v", err)

staging/src/k8s.io/apiextensions-apiserver/test/integration/validation_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -779,14 +779,14 @@ func TestCRValidationOnCRDUpdate(t *testing.T) {
779779

780780
// CR is now accepted
781781
err = wait.PollUntilContextTimeout(context.Background(), 500*time.Millisecond, wait.ForeverTestTimeout, true, func(ctx context.Context) (done bool, err error) {
782-
_, err = noxuResourceClient.Create(ctx, instanceToCreate, metav1.CreateOptions{})
783-
if _, isStatus := err.(*apierrors.StatusError); isStatus {
784-
if apierrors.IsInvalid(err) {
782+
_, createErr := noxuResourceClient.Create(ctx, instanceToCreate, metav1.CreateOptions{})
783+
if _, isStatus := createErr.(*apierrors.StatusError); isStatus {
784+
if apierrors.IsInvalid(createErr) {
785785
return false, nil
786786
}
787787
}
788-
if err != nil {
789-
return false, err
788+
if createErr != nil {
789+
return false, createErr
790790
}
791791
return true, nil
792792
})

staging/src/k8s.io/apiextensions-apiserver/test/integration/versioning_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@ func TestInternalVersionIsHandlerVersion(t *testing.T) {
9292
patch := []byte(fmt.Sprintf(`{"i": %d}`, i))
9393
i++
9494

95-
_, err = noxuNamespacedResourceClientV1beta1.Patch(ctx, "foo", types.MergePatchType, patch, metav1.PatchOptions{})
96-
if err != nil {
95+
_, patchErr := noxuNamespacedResourceClientV1beta1.Patch(ctx, "foo", types.MergePatchType, patch, metav1.PatchOptions{})
96+
if patchErr != nil {
9797
// work around "grpc: the client connection is closing" error
9898
// TODO: fix the grpc error
99-
if err, ok := err.(*errors.StatusError); ok && err.Status().Code == http.StatusInternalServerError {
99+
if statusErr, ok := patchErr.(*errors.StatusError); ok && statusErr.Status().Code == http.StatusInternalServerError {
100100
return false, nil
101101
}
102-
return false, err
102+
return false, patchErr
103103
}
104104
return true, nil
105105
})
@@ -115,16 +115,16 @@ func TestInternalVersionIsHandlerVersion(t *testing.T) {
115115
patch := []byte(fmt.Sprintf(`{"i": %d}`, i))
116116
i++
117117

118-
_, err = noxuNamespacedResourceClientV1beta2.Patch(ctx, "foo", types.MergePatchType, patch, metav1.PatchOptions{})
119-
assert.Error(t, err)
118+
_, patchErr := noxuNamespacedResourceClientV1beta2.Patch(ctx, "foo", types.MergePatchType, patch, metav1.PatchOptions{})
119+
assert.Error(t, patchErr)
120120

121121
// work around "grpc: the client connection is closing" error
122122
// TODO: fix the grpc error
123-
if err, ok := err.(*errors.StatusError); ok && err.Status().Code == http.StatusInternalServerError {
123+
if statusErr, ok := patchErr.(*errors.StatusError); ok && statusErr.Status().Code == http.StatusInternalServerError {
124124
return false, nil
125125
}
126126

127-
assert.ErrorContains(t, err, "apiVersion")
127+
assert.ErrorContains(t, patchErr, "apiVersion")
128128
return true, nil
129129
})
130130
assert.NoError(t, err)

0 commit comments

Comments
 (0)