@@ -4,25 +4,22 @@ import (
4
4
"context"
5
5
"errors"
6
6
"fmt"
7
- "github.com/kubernetes-csi/external-resizer/pkg/util"
8
- "google.golang.org/grpc/codes"
9
- "google.golang.org/grpc/status"
10
- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11
- "k8s.io/client-go/tools/cache"
12
7
"testing"
13
8
"time"
14
9
15
- "github.com/kubernetes-csi/external-resizer/pkg/features"
16
-
17
- "k8s.io/client-go/util/workqueue"
18
-
19
10
"github.com/kubernetes-csi/external-resizer/pkg/csi"
11
+ "github.com/kubernetes-csi/external-resizer/pkg/features"
20
12
"github.com/kubernetes-csi/external-resizer/pkg/modifier"
21
-
13
+ "github.com/kubernetes-csi/external-resizer/pkg/util"
14
+ "google.golang.org/grpc/codes"
15
+ "google.golang.org/grpc/status"
22
16
v1 "k8s.io/api/core/v1"
23
17
storagev1beta1 "k8s.io/api/storage/v1beta1"
18
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24
19
"k8s.io/apimachinery/pkg/runtime"
25
20
utilfeature "k8s.io/apiserver/pkg/util/feature"
21
+ "k8s.io/client-go/tools/cache"
22
+ "k8s.io/client-go/util/workqueue"
26
23
featuregatetesting "k8s.io/component-base/featuregate/testing"
27
24
)
28
25
@@ -71,8 +68,7 @@ func TestController(t *testing.T) {
71
68
client := csi .NewMockClient (testDriverName , true , true , true , true , true , false )
72
69
73
70
initialObjects := []runtime.Object {test .pvc , test .pv , testVacObject , targetVacObject }
74
- ctrlInstance , ctx := setupFakeK8sEnvironment (t , client , initialObjects )
75
- defer ctx .Done ()
71
+ ctrlInstance := setupFakeK8sEnvironment (t , client , initialObjects )
76
72
77
73
_ , _ , err , _ := ctrlInstance .modify (test .pvc , test .pv )
78
74
if err != nil {
@@ -126,8 +122,7 @@ func TestModifyPVC(t *testing.T) {
126
122
}
127
123
128
124
initialObjects := []runtime.Object {test .pvc , test .pv , testVacObject , targetVacObject }
129
- ctrlInstance , ctx := setupFakeK8sEnvironment (t , client , initialObjects )
130
- defer ctx .Done ()
125
+ ctrlInstance := setupFakeK8sEnvironment (t , client , initialObjects )
131
126
132
127
_ , _ , err , _ := ctrlInstance .modify (test .pvc , test .pv )
133
128
@@ -225,8 +220,7 @@ func TestSyncPVC(t *testing.T) {
225
220
client := csi .NewMockClient (testDriverName , true , true , true , true , true , false )
226
221
227
222
initialObjects := []runtime.Object {test .pvc , test .pv , testVacObject , targetVacObject }
228
- ctrlInstance , ctx := setupFakeK8sEnvironment (t , client , initialObjects )
229
- defer ctx .Done ()
223
+ ctrlInstance := setupFakeK8sEnvironment (t , client , initialObjects )
230
224
231
225
err := ctrlInstance .syncPVC (pvcNamespace + "/" + pvcName )
232
226
if err != nil {
@@ -289,8 +283,7 @@ func TestInfeasibleRetry(t *testing.T) {
289
283
}
290
284
291
285
initialObjects := []runtime.Object {test .pvc , basePV , testVacObject , targetVacObject }
292
- ctrlInstance , ctx := setupFakeK8sEnvironment (t , client , initialObjects )
293
- defer ctx .Done ()
286
+ ctrlInstance := setupFakeK8sEnvironment (t , client , initialObjects )
294
287
295
288
// Attempt modification first time
296
289
err := ctrlInstance .syncPVC (pvcNamespace + "/" + pvcName )
@@ -329,7 +322,7 @@ func TestInfeasibleRetry(t *testing.T) {
329
322
}
330
323
331
324
// setupFakeK8sEnvironment creates fake K8s environment and starts Informers and ModifyController
332
- func setupFakeK8sEnvironment (t * testing.T , client * csi.MockClient , initialObjects []runtime.Object ) ( * modifyController , context. Context ) {
325
+ func setupFakeK8sEnvironment (t * testing.T , client * csi.MockClient , initialObjects []runtime.Object ) * modifyController {
333
326
t .Helper ()
334
327
335
328
featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .VolumeAttributesClass , true )
@@ -356,8 +349,7 @@ func setupFakeK8sEnvironment(t *testing.T, client *csi.MockClient, initialObject
356
349
stopCh := make (chan struct {})
357
350
informerFactory .Start (stopCh )
358
351
359
- ctx := context .TODO ()
360
- go controller .Run (1 , ctx )
352
+ go controller .Run (1 , t .Context ())
361
353
362
354
/* Add initial objects to informer caches */
363
355
for _ , obj := range initialObjects {
@@ -375,5 +367,5 @@ func setupFakeK8sEnvironment(t *testing.T, client *csi.MockClient, initialObject
375
367
376
368
ctrlInstance , _ := controller .(* modifyController )
377
369
378
- return ctrlInstance , ctx
370
+ return ctrlInstance
379
371
}
0 commit comments