@@ -117,7 +117,7 @@ var _ = Describe("Informer Cache", func() {
117
117
It ("should be able to list objects that haven't been watched previously" , func () {
118
118
By ("listing all services in the cluster" )
119
119
listObj := & kcorev1.ServiceList {}
120
- Expect (informerCache .List (context .Background (), listObj )).To (Succeed ())
120
+ Expect (informerCache .List (context .Background (), nil , listObj )).To (Succeed ())
121
121
122
122
By ("verifying that the returned list contains the Kubernetes service" )
123
123
// NB: kubernetes default service is automatically created in testenv.
@@ -147,10 +147,10 @@ var _ = Describe("Informer Cache", func() {
147
147
By ("listing pods with a particular label" )
148
148
// NB: each pod has a "test-label": <pod-name>
149
149
out := kcorev1.PodList {}
150
- Expect ( informerCache . List ( context . Background (), & out ,
151
- client .InNamespace (testNamespaceTwo ),
152
- client .MatchingLabels (map [string ]string {"test-label" : "test-pod-2" }),
153
- )).To (Succeed ())
150
+ lo := & client. ListOptions {}
151
+ lo .InNamespace (testNamespaceTwo )
152
+ lo .MatchingLabels (map [string ]string {"test-label" : "test-pod-2" })
153
+ Expect ( informerCache . List ( context . Background (), lo , & out )).To (Succeed ())
154
154
155
155
By ("verifying the returned pods have the correct label" )
156
156
Expect (out .Items ).NotTo (BeEmpty ())
@@ -167,9 +167,9 @@ var _ = Describe("Informer Cache", func() {
167
167
// NB: each pod has a "test-label": <pod-name>
168
168
out := kcorev1.PodList {}
169
169
labels := map [string ]string {"test-label" : "test-pod-2" }
170
- Expect ( informerCache . List ( context . Background (), & out ,
171
- client .MatchingLabels (labels ),
172
- )).To (Succeed ())
170
+ lo := & client. ListOptions {}
171
+ lo .MatchingLabels (labels )
172
+ Expect ( informerCache . List ( context . Background (), lo , & out )).To (Succeed ())
173
173
174
174
By ("verifying multiple pods with the same label in different namespaces are returned" )
175
175
Expect (out .Items ).NotTo (BeEmpty ())
@@ -184,9 +184,9 @@ var _ = Describe("Informer Cache", func() {
184
184
It ("should be able to list objects by namespace" , func () {
185
185
By ("listing pods in test-namespace-1" )
186
186
listObj := & kcorev1.PodList {}
187
- Expect ( informerCache . List ( context . Background (),
188
- client .InNamespace (testNamespaceOne ),
189
- listObj )).To (Succeed ())
187
+ lo := & client. ListOptions {}
188
+ lo .InNamespace (testNamespaceOne )
189
+ Expect ( informerCache . List ( context . Background (), lo , listObj )).To (Succeed ())
190
190
191
191
By ("verifying that the returned pods are in test-namespace-1" )
192
192
Expect (listObj .Items ).NotTo (BeEmpty ())
@@ -231,7 +231,8 @@ var _ = Describe("Informer Cache", func() {
231
231
Version : "v1" ,
232
232
Kind : "ServiceList" ,
233
233
})
234
- Expect (informerCache .List (context .Background (), nil , listObj )).To (Succeed ())
234
+ err := informerCache .List (context .Background (), nil , listObj )
235
+ Expect (err ).To (Succeed ())
235
236
236
237
By ("verifying that the returned list contains the Kubernetes service" )
237
238
// NB: kubernetes default service is automatically created in testenv.
@@ -271,8 +272,11 @@ var _ = Describe("Informer Cache", func() {
271
272
Version : "v1" ,
272
273
Kind : "PodList" ,
273
274
})
274
- Expect (informerCache .List (context .Background (), client .InNamespace (testNamespaceTwo ).
275
- MatchingLabels (map [string ]string {"test-label" : "test-pod-2" }), & out )).To (Succeed ())
275
+ lo := & client.ListOptions {}
276
+ lo .InNamespace (testNamespaceTwo )
277
+ lo .MatchingLabels (map [string ]string {"test-label" : "test-pod-2" })
278
+ err := informerCache .List (context .Background (), lo , & out )
279
+ Expect (err ).To (Succeed ())
276
280
277
281
By ("verifying the returned pods have the correct label" )
278
282
Expect (out .Items ).NotTo (BeEmpty ())
@@ -294,8 +298,10 @@ var _ = Describe("Informer Cache", func() {
294
298
Kind : "PodList" ,
295
299
})
296
300
labels := map [string ]string {"test-label" : "test-pod-2" }
297
- Expect (informerCache .List (context .Background (),
298
- client .MatchingLabels (labels ), & out )).To (Succeed ())
301
+ lo := & client.ListOptions {}
302
+ lo .MatchingLabels (labels )
303
+ err := informerCache .List (context .Background (), lo , & out )
304
+ Expect (err ).To (Succeed ())
299
305
300
306
By ("verifying multiple pods with the same label in different namespaces are returned" )
301
307
Expect (out .Items ).NotTo (BeEmpty ())
@@ -315,9 +321,10 @@ var _ = Describe("Informer Cache", func() {
315
321
Version : "v1" ,
316
322
Kind : "PodList" ,
317
323
})
318
- Expect (informerCache .List (context .Background (),
319
- client .InNamespace (testNamespaceOne ),
320
- listObj )).To (Succeed ())
324
+ lo := & client.ListOptions {}
325
+ lo .InNamespace (testNamespaceOne )
326
+ err := informerCache .List (context .Background (), lo , listObj )
327
+ Expect (err ).To (Succeed ())
321
328
322
329
By ("verifying that the returned pods are in test-namespace-1" )
323
330
Expect (listObj .Items ).NotTo (BeEmpty ())
@@ -470,9 +477,9 @@ var _ = Describe("Informer Cache", func() {
470
477
471
478
By ("listing Pods with restartPolicyOnFailure" )
472
479
listObj := & kcorev1.PodList {}
473
- Expect ( informer . List ( context . Background (), listObj ,
474
- client .MatchingField ("spec.restartPolicy" , "OnFailure" ),
475
- )).To (Succeed ())
480
+ lo := & client. ListOptions {}
481
+ lo .MatchingField ("spec.restartPolicy" , "OnFailure" )
482
+ Expect ( informer . List ( context . Background (), lo , listObj )).To (Succeed ())
476
483
477
484
By ("verifying that the returned pods have correct restart policy" )
478
485
Expect (listObj .Items ).NotTo (BeEmpty ())
@@ -524,7 +531,7 @@ var _ = Describe("Informer Cache", func() {
524
531
By ("verifying the object is received on the channel" )
525
532
Eventually (out ).Should (Receive (Equal (pod )))
526
533
close (done )
527
- })
534
+ }, 3 )
528
535
529
536
It ("should be able to index an object field then retrieve objects by that field" , func () {
530
537
By ("creating the cache" )
@@ -565,16 +572,17 @@ var _ = Describe("Informer Cache", func() {
565
572
Version : "v1" ,
566
573
Kind : "PodList" ,
567
574
})
568
- Expect (informer .List (context .Background (),
569
- client .MatchingField ("spec.restartPolicy" , "OnFailure" ),
570
- listObj )).To (Succeed ())
575
+ lo := & client.ListOptions {}
576
+ lo .MatchingField ("spec.restartPolicy" , "OnFailure" )
577
+ err = informer .List (context .Background (), lo , listObj )
578
+ Expect (err ).To (Succeed ())
571
579
572
580
By ("verifying that the returned pods have correct restart policy" )
573
581
Expect (listObj .Items ).NotTo (BeEmpty ())
574
582
Expect (listObj .Items ).Should (HaveLen (1 ))
575
583
actual := listObj .Items [0 ]
576
584
Expect (actual .GetName ()).To (Equal ("test-pod-3" ))
577
- })
585
+ }, 3 )
578
586
})
579
587
})
580
588
})
0 commit comments