Expose Informer constructors

This commit is contained in:
Mikhail Mazurskiy 2017-07-19 10:58:43 +10:00
parent dbcc199d1f
commit 7927fdf856
No known key found for this signature in database
GPG Key ID: 93551ECC96E2F568

View File

@ -96,11 +96,8 @@ func (g *informerGenerator) GenerateType(c *generator.Context, t *types.Type, w
sw.Do(typeInformerInterface, m) sw.Do(typeInformerInterface, m)
sw.Do(typeInformerStruct, m) sw.Do(typeInformerStruct, m)
if len(g.groupVersion.Version) == 0 { sw.Do(typeInformerPublicConstructor, m)
sw.Do(typeInformerConstructorInternal, m) sw.Do(typeInformerConstructor, m)
} else {
sw.Do(typeInformerConstructorVersioned, m)
}
sw.Do(typeInformerInformer, m) sw.Do(typeInformerInformer, m)
sw.Do(typeInformerLister, m) sw.Do(typeInformerLister, m)
@ -122,49 +119,36 @@ type $.type|private$Informer struct {
} }
` `
var typeInformerConstructorInternal = ` var typeInformerPublicConstructor = `
func new$.type|public$Informer(client $.clientSetInterface|raw$, resyncPeriod $.timeDuration|raw$) $.cacheSharedIndexInformer|raw$ { // New$.type|public$Informer constructs a new informer for $.type|public$ type.
sharedIndexInformer := $.cacheNewSharedIndexInformer|raw$( // Always prefer using an informer factory to get a shared informer instead of getting an independent
// one. This reduces memory footprint and number of connections to the server.
func New$.type|public$Informer(client $.clientSetInterface|raw$$if .namespaced$, namespace string$end$, resyncPeriod $.timeDuration|raw$, indexers $.cacheIndexers|raw$) $.cacheSharedIndexInformer|raw$ {
return $.cacheNewSharedIndexInformer|raw$(
&$.cacheListWatch|raw${ &$.cacheListWatch|raw${
ListFunc: func(options $.v1ListOptions|raw$) ($.runtimeObject|raw$, error) { ListFunc: func(options $.v1ListOptions|raw$) ($.runtimeObject|raw$, error) {
return client.$.group$$.version$().$.type|publicPlural$($if .namespaced$$.namespaceAll|raw$$end$).List(options) return client.$.group$$.version$().$.type|publicPlural$($if .namespaced$namespace$end$).List(options)
}, },
WatchFunc: func(options $.v1ListOptions|raw$) ($.watchInterface|raw$, error) { WatchFunc: func(options $.v1ListOptions|raw$) ($.watchInterface|raw$, error) {
return client.$.group$$.version$().$.type|publicPlural$($if .namespaced$$.namespaceAll|raw$$end$).Watch(options) return client.$.group$$.version$().$.type|publicPlural$($if .namespaced$namespace$end$).Watch(options)
}, },
}, },
&$.type|raw${}, &$.type|raw${},
resyncPeriod, resyncPeriod,
$.cacheIndexers|raw${$.cacheNamespaceIndex|raw$: $.cacheMetaNamespaceIndexFunc|raw$}, indexers,
) )
return sharedIndexInformer
} }
` `
var typeInformerConstructorVersioned = ` var typeInformerConstructor = `
func new$.type|public$Informer(client $.clientSetInterface|raw$, resyncPeriod $.timeDuration|raw$) $.cacheSharedIndexInformer|raw$ { func default$.type|public$Informer(client $.clientSetInterface|raw$, resyncPeriod $.timeDuration|raw$) $.cacheSharedIndexInformer|raw$ {
sharedIndexInformer := $.cacheNewSharedIndexInformer|raw$( return New$.type|public$Informer(client, $if .namespaced$$.namespaceAll|raw$, $end$resyncPeriod, $.cacheIndexers|raw${$.cacheNamespaceIndex|raw$: $.cacheMetaNamespaceIndexFunc|raw$})
&$.cacheListWatch|raw${
ListFunc: func(options $.v1ListOptions|raw$) ($.runtimeObject|raw$, error) {
return client.$.group$$.version$().$.type|publicPlural$($if .namespaced$$.namespaceAll|raw$$end$).List(options)
},
WatchFunc: func(options $.v1ListOptions|raw$) ($.watchInterface|raw$, error) {
return client.$.group$$.version$().$.type|publicPlural$($if .namespaced$$.namespaceAll|raw$$end$).Watch(options)
},
},
&$.type|raw${},
resyncPeriod,
$.cacheIndexers|raw${$.cacheNamespaceIndex|raw$: $.cacheMetaNamespaceIndexFunc|raw$},
)
return sharedIndexInformer
} }
` `
var typeInformerInformer = ` var typeInformerInformer = `
func (f *$.type|private$Informer) Informer() $.cacheSharedIndexInformer|raw$ { func (f *$.type|private$Informer) Informer() $.cacheSharedIndexInformer|raw$ {
return f.factory.$.informerFor$(&$.type|raw${}, new$.type|public$Informer) return f.factory.$.informerFor$(&$.type|raw${}, default$.type|public$Informer)
} }
` `