@@ -63,6 +63,9 @@ type guardedInformer struct {
6363 wg wait.Group
6464}
6565
66+ // This function is used by factory.CacheFor() to pull in table info when the function needs to create new DB tables.
67+ type GetFieldsFuncType func () (fields [][]string , typeGuidance map [string ]string , externalUpdateInfo * sqltypes.ExternalGVKUpdates , selfUpdateInfo * sqltypes.ExternalGVKUpdates , isNamespaced bool , transform cache.TransformFunc )
68+
6669type newInformer func (ctx context.Context , client dynamic.ResourceInterface , fields [][]string , externalUpdateInfo * sqltypes.ExternalGVKUpdates , selfUpdateInfo * sqltypes.ExternalGVKUpdates , transform cache.TransformFunc , gvk schema.GroupVersionKind , db db.Client , shouldEncrypt bool , typeGuidance map [string ]string , namespace bool , watchable bool , gcInterval time.Duration , gcKeepCount int ) (* informer.Informer , error )
6770
6871type Cache struct {
@@ -144,7 +147,8 @@ func NewCacheFactoryWithContext(ctx context.Context, opts CacheFactoryOptions) (
144147// a context for a single cache to be able to stop that cache (eg: on schema refresh) without impacting the other caches.
145148//
146149// Don't forget to call DoneWithCache with the given informer once done with it.
147- func (f * CacheFactory ) CacheFor (ctx context.Context , fields [][]string , externalUpdateInfo * sqltypes.ExternalGVKUpdates , selfUpdateInfo * sqltypes.ExternalGVKUpdates , transform cache.TransformFunc , client dynamic.ResourceInterface , gvk schema.GroupVersionKind , typeGuidance map [string ]string , namespaced bool , watchable bool ) (* Cache , error ) {
150+
151+ func (f * CacheFactory ) CacheFor (ctx context.Context , getFieldsFunc GetFieldsFuncType , client dynamic.ResourceInterface , gvk schema.GroupVersionKind , watchable bool ) (* Cache , error ) {
148152 // Second, check if the informer and its accompanying informer-specific mutex exist already in the informers cache
149153 // If not, start by creating such informer-specific mutex. That is used later to ensure no two goroutines create
150154 // informers for the same GVK at the same type
@@ -168,15 +172,15 @@ func (f *CacheFactory) CacheFor(ctx context.Context, fields [][]string, external
168172 // Prevent Stop() to be called for that GVK
169173 gi .stopMutex .RLock ()
170174
171- gvkCache , err := f .cacheForLocked (ctx , gi , fields , externalUpdateInfo , selfUpdateInfo , transform , client , gvk , typeGuidance , namespaced , watchable )
175+ gvkCache , err := f .cacheForLocked (ctx , gi , getFieldsFunc , client , gvk , watchable )
172176 if err != nil {
173177 gi .stopMutex .RUnlock ()
174178 return nil , err
175179 }
176180 return gvkCache , nil
177181}
178182
179- func (f * CacheFactory ) cacheForLocked (ctx context.Context , gi * guardedInformer , fields [][] string , externalUpdateInfo * sqltypes. ExternalGVKUpdates , selfUpdateInfo * sqltypes. ExternalGVKUpdates , transform cache. TransformFunc , client dynamic.ResourceInterface , gvk schema.GroupVersionKind , typeGuidance map [ string ] string , namespaced bool , watchable bool ) (* Cache , error ) {
183+ func (f * CacheFactory ) cacheForLocked (ctx context.Context , gi * guardedInformer , getFieldsFunc GetFieldsFuncType , client dynamic.ResourceInterface , gvk schema.GroupVersionKind , watchable bool ) (* Cache , error ) {
180184 // At this point an informer-specific mutex (gi.mutex) is guaranteed to exist. Lock it
181185 gi .informerMutex .Lock ()
182186
@@ -191,9 +195,10 @@ func (f *CacheFactory) cacheForLocked(ctx context.Context, gi *guardedInformer,
191195
192196 _ , encryptResourceAlways := defaultEncryptedResourceTypes [gvk ]
193197 shouldEncrypt := f .encryptAll || encryptResourceAlways
198+ fields , typeGuidance , externalUpdateInfo , selfUpdateInfo , isNamespaced , transformFunc := getFieldsFunc ()
194199 // In non-test code this invokes pkg/sqlcache/informer/informer.go: NewInformer()
195200 // search for "func NewInformer(ctx"
196- i , err := f .newInformer (gi .ctx , client , fields , externalUpdateInfo , selfUpdateInfo , transform , gvk , f .dbClient , shouldEncrypt , typeGuidance , namespaced , watchable , f .gcInterval , f .gcKeepCount )
201+ i , err := f .newInformer (gi .ctx , client , fields , externalUpdateInfo , selfUpdateInfo , transformFunc , gvk , f .dbClient , shouldEncrypt , typeGuidance , isNamespaced , watchable , f .gcInterval , f .gcKeepCount )
197202 if err != nil {
198203 gi .informerMutex .Unlock ()
199204 return nil , err
0 commit comments