@@ -61,10 +61,6 @@ func (g *factoryGenerator) Namers(c *generator.Context) namer.NameSystems {
6161
6262func (g * factoryGenerator ) Imports (c * generator.Context ) (imports []string ) {
6363 imports = append (imports , g .imports .ImportLines ()... )
64- imports = append (imports ,
65- `"github.com/kcp-dev/logicalcluster/v3"` ,
66- `kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache"` ,
67- )
6864 return
6965}
7066
@@ -102,19 +98,24 @@ func (g *factoryGenerator) GenerateType(c *generator.Context, t *types.Type, w i
10298 "gvNewScopedFuncs" : gvNewScopedFuncs ,
10399 "gvGoNames" : g .gvGoNames ,
104100 "interfacesNewInformerFunc" : c .Universe .Type (types.Name {Package : g .internalInterfacesPackage , Name : "NewInformerFunc" }),
101+ "interfacesNewScopedInformerFunc" : c .Universe .Type (types.Name {Package : g .internalInterfacesPackage , Name : "NewScopedInformerFunc" }),
105102 "interfacesTweakListOptionsFunc" : c .Universe .Type (types.Name {Package : g .internalInterfacesPackage , Name : "TweakListOptionsFunc" }),
106103 "informerFactoryInterface" : c .Universe .Type (types.Name {Package : g .internalInterfacesPackage , Name : "SharedInformerFactory" }),
107104 "informerScopedFactoryInterface" : c .Universe .Type (types.Name {Package : g .internalInterfacesPackage , Name : "SharedScopedInformerFactory" }),
108105 "clientSetInterface" : c .Universe .Type (types.Name {Package : g .singleClusterVersionedClientSetPackage , Name : "Interface" }),
109106 "clusterClientSetInterface" : c .Universe .Type (types.Name {Package : g .clientSetPackage , Name : "ClusterInterface" }),
110107 "genericInformer" : c .Universe .Type (types.Name {Package : genericInformerPkg , Name : "GenericInformer" }),
108+ "cacheWaitForCacheSync" : c .Universe .Function (cacheWaitForCacheSync ),
111109 "reflectType" : c .Universe .Type (reflectType ),
110+ "reflectTypeOf" : c .Universe .Type (reflectTypeOf ),
112111 "runtimeObject" : c .Universe .Type (runtimeObject ),
113112 "schemaGroupVersionResource" : c .Universe .Type (schemaGroupVersionResource ),
114113 "syncMutex" : c .Universe .Type (syncMutex ),
114+ "syncWaitGroup" : c .Universe .Type (syncWaitGroup ),
115115 "timeDuration" : c .Universe .Type (timeDuration ),
116116 "namespaceAll" : c .Universe .Type (metav1NamespaceAll ),
117117 "object" : c .Universe .Type (metav1Object ),
118+ "logicalclusterName" : c .Universe .Type (logicalclusterName ),
118119 }
119120
120121 sw .Do (sharedInformerFactoryStruct , m )
@@ -132,9 +133,9 @@ var sharedInformerFactoryStruct = `
132133type SharedInformerOption func(*SharedInformerOptions) *SharedInformerOptions
133134
134135type SharedInformerOptions struct {
135- customResync map[reflect.Type]time.Duration
136- tweakListOptions internalinterfaces.TweakListOptionsFunc
137- transform cache.TransformFunc
136+ customResync map[{{.reflectType|raw}}]{{.timeDuration|raw}}
137+ tweakListOptions {{.interfacesTweakListOptionsFunc|raw}}
138+ transform {{.cacheTransformFunc|raw}}
138139 namespace string
139140}
140141
@@ -151,7 +152,7 @@ type sharedInformerFactory struct {
151152 // This allows Start() to be called multiple times safely.
152153 startedInformers map[{{.reflectType|raw}}]bool
153154 // wg tracks how many goroutines were started.
154- wg sync.WaitGroup
155+ wg {{.syncWaitGroup|raw}}
155156 // shuttingDown is true when Shutdown has been called. It may still be running
156157 // because it needs to wait for goroutines.
157158 shuttingDown bool
@@ -161,14 +162,14 @@ type sharedInformerFactory struct {
161162func WithCustomResyncConfig(resyncConfig map[{{.object|raw}}]{{.timeDuration|raw}}) SharedInformerOption {
162163 return func(opts *SharedInformerOptions) *SharedInformerOptions {
163164 for k, v := range resyncConfig {
164- opts.customResync[reflect.TypeOf (k)] = v
165+ opts.customResync[{{.reflectTypeOf|raw}} (k)] = v
165166 }
166167 return opts
167168 }
168169}
169170
170171// WithTweakListOptions sets a custom filter on all listers of the configured SharedInformerFactory.
171- func WithTweakListOptions(tweakListOptions internalinterfaces.TweakListOptionsFunc ) SharedInformerOption {
172+ func WithTweakListOptions(tweakListOptions {{.interfacesTweakListOptionsFunc|raw}} ) SharedInformerOption {
172173 return func(opts *SharedInformerOptions) *SharedInformerOptions {
173174 opts.tweakListOptions = tweakListOptions
174175 return opts
@@ -252,7 +253,6 @@ func (f *sharedInformerFactory) Shutdown() {
252253 f.shuttingDown = true
253254 f.lock.Unlock()
254255
255-
256256 // Will return immediately if there is nothing to wait for.
257257 f.wg.Wait()
258258}
@@ -273,7 +273,7 @@ func (f *sharedInformerFactory) WaitForCacheSync(stopCh <-chan struct{}) map[{{.
273273
274274 res := map[{{.reflectType|raw}}]bool{}
275275 for informType, informer := range informers {
276- res[informType] = cache.WaitForCacheSync (stopCh, informer.HasSynced)
276+ res[informType] = {{.cacheWaitForCacheSync|raw}} (stopCh, informer.HasSynced)
277277 }
278278
279279 return res
@@ -284,7 +284,7 @@ func (f *sharedInformerFactory) InformerFor(obj {{.runtimeObject|raw}}, newFunc
284284 f.lock.Lock()
285285 defer f.lock.Unlock()
286286
287- informerType := reflect.TypeOf (obj)
287+ informerType := {{.reflectTypeOf|raw}} (obj)
288288 informer, exists := f.informers[informerType]
289289 if exists {
290290 return informer
@@ -306,7 +306,7 @@ func (f *sharedInformerFactory) InformerFor(obj {{.runtimeObject|raw}}, newFunc
306306var sharedInformerFactoryInterface = `
307307type ScopedDynamicSharedInformerFactory interface {
308308 // ForResource gives generic access to a shared informer of the matching type.
309- ForResource(resource schema.GroupVersionResource ) ({{.genericInformer|raw}}, error)
309+ ForResource(resource {{.schemaGroupVersionResource|raw}} ) ({{.genericInformer|raw}}, error)
310310
311311 // Start initializes all requested informers. They are handled in goroutines
312312 // which run until the stop channel gets closed.
@@ -340,7 +340,7 @@ type ScopedDynamicSharedInformerFactory interface {
340340type SharedInformerFactory interface {
341341 {{.informerFactoryInterface|raw}}
342342
343- Cluster(logicalcluster.Name ) ScopedDynamicSharedInformerFactory
343+ Cluster({{.logicalclusterName|raw}} ) ScopedDynamicSharedInformerFactory
344344
345345 // Start initializes all requested informers. They are handled in goroutines
346346 // which run until the stop channel gets closed.
@@ -361,7 +361,7 @@ type SharedInformerFactory interface {
361361
362362 // WaitForCacheSync blocks until all started informers' caches were synced
363363 // or the stop channel gets closed.
364- WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type ]bool
364+ WaitForCacheSync(stopCh <-chan struct{}) map[{{.reflectType|raw}} ]bool
365365
366366 // ForResource gives generic access to a shared informer of the matching type.
367367 ForResource(resource {{.schemaGroupVersionResource|raw}}) (GenericClusterInformer, error)
@@ -380,7 +380,7 @@ func (f *sharedInformerFactory) {{index $.gvGoNames $groupPkgName}}() {{index $.
380380}
381381{{end}}
382382
383- func (f *sharedInformerFactory) Cluster(clusterName logicalcluster.Name ) ScopedDynamicSharedInformerFactory {
383+ func (f *sharedInformerFactory) Cluster(clusterName {{.logicalclusterName|raw}} ) ScopedDynamicSharedInformerFactory {
384384 return &scopedDynamicSharedInformerFactory{
385385 sharedInformerFactory: f,
386386 clusterName: clusterName,
@@ -389,10 +389,10 @@ func (f *sharedInformerFactory) Cluster(clusterName logicalcluster.Name) ScopedD
389389
390390type scopedDynamicSharedInformerFactory struct {
391391 *sharedInformerFactory
392- clusterName logicalcluster.Name
392+ clusterName {{.logicalclusterName|raw}}
393393}
394394
395- func (f *scopedDynamicSharedInformerFactory) ForResource(resource schema.GroupVersionResource ) ({{.genericInformer|raw}}, error) {
395+ func (f *scopedDynamicSharedInformerFactory) ForResource(resource {{.schemaGroupVersionResource|raw}} ) ({{.genericInformer|raw}}, error) {
396396 clusterInformer, err := f.sharedInformerFactory.ForResource(resource)
397397 if err != nil {
398398 return nil, err
@@ -491,17 +491,17 @@ func (f *sharedScopedInformerFactory) WaitForCacheSync(stopCh <-chan struct{}) m
491491
492492 res := map[{{.reflectType|raw}}]bool{}
493493 for informType, informer := range informers {
494- res[informType] = cache.WaitForCacheSync (stopCh, informer.HasSynced)
494+ res[informType] = {{.cacheWaitForCacheSync|raw}} (stopCh, informer.HasSynced)
495495 }
496496 return res
497497}
498498
499499// InformerFor returns the SharedIndexInformer for obj.
500- func (f *sharedScopedInformerFactory) InformerFor(obj runtime.Object , newFunc internalinterfaces.NewScopedInformerFunc ) {{.cacheSharedIndexInformer|raw}} {
500+ func (f *sharedScopedInformerFactory) InformerFor(obj {{.runtimeObject|raw}} , newFunc {{.interfacesNewScopedInformerFunc|raw}} ) {{.cacheSharedIndexInformer|raw}} {
501501 f.lock.Lock()
502502 defer f.lock.Unlock()
503503
504- informerType := reflect.TypeOf (obj)
504+ informerType := {{.reflectTypeOf|raw}} (obj)
505505 informer, exists := f.informers[informerType]
506506 if exists {
507507 return informer
@@ -523,7 +523,7 @@ func (f *sharedScopedInformerFactory) InformerFor(obj runtime.Object, newFunc in
523523// API group versions, scoped to one workspace.
524524type SharedScopedInformerFactory interface {
525525 {{.informerScopedFactoryInterface|raw}}
526- ForResource(resource schema.GroupVersionResource ) (GenericInformer, error)
526+ ForResource(resource {{.schemaGroupVersionResource|raw}} ) (GenericInformer, error)
527527 WaitForCacheSync(stopCh <-chan struct{}) map[{{.reflectType|raw}}]bool
528528
529529 {{range $groupName, $group := .groupVersions}}{{index $.gvGoNames $groupName}}() {{index $.gvInterfaces $groupName|raw}}
0 commit comments