@@ -195,6 +195,35 @@ var _ = Describe("Informer Cache", func() {
195
195
Expect (actual .Namespace ).To (Equal (testNamespaceOne ))
196
196
})
197
197
198
+ It ("should be able to restrict cache to a namespace" , func () {
199
+ By ("creating a namespaced cache" )
200
+ namespacedCache , err := cache .New (cfg , cache.Options {Namespace : testNamespaceOne })
201
+ Expect (err ).NotTo (HaveOccurred ())
202
+
203
+ By ("running the cache and waiting for it to sync" )
204
+ go func () {
205
+ defer GinkgoRecover ()
206
+ Expect (namespacedCache .Start (stop )).To (Succeed ())
207
+ }()
208
+ Expect (namespacedCache .WaitForCacheSync (stop )).NotTo (BeFalse ())
209
+
210
+ By ("listing pods in all namespaces" )
211
+ out := & kcorev1.PodList {}
212
+ Expect (namespacedCache .List (context .Background (), nil , out )).To (Succeed ())
213
+
214
+ By ("verifying the returned pod is from the watched namespace" )
215
+ Expect (out .Items ).NotTo (BeEmpty ())
216
+ Expect (out .Items ).Should (HaveLen (1 ))
217
+ Expect (out .Items [0 ].Namespace ).To (Equal (testNamespaceOne ))
218
+
219
+ By ("listing all namespaces - should still be able to get a cluster-scoped resource" )
220
+ namespaceList := & kcorev1.NamespaceList {}
221
+ Expect (namespacedCache .List (context .Background (), nil , namespaceList )).To (Succeed ())
222
+
223
+ By ("verifying the namespace list is not empty" )
224
+ Expect (namespaceList .Items ).NotTo (BeEmpty ())
225
+ })
226
+
198
227
It ("should deep copy the object unless told otherwise" , func () {
199
228
By ("retrieving a specific pod from the cache" )
200
229
out := & kcorev1.Pod {}
@@ -333,6 +362,45 @@ var _ = Describe("Informer Cache", func() {
333
362
Expect (actual .GetNamespace ()).To (Equal (testNamespaceOne ))
334
363
})
335
364
365
+ It ("should be able to restrict cache to a namespace" , func () {
366
+ By ("creating a namespaced cache" )
367
+ namespacedCache , err := cache .New (cfg , cache.Options {Namespace : testNamespaceOne })
368
+ Expect (err ).NotTo (HaveOccurred ())
369
+
370
+ By ("running the cache and waiting for it to sync" )
371
+ go func () {
372
+ defer GinkgoRecover ()
373
+ Expect (namespacedCache .Start (stop )).To (Succeed ())
374
+ }()
375
+ Expect (namespacedCache .WaitForCacheSync (stop )).NotTo (BeFalse ())
376
+
377
+ By ("listing pods in all namespaces" )
378
+ out := & unstructured.UnstructuredList {}
379
+ out .SetGroupVersionKind (schema.GroupVersionKind {
380
+ Group : "" ,
381
+ Version : "v1" ,
382
+ Kind : "PodList" ,
383
+ })
384
+ Expect (namespacedCache .List (context .Background (), nil , out )).To (Succeed ())
385
+
386
+ By ("verifying the returned pod is from the watched namespace" )
387
+ Expect (out .Items ).NotTo (BeEmpty ())
388
+ Expect (out .Items ).Should (HaveLen (1 ))
389
+ Expect (out .Items [0 ].GetNamespace ()).To (Equal (testNamespaceOne ))
390
+
391
+ By ("listing all namespaces - should still be able to get a cluster-scoped resource" )
392
+ namespaceList := & unstructured.UnstructuredList {}
393
+ namespaceList .SetGroupVersionKind (schema.GroupVersionKind {
394
+ Group : "" ,
395
+ Version : "v1" ,
396
+ Kind : "NamespaceList" ,
397
+ })
398
+ Expect (namespacedCache .List (context .Background (), nil , namespaceList )).To (Succeed ())
399
+
400
+ By ("verifying the namespace list is not empty" )
401
+ Expect (namespaceList .Items ).NotTo (BeEmpty ())
402
+ })
403
+
336
404
It ("should deep copy the object unless told otherwise" , func () {
337
405
By ("retrieving a specific pod from the cache" )
338
406
out := & unstructured.Unstructured {}
0 commit comments