Skip to content

Commit

Permalink
Merge pull request kubernetes#45946 from atlassian/expose-informer-co…
Browse files Browse the repository at this point in the history
…nstructors

Automatic merge from submit-queue (batch tested with PRs 48224, 45431, 45946, 48775, 49396)

Expose informer constructors

**What this PR does / why we need it**:
See kubernetes#45939

**Which issue this PR fixes**
Fixes kubernetes#45939

**Release note**:

```release-note
NONE
```
  • Loading branch information
Kubernetes Submit Queue authored Jul 25, 2017
2 parents 393b122 + 37f909a commit a25a51c
Show file tree
Hide file tree
Showing 97 changed files with 1,097 additions and 633 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ type externalAdmissionHookConfigurationInformer struct {
factory internalinterfaces.SharedInformerFactory
}

func newExternalAdmissionHookConfigurationInformer(client internalclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
sharedIndexInformer := cache.NewSharedIndexInformer(
// NewExternalAdmissionHookConfigurationInformer constructs a new informer for ExternalAdmissionHookConfiguration 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 NewExternalAdmissionHookConfigurationInformer(client internalclientset.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer {
return cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options v1.ListOptions) (runtime.Object, error) {
return client.Admissionregistration().ExternalAdmissionHookConfigurations().List(options)
Expand All @@ -53,14 +56,16 @@ func newExternalAdmissionHookConfigurationInformer(client internalclientset.Inte
},
&admissionregistration.ExternalAdmissionHookConfiguration{},
resyncPeriod,
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
indexers,
)
}

return sharedIndexInformer
func defaultExternalAdmissionHookConfigurationInformer(client internalclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
return NewExternalAdmissionHookConfigurationInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
}

func (f *externalAdmissionHookConfigurationInformer) Informer() cache.SharedIndexInformer {
return f.factory.InformerFor(&admissionregistration.ExternalAdmissionHookConfiguration{}, newExternalAdmissionHookConfigurationInformer)
return f.factory.InformerFor(&admissionregistration.ExternalAdmissionHookConfiguration{}, defaultExternalAdmissionHookConfigurationInformer)
}

func (f *externalAdmissionHookConfigurationInformer) Lister() internalversion.ExternalAdmissionHookConfigurationLister {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ type initializerConfigurationInformer struct {
factory internalinterfaces.SharedInformerFactory
}

func newInitializerConfigurationInformer(client internalclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
sharedIndexInformer := cache.NewSharedIndexInformer(
// NewInitializerConfigurationInformer constructs a new informer for InitializerConfiguration 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 NewInitializerConfigurationInformer(client internalclientset.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer {
return cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options v1.ListOptions) (runtime.Object, error) {
return client.Admissionregistration().InitializerConfigurations().List(options)
Expand All @@ -53,14 +56,16 @@ func newInitializerConfigurationInformer(client internalclientset.Interface, res
},
&admissionregistration.InitializerConfiguration{},
resyncPeriod,
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
indexers,
)
}

return sharedIndexInformer
func defaultInitializerConfigurationInformer(client internalclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
return NewInitializerConfigurationInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
}

func (f *initializerConfigurationInformer) Informer() cache.SharedIndexInformer {
return f.factory.InformerFor(&admissionregistration.InitializerConfiguration{}, newInitializerConfigurationInformer)
return f.factory.InformerFor(&admissionregistration.InitializerConfiguration{}, defaultInitializerConfigurationInformer)
}

func (f *initializerConfigurationInformer) Lister() internalversion.InitializerConfigurationLister {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,31 @@ type controllerRevisionInformer struct {
factory internalinterfaces.SharedInformerFactory
}

func newControllerRevisionInformer(client internalclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
sharedIndexInformer := cache.NewSharedIndexInformer(
// NewControllerRevisionInformer constructs a new informer for ControllerRevision 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 NewControllerRevisionInformer(client internalclientset.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer {
return cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options v1.ListOptions) (runtime.Object, error) {
return client.Apps().ControllerRevisions(v1.NamespaceAll).List(options)
return client.Apps().ControllerRevisions(namespace).List(options)
},
WatchFunc: func(options v1.ListOptions) (watch.Interface, error) {
return client.Apps().ControllerRevisions(v1.NamespaceAll).Watch(options)
return client.Apps().ControllerRevisions(namespace).Watch(options)
},
},
&apps.ControllerRevision{},
resyncPeriod,
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
indexers,
)
}

return sharedIndexInformer
func defaultControllerRevisionInformer(client internalclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
return NewControllerRevisionInformer(client, v1.NamespaceAll, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
}

func (f *controllerRevisionInformer) Informer() cache.SharedIndexInformer {
return f.factory.InformerFor(&apps.ControllerRevision{}, newControllerRevisionInformer)
return f.factory.InformerFor(&apps.ControllerRevision{}, defaultControllerRevisionInformer)
}

func (f *controllerRevisionInformer) Lister() internalversion.ControllerRevisionLister {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,31 @@ type statefulSetInformer struct {
factory internalinterfaces.SharedInformerFactory
}

func newStatefulSetInformer(client internalclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
sharedIndexInformer := cache.NewSharedIndexInformer(
// NewStatefulSetInformer constructs a new informer for StatefulSet 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 NewStatefulSetInformer(client internalclientset.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer {
return cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options v1.ListOptions) (runtime.Object, error) {
return client.Apps().StatefulSets(v1.NamespaceAll).List(options)
return client.Apps().StatefulSets(namespace).List(options)
},
WatchFunc: func(options v1.ListOptions) (watch.Interface, error) {
return client.Apps().StatefulSets(v1.NamespaceAll).Watch(options)
return client.Apps().StatefulSets(namespace).Watch(options)
},
},
&apps.StatefulSet{},
resyncPeriod,
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
indexers,
)
}

return sharedIndexInformer
func defaultStatefulSetInformer(client internalclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
return NewStatefulSetInformer(client, v1.NamespaceAll, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
}

func (f *statefulSetInformer) Informer() cache.SharedIndexInformer {
return f.factory.InformerFor(&apps.StatefulSet{}, newStatefulSetInformer)
return f.factory.InformerFor(&apps.StatefulSet{}, defaultStatefulSetInformer)
}

func (f *statefulSetInformer) Lister() internalversion.StatefulSetLister {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,31 @@ type horizontalPodAutoscalerInformer struct {
factory internalinterfaces.SharedInformerFactory
}

func newHorizontalPodAutoscalerInformer(client internalclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
sharedIndexInformer := cache.NewSharedIndexInformer(
// NewHorizontalPodAutoscalerInformer constructs a new informer for HorizontalPodAutoscaler 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 NewHorizontalPodAutoscalerInformer(client internalclientset.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer {
return cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options v1.ListOptions) (runtime.Object, error) {
return client.Autoscaling().HorizontalPodAutoscalers(v1.NamespaceAll).List(options)
return client.Autoscaling().HorizontalPodAutoscalers(namespace).List(options)
},
WatchFunc: func(options v1.ListOptions) (watch.Interface, error) {
return client.Autoscaling().HorizontalPodAutoscalers(v1.NamespaceAll).Watch(options)
return client.Autoscaling().HorizontalPodAutoscalers(namespace).Watch(options)
},
},
&autoscaling.HorizontalPodAutoscaler{},
resyncPeriod,
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
indexers,
)
}

return sharedIndexInformer
func defaultHorizontalPodAutoscalerInformer(client internalclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
return NewHorizontalPodAutoscalerInformer(client, v1.NamespaceAll, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
}

func (f *horizontalPodAutoscalerInformer) Informer() cache.SharedIndexInformer {
return f.factory.InformerFor(&autoscaling.HorizontalPodAutoscaler{}, newHorizontalPodAutoscalerInformer)
return f.factory.InformerFor(&autoscaling.HorizontalPodAutoscaler{}, defaultHorizontalPodAutoscalerInformer)
}

func (f *horizontalPodAutoscalerInformer) Lister() internalversion.HorizontalPodAutoscalerLister {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,31 @@ type cronJobInformer struct {
factory internalinterfaces.SharedInformerFactory
}

func newCronJobInformer(client internalclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
sharedIndexInformer := cache.NewSharedIndexInformer(
// NewCronJobInformer constructs a new informer for CronJob 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 NewCronJobInformer(client internalclientset.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer {
return cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options v1.ListOptions) (runtime.Object, error) {
return client.Batch().CronJobs(v1.NamespaceAll).List(options)
return client.Batch().CronJobs(namespace).List(options)
},
WatchFunc: func(options v1.ListOptions) (watch.Interface, error) {
return client.Batch().CronJobs(v1.NamespaceAll).Watch(options)
return client.Batch().CronJobs(namespace).Watch(options)
},
},
&batch.CronJob{},
resyncPeriod,
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
indexers,
)
}

return sharedIndexInformer
func defaultCronJobInformer(client internalclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
return NewCronJobInformer(client, v1.NamespaceAll, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
}

func (f *cronJobInformer) Informer() cache.SharedIndexInformer {
return f.factory.InformerFor(&batch.CronJob{}, newCronJobInformer)
return f.factory.InformerFor(&batch.CronJob{}, defaultCronJobInformer)
}

func (f *cronJobInformer) Lister() internalversion.CronJobLister {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,31 @@ type jobInformer struct {
factory internalinterfaces.SharedInformerFactory
}

func newJobInformer(client internalclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
sharedIndexInformer := cache.NewSharedIndexInformer(
// NewJobInformer constructs a new informer for Job 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 NewJobInformer(client internalclientset.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer {
return cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options v1.ListOptions) (runtime.Object, error) {
return client.Batch().Jobs(v1.NamespaceAll).List(options)
return client.Batch().Jobs(namespace).List(options)
},
WatchFunc: func(options v1.ListOptions) (watch.Interface, error) {
return client.Batch().Jobs(v1.NamespaceAll).Watch(options)
return client.Batch().Jobs(namespace).Watch(options)
},
},
&batch.Job{},
resyncPeriod,
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
indexers,
)
}

return sharedIndexInformer
func defaultJobInformer(client internalclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
return NewJobInformer(client, v1.NamespaceAll, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
}

func (f *jobInformer) Informer() cache.SharedIndexInformer {
return f.factory.InformerFor(&batch.Job{}, newJobInformer)
return f.factory.InformerFor(&batch.Job{}, defaultJobInformer)
}

func (f *jobInformer) Lister() internalversion.JobLister {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ type certificateSigningRequestInformer struct {
factory internalinterfaces.SharedInformerFactory
}

func newCertificateSigningRequestInformer(client internalclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
sharedIndexInformer := cache.NewSharedIndexInformer(
// NewCertificateSigningRequestInformer constructs a new informer for CertificateSigningRequest 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 NewCertificateSigningRequestInformer(client internalclientset.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer {
return cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options v1.ListOptions) (runtime.Object, error) {
return client.Certificates().CertificateSigningRequests().List(options)
Expand All @@ -53,14 +56,16 @@ func newCertificateSigningRequestInformer(client internalclientset.Interface, re
},
&certificates.CertificateSigningRequest{},
resyncPeriod,
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
indexers,
)
}

return sharedIndexInformer
func defaultCertificateSigningRequestInformer(client internalclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
return NewCertificateSigningRequestInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
}

func (f *certificateSigningRequestInformer) Informer() cache.SharedIndexInformer {
return f.factory.InformerFor(&certificates.CertificateSigningRequest{}, newCertificateSigningRequestInformer)
return f.factory.InformerFor(&certificates.CertificateSigningRequest{}, defaultCertificateSigningRequestInformer)
}

func (f *certificateSigningRequestInformer) Lister() internalversion.CertificateSigningRequestLister {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ type componentStatusInformer struct {
factory internalinterfaces.SharedInformerFactory
}

func newComponentStatusInformer(client internalclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
sharedIndexInformer := cache.NewSharedIndexInformer(
// NewComponentStatusInformer constructs a new informer for ComponentStatus 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 NewComponentStatusInformer(client internalclientset.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer {
return cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options v1.ListOptions) (runtime.Object, error) {
return client.Core().ComponentStatuses().List(options)
Expand All @@ -53,14 +56,16 @@ func newComponentStatusInformer(client internalclientset.Interface, resyncPeriod
},
&api.ComponentStatus{},
resyncPeriod,
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
indexers,
)
}

return sharedIndexInformer
func defaultComponentStatusInformer(client internalclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
return NewComponentStatusInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
}

func (f *componentStatusInformer) Informer() cache.SharedIndexInformer {
return f.factory.InformerFor(&api.ComponentStatus{}, newComponentStatusInformer)
return f.factory.InformerFor(&api.ComponentStatus{}, defaultComponentStatusInformer)
}

func (f *componentStatusInformer) Lister() internalversion.ComponentStatusLister {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,31 @@ type configMapInformer struct {
factory internalinterfaces.SharedInformerFactory
}

func newConfigMapInformer(client internalclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
sharedIndexInformer := cache.NewSharedIndexInformer(
// NewConfigMapInformer constructs a new informer for ConfigMap 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 NewConfigMapInformer(client internalclientset.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer {
return cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options v1.ListOptions) (runtime.Object, error) {
return client.Core().ConfigMaps(v1.NamespaceAll).List(options)
return client.Core().ConfigMaps(namespace).List(options)
},
WatchFunc: func(options v1.ListOptions) (watch.Interface, error) {
return client.Core().ConfigMaps(v1.NamespaceAll).Watch(options)
return client.Core().ConfigMaps(namespace).Watch(options)
},
},
&api.ConfigMap{},
resyncPeriod,
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
indexers,
)
}

return sharedIndexInformer
func defaultConfigMapInformer(client internalclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
return NewConfigMapInformer(client, v1.NamespaceAll, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
}

func (f *configMapInformer) Informer() cache.SharedIndexInformer {
return f.factory.InformerFor(&api.ConfigMap{}, newConfigMapInformer)
return f.factory.InformerFor(&api.ConfigMap{}, defaultConfigMapInformer)
}

func (f *configMapInformer) Lister() internalversion.ConfigMapLister {
Expand Down
Loading

0 comments on commit a25a51c

Please sign in to comment.