@@ -119,15 +119,6 @@ var _ = Describe("Informer Cache", func() {
119
119
var _ = Describe ("Multi-Namespace Informer Cache" , func () {
120
120
CacheTest (cache .MultiNamespacedCacheBuilder ([]string {testNamespaceOne , testNamespaceTwo , "default" }), cache.Options {})
121
121
})
122
- var _ = Describe ("Informer Cache without DeepCopy" , func () {
123
- CacheTest (cache .New , cache.Options {
124
- View : cache.ViewOptions {
125
- ByObject : cache.ViewByObject {
126
- UnsafeDisableDeepCopy : cache.DisableDeepCopyByObject {cache.ObjectAll {}: true },
127
- },
128
- },
129
- })
130
- })
131
122
132
123
var _ = Describe ("Cache with transformers" , func () {
133
124
var (
@@ -190,48 +181,46 @@ var _ = Describe("Cache with transformers", func() {
190
181
191
182
By ("creating the informer cache" )
192
183
informerCache , err = cache .New (cfg , cache.Options {
193
- View : cache.ViewOptions {
194
- DefaultTransform : func (i interface {}) (interface {}, error ) {
195
- obj := i .(runtime.Object )
196
- Expect (obj ).NotTo (BeNil ())
197
-
198
- accessor , err := meta .Accessor (obj )
199
- Expect (err ).To (BeNil ())
200
- annotations := accessor .GetAnnotations ()
184
+ DefaultTransform : func (i interface {}) (interface {}, error ) {
185
+ obj := i .(runtime.Object )
186
+ Expect (obj ).NotTo (BeNil ())
201
187
202
- if _ , exists := annotations ["transformed" ]; exists {
203
- // Avoid performing transformation multiple times.
204
- return i , nil
205
- }
188
+ accessor , err := meta .Accessor (obj )
189
+ Expect (err ).To (BeNil ())
190
+ annotations := accessor .GetAnnotations ()
206
191
207
- if annotations == nil {
208
- annotations = make (map [string ]string )
209
- }
210
- annotations ["transformed" ] = "default"
211
- accessor .SetAnnotations (annotations )
192
+ if _ , exists := annotations ["transformed" ]; exists {
193
+ // Avoid performing transformation multiple times.
212
194
return i , nil
213
- },
214
- ByObject : cache. ViewByObject {
215
- Transform : cache. TransformByObject {
216
- & corev1. Pod {}: func ( i interface {}) ( interface {}, error ) {
217
- obj := i .(runtime. Object )
218
- Expect ( obj ). NotTo ( BeNil ())
219
- accessor , err := meta . Accessor ( obj )
220
- Expect ( err ). To ( BeNil ())
221
-
222
- annotations := accessor . GetAnnotations ()
223
- if _ , exists := annotations [ "transformed" ]; exists {
224
- // Avoid performing transformation multiple times.
225
- return i , nil
226
- }
227
-
228
- if annotations == nil {
229
- annotations = make ( map [ string ] string )
230
- }
231
- annotations ["transformed" ] = "explicit"
232
- accessor . SetAnnotations ( annotations )
195
+ }
196
+
197
+ if annotations == nil {
198
+ annotations = make ( map [ string ] string )
199
+ }
200
+ annotations [ "transformed" ] = "default"
201
+ accessor . SetAnnotations ( annotations )
202
+ return i , nil
203
+ },
204
+ ByObject : map [client. Object ]cache. ByObject {
205
+ & corev1. Pod {}: {
206
+ Transform : func ( i interface {}) ( interface {}, error ) {
207
+ obj := i .(runtime. Object )
208
+ Expect ( obj ). NotTo ( BeNil ())
209
+ accessor , err := meta . Accessor ( obj )
210
+ Expect ( err ). To ( BeNil ())
211
+
212
+ annotations := accessor . GetAnnotations ()
213
+ if _ , exists := annotations ["transformed" ]; exists {
214
+ // Avoid performing transformation multiple times.
233
215
return i , nil
234
- },
216
+ }
217
+
218
+ if annotations == nil {
219
+ annotations = make (map [string ]string )
220
+ }
221
+ annotations ["transformed" ] = "explicit"
222
+ accessor .SetAnnotations (annotations )
223
+ return i , nil
235
224
},
236
225
},
237
226
},
@@ -370,13 +359,9 @@ var _ = Describe("Cache with selectors", func() {
370
359
}
371
360
372
361
opts := cache.Options {
373
- View : cache.ViewOptions {
374
- DefaultSelector : cache.ObjectSelector {Field : fields .OneTermEqualSelector ("metadata.namespace" , testNamespaceTwo )},
375
- ByObject : cache.ViewByObject {
376
- Selectors : cache.SelectorsByObject {
377
- & corev1.ServiceAccount {}: {Field : fields .OneTermEqualSelector ("metadata.namespace" , testNamespaceOne )},
378
- },
379
- },
362
+ DefaultSelector : cache.ObjectSelector {Field : fields .OneTermEqualSelector ("metadata.namespace" , testNamespaceTwo )},
363
+ ByObject : map [client.Object ]cache.ByObject {
364
+ & corev1.ServiceAccount {}: {Field : fields .OneTermEqualSelector ("metadata.namespace" , testNamespaceOne )},
380
365
},
381
366
}
382
367
@@ -798,7 +783,7 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
798
783
799
784
It ("should be able to restrict cache to a namespace" , func () {
800
785
By ("creating a namespaced cache" )
801
- namespacedCache , err := cache .New (cfg , cache.Options {View : cache. ViewOptions { Namespaces : []string {testNamespaceOne } }})
786
+ namespacedCache , err := cache .New (cfg , cache.Options {Namespaces : []string {testNamespaceOne }})
802
787
Expect (err ).NotTo (HaveOccurred ())
803
788
804
789
By ("running the cache and waiting for it to sync" )
@@ -1079,7 +1064,7 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
1079
1064
1080
1065
It ("should be able to restrict cache to a namespace" , func () {
1081
1066
By ("creating a namespaced cache" )
1082
- namespacedCache , err := cache .New (cfg , cache.Options {View : cache. ViewOptions { Namespaces : []string {testNamespaceOne } }})
1067
+ namespacedCache , err := cache .New (cfg , cache.Options {Namespaces : []string {testNamespaceOne }})
1083
1068
Expect (err ).NotTo (HaveOccurred ())
1084
1069
1085
1070
By ("running the cache and waiting for it to sync" )
@@ -1233,14 +1218,10 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
1233
1218
By ("creating the cache" )
1234
1219
builder := cache .BuilderWithOptions (
1235
1220
cache.Options {
1236
- View : cache.ViewOptions {
1237
- ByObject : cache.ViewByObject {
1238
- Selectors : cache.SelectorsByObject {
1239
- & corev1.Pod {}: {
1240
- Label : labels .Set (tc .labelSelectors ).AsSelector (),
1241
- Field : fields .Set (tc .fieldSelectors ).AsSelector (),
1242
- },
1243
- },
1221
+ ByObject : map [client.Object ]cache.ByObject {
1222
+ & corev1.Pod {}: {
1223
+ Label : labels .Set (tc .labelSelectors ).AsSelector (),
1224
+ Field : fields .Set (tc .fieldSelectors ).AsSelector (),
1244
1225
},
1245
1226
},
1246
1227
},
@@ -1822,12 +1803,5 @@ func isKubeService(svc metav1.Object) bool {
1822
1803
}
1823
1804
1824
1805
func isPodDisableDeepCopy (opts cache.Options ) bool {
1825
- if d , ok := opts .View .ByObject .UnsafeDisableDeepCopy [& corev1.Pod {}]; ok {
1826
- return d
1827
- } else if d , ok = opts .View .ByObject .UnsafeDisableDeepCopy [cache.ObjectAll {}]; ok {
1828
- return d
1829
- } else if d , ok = opts .View .ByObject .UnsafeDisableDeepCopy [& cache.ObjectAll {}]; ok {
1830
- return d
1831
- }
1832
- return false
1806
+ return opts .ByObject [& corev1.Pod {}].UnsafeDisableDeepCopy
1833
1807
}
0 commit comments