@@ -1245,6 +1245,40 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
1245
1245
Expect (sii ).To (BeNil ())
1246
1246
Expect (apierrors .IsTimeout (err )).To (BeTrue ())
1247
1247
})
1248
+
1249
+ It ("should be able not to change indexer values after indexing cluster-scope objects" , func () {
1250
+ By ("creating the cache" )
1251
+ informer , err := cache .New (cfg , cache.Options {})
1252
+ Expect (err ).NotTo (HaveOccurred ())
1253
+
1254
+ By ("indexing the Namespace objects with fixed values before starting" )
1255
+ pod := & corev1.Namespace {}
1256
+ indexerValues := []string {"a" , "b" , "c" }
1257
+ fieldName := "fixedValues"
1258
+ indexFunc := func (obj client.Object ) []string {
1259
+ return indexerValues
1260
+ }
1261
+ Expect (informer .IndexField (context .TODO (), pod , fieldName , indexFunc )).To (Succeed ())
1262
+
1263
+ By ("running the cache and waiting for it to sync" )
1264
+ go func () {
1265
+ defer GinkgoRecover ()
1266
+ Expect (informer .Start (informerCacheCtx )).To (Succeed ())
1267
+ }()
1268
+ Expect (informer .WaitForCacheSync (informerCacheCtx )).NotTo (BeFalse ())
1269
+
1270
+ By ("listing Namespaces with fixed indexer" )
1271
+ listObj := & corev1.NamespaceList {}
1272
+ Expect (informer .List (context .Background (), listObj ,
1273
+ client.MatchingFields {fieldName : "a" })).To (Succeed ())
1274
+ Expect (listObj .Items ).NotTo (BeZero ())
1275
+
1276
+ By ("verifying the indexing does not change fixed returned values" )
1277
+ Expect (indexerValues ).Should (HaveLen (3 ))
1278
+ Expect (indexerValues [0 ]).To (Equal ("a" ))
1279
+ Expect (indexerValues [1 ]).To (Equal ("b" ))
1280
+ Expect (indexerValues [2 ]).To (Equal ("c" ))
1281
+ })
1248
1282
})
1249
1283
Context ("with unstructured objects" , func () {
1250
1284
It ("should be able to get informer for the object" , func () {
0 commit comments