mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 15:05:27 +00:00
Expose Informer constructors
This commit is contained in:
parent
dbcc199d1f
commit
7927fdf856
@ -96,11 +96,8 @@ func (g *informerGenerator) GenerateType(c *generator.Context, t *types.Type, w
|
||||
|
||||
sw.Do(typeInformerInterface, m)
|
||||
sw.Do(typeInformerStruct, m)
|
||||
if len(g.groupVersion.Version) == 0 {
|
||||
sw.Do(typeInformerConstructorInternal, m)
|
||||
} else {
|
||||
sw.Do(typeInformerConstructorVersioned, m)
|
||||
}
|
||||
sw.Do(typeInformerPublicConstructor, m)
|
||||
sw.Do(typeInformerConstructor, m)
|
||||
sw.Do(typeInformerInformer, m)
|
||||
sw.Do(typeInformerLister, m)
|
||||
|
||||
@ -122,49 +119,36 @@ type $.type|private$Informer struct {
|
||||
}
|
||||
`
|
||||
|
||||
var typeInformerConstructorInternal = `
|
||||
func new$.type|public$Informer(client $.clientSetInterface|raw$, resyncPeriod $.timeDuration|raw$) $.cacheSharedIndexInformer|raw$ {
|
||||
sharedIndexInformer := $.cacheNewSharedIndexInformer|raw$(
|
||||
var typeInformerPublicConstructor = `
|
||||
// New$.type|public$Informer constructs a new informer for $.type|public$ type.
|
||||
// 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${
|
||||
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) {
|
||||
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${},
|
||||
resyncPeriod,
|
||||
$.cacheIndexers|raw${$.cacheNamespaceIndex|raw$: $.cacheMetaNamespaceIndexFunc|raw$},
|
||||
indexers,
|
||||
)
|
||||
|
||||
return sharedIndexInformer
|
||||
}
|
||||
`
|
||||
|
||||
var typeInformerConstructorVersioned = `
|
||||
func new$.type|public$Informer(client $.clientSetInterface|raw$, resyncPeriod $.timeDuration|raw$) $.cacheSharedIndexInformer|raw$ {
|
||||
sharedIndexInformer := $.cacheNewSharedIndexInformer|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 typeInformerConstructor = `
|
||||
func default$.type|public$Informer(client $.clientSetInterface|raw$, resyncPeriod $.timeDuration|raw$) $.cacheSharedIndexInformer|raw$ {
|
||||
return New$.type|public$Informer(client, $if .namespaced$$.namespaceAll|raw$, $end$resyncPeriod, $.cacheIndexers|raw${$.cacheNamespaceIndex|raw$: $.cacheMetaNamespaceIndexFunc|raw$})
|
||||
}
|
||||
`
|
||||
|
||||
var typeInformerInformer = `
|
||||
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)
|
||||
}
|
||||
`
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user