diff --git a/informers/admissionregistration/v1alpha1/externaladmissionhookconfiguration.go b/informers/admissionregistration/v1alpha1/externaladmissionhookconfiguration.go index 2810cac8..cdc03d99 100644 --- a/informers/admissionregistration/v1alpha1/externaladmissionhookconfiguration.go +++ b/informers/admissionregistration/v1alpha1/externaladmissionhookconfiguration.go @@ -41,8 +41,11 @@ type externalAdmissionHookConfigurationInformer struct { factory internalinterfaces.SharedInformerFactory } -func newExternalAdmissionHookConfigurationInformer(client kubernetes.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 kubernetes.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options v1.ListOptions) (runtime.Object, error) { return client.AdmissionregistrationV1alpha1().ExternalAdmissionHookConfigurations().List(options) @@ -53,14 +56,16 @@ func newExternalAdmissionHookConfigurationInformer(client kubernetes.Interface, }, &admissionregistration_v1alpha1.ExternalAdmissionHookConfiguration{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultExternalAdmissionHookConfigurationInformer(client kubernetes.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_v1alpha1.ExternalAdmissionHookConfiguration{}, newExternalAdmissionHookConfigurationInformer) + return f.factory.InformerFor(&admissionregistration_v1alpha1.ExternalAdmissionHookConfiguration{}, defaultExternalAdmissionHookConfigurationInformer) } func (f *externalAdmissionHookConfigurationInformer) Lister() v1alpha1.ExternalAdmissionHookConfigurationLister { diff --git a/informers/admissionregistration/v1alpha1/initializerconfiguration.go b/informers/admissionregistration/v1alpha1/initializerconfiguration.go index a7b80619..90e0078f 100644 --- a/informers/admissionregistration/v1alpha1/initializerconfiguration.go +++ b/informers/admissionregistration/v1alpha1/initializerconfiguration.go @@ -41,8 +41,11 @@ type initializerConfigurationInformer struct { factory internalinterfaces.SharedInformerFactory } -func newInitializerConfigurationInformer(client kubernetes.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 kubernetes.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options v1.ListOptions) (runtime.Object, error) { return client.AdmissionregistrationV1alpha1().InitializerConfigurations().List(options) @@ -53,14 +56,16 @@ func newInitializerConfigurationInformer(client kubernetes.Interface, resyncPeri }, &admissionregistration_v1alpha1.InitializerConfiguration{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultInitializerConfigurationInformer(client kubernetes.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_v1alpha1.InitializerConfiguration{}, newInitializerConfigurationInformer) + return f.factory.InformerFor(&admissionregistration_v1alpha1.InitializerConfiguration{}, defaultInitializerConfigurationInformer) } func (f *initializerConfigurationInformer) Lister() v1alpha1.InitializerConfigurationLister { diff --git a/informers/apps/v1beta1/controllerrevision.go b/informers/apps/v1beta1/controllerrevision.go index 6d0d30ac..1a433f84 100644 --- a/informers/apps/v1beta1/controllerrevision.go +++ b/informers/apps/v1beta1/controllerrevision.go @@ -41,26 +41,31 @@ type controllerRevisionInformer struct { factory internalinterfaces.SharedInformerFactory } -func newControllerRevisionInformer(client kubernetes.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 kubernetes.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.AppsV1beta1().ControllerRevisions(v1.NamespaceAll).List(options) + return client.AppsV1beta1().ControllerRevisions(namespace).List(options) }, WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - return client.AppsV1beta1().ControllerRevisions(v1.NamespaceAll).Watch(options) + return client.AppsV1beta1().ControllerRevisions(namespace).Watch(options) }, }, &apps_v1beta1.ControllerRevision{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultControllerRevisionInformer(client kubernetes.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_v1beta1.ControllerRevision{}, newControllerRevisionInformer) + return f.factory.InformerFor(&apps_v1beta1.ControllerRevision{}, defaultControllerRevisionInformer) } func (f *controllerRevisionInformer) Lister() v1beta1.ControllerRevisionLister { diff --git a/informers/apps/v1beta1/deployment.go b/informers/apps/v1beta1/deployment.go index be1cee68..d77f3b3c 100644 --- a/informers/apps/v1beta1/deployment.go +++ b/informers/apps/v1beta1/deployment.go @@ -41,26 +41,31 @@ type deploymentInformer struct { factory internalinterfaces.SharedInformerFactory } -func newDeploymentInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - sharedIndexInformer := cache.NewSharedIndexInformer( +// NewDeploymentInformer constructs a new informer for Deployment 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 NewDeploymentInformer(client kubernetes.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.AppsV1beta1().Deployments(v1.NamespaceAll).List(options) + return client.AppsV1beta1().Deployments(namespace).List(options) }, WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - return client.AppsV1beta1().Deployments(v1.NamespaceAll).Watch(options) + return client.AppsV1beta1().Deployments(namespace).Watch(options) }, }, &apps_v1beta1.Deployment{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultDeploymentInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewDeploymentInformer(client, v1.NamespaceAll, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *deploymentInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&apps_v1beta1.Deployment{}, newDeploymentInformer) + return f.factory.InformerFor(&apps_v1beta1.Deployment{}, defaultDeploymentInformer) } func (f *deploymentInformer) Lister() v1beta1.DeploymentLister { diff --git a/informers/apps/v1beta1/statefulset.go b/informers/apps/v1beta1/statefulset.go index 61e35218..3bd8af7d 100644 --- a/informers/apps/v1beta1/statefulset.go +++ b/informers/apps/v1beta1/statefulset.go @@ -41,26 +41,31 @@ type statefulSetInformer struct { factory internalinterfaces.SharedInformerFactory } -func newStatefulSetInformer(client kubernetes.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 kubernetes.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.AppsV1beta1().StatefulSets(v1.NamespaceAll).List(options) + return client.AppsV1beta1().StatefulSets(namespace).List(options) }, WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - return client.AppsV1beta1().StatefulSets(v1.NamespaceAll).Watch(options) + return client.AppsV1beta1().StatefulSets(namespace).Watch(options) }, }, &apps_v1beta1.StatefulSet{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultStatefulSetInformer(client kubernetes.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_v1beta1.StatefulSet{}, newStatefulSetInformer) + return f.factory.InformerFor(&apps_v1beta1.StatefulSet{}, defaultStatefulSetInformer) } func (f *statefulSetInformer) Lister() v1beta1.StatefulSetLister { diff --git a/informers/apps/v1beta2/deployment.go b/informers/apps/v1beta2/deployment.go index acb1ba38..031bcddd 100644 --- a/informers/apps/v1beta2/deployment.go +++ b/informers/apps/v1beta2/deployment.go @@ -41,26 +41,31 @@ type deploymentInformer struct { factory internalinterfaces.SharedInformerFactory } -func newDeploymentInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - sharedIndexInformer := cache.NewSharedIndexInformer( +// NewDeploymentInformer constructs a new informer for Deployment 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 NewDeploymentInformer(client kubernetes.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.AppsV1beta2().Deployments(v1.NamespaceAll).List(options) + return client.AppsV1beta2().Deployments(namespace).List(options) }, WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - return client.AppsV1beta2().Deployments(v1.NamespaceAll).Watch(options) + return client.AppsV1beta2().Deployments(namespace).Watch(options) }, }, &apps_v1beta2.Deployment{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultDeploymentInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewDeploymentInformer(client, v1.NamespaceAll, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *deploymentInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&apps_v1beta2.Deployment{}, newDeploymentInformer) + return f.factory.InformerFor(&apps_v1beta2.Deployment{}, defaultDeploymentInformer) } func (f *deploymentInformer) Lister() v1beta2.DeploymentLister { diff --git a/informers/apps/v1beta2/statefulset.go b/informers/apps/v1beta2/statefulset.go index 5b565532..004e6b8e 100644 --- a/informers/apps/v1beta2/statefulset.go +++ b/informers/apps/v1beta2/statefulset.go @@ -41,26 +41,31 @@ type statefulSetInformer struct { factory internalinterfaces.SharedInformerFactory } -func newStatefulSetInformer(client kubernetes.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 kubernetes.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.AppsV1beta2().StatefulSets(v1.NamespaceAll).List(options) + return client.AppsV1beta2().StatefulSets(namespace).List(options) }, WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - return client.AppsV1beta2().StatefulSets(v1.NamespaceAll).Watch(options) + return client.AppsV1beta2().StatefulSets(namespace).Watch(options) }, }, &apps_v1beta2.StatefulSet{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultStatefulSetInformer(client kubernetes.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_v1beta2.StatefulSet{}, newStatefulSetInformer) + return f.factory.InformerFor(&apps_v1beta2.StatefulSet{}, defaultStatefulSetInformer) } func (f *statefulSetInformer) Lister() v1beta2.StatefulSetLister { diff --git a/informers/autoscaling/v1/horizontalpodautoscaler.go b/informers/autoscaling/v1/horizontalpodautoscaler.go index 56557ad3..d1f8cae6 100644 --- a/informers/autoscaling/v1/horizontalpodautoscaler.go +++ b/informers/autoscaling/v1/horizontalpodautoscaler.go @@ -41,26 +41,31 @@ type horizontalPodAutoscalerInformer struct { factory internalinterfaces.SharedInformerFactory } -func newHorizontalPodAutoscalerInformer(client kubernetes.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 kubernetes.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) { - return client.AutoscalingV1().HorizontalPodAutoscalers(meta_v1.NamespaceAll).List(options) + return client.AutoscalingV1().HorizontalPodAutoscalers(namespace).List(options) }, WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) { - return client.AutoscalingV1().HorizontalPodAutoscalers(meta_v1.NamespaceAll).Watch(options) + return client.AutoscalingV1().HorizontalPodAutoscalers(namespace).Watch(options) }, }, &autoscaling_v1.HorizontalPodAutoscaler{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultHorizontalPodAutoscalerInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewHorizontalPodAutoscalerInformer(client, meta_v1.NamespaceAll, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *horizontalPodAutoscalerInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&autoscaling_v1.HorizontalPodAutoscaler{}, newHorizontalPodAutoscalerInformer) + return f.factory.InformerFor(&autoscaling_v1.HorizontalPodAutoscaler{}, defaultHorizontalPodAutoscalerInformer) } func (f *horizontalPodAutoscalerInformer) Lister() v1.HorizontalPodAutoscalerLister { diff --git a/informers/autoscaling/v2alpha1/horizontalpodautoscaler.go b/informers/autoscaling/v2alpha1/horizontalpodautoscaler.go index 51cfd1f9..05d7d756 100644 --- a/informers/autoscaling/v2alpha1/horizontalpodautoscaler.go +++ b/informers/autoscaling/v2alpha1/horizontalpodautoscaler.go @@ -41,26 +41,31 @@ type horizontalPodAutoscalerInformer struct { factory internalinterfaces.SharedInformerFactory } -func newHorizontalPodAutoscalerInformer(client kubernetes.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 kubernetes.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.AutoscalingV2alpha1().HorizontalPodAutoscalers(v1.NamespaceAll).List(options) + return client.AutoscalingV2alpha1().HorizontalPodAutoscalers(namespace).List(options) }, WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - return client.AutoscalingV2alpha1().HorizontalPodAutoscalers(v1.NamespaceAll).Watch(options) + return client.AutoscalingV2alpha1().HorizontalPodAutoscalers(namespace).Watch(options) }, }, &autoscaling_v2alpha1.HorizontalPodAutoscaler{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultHorizontalPodAutoscalerInformer(client kubernetes.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_v2alpha1.HorizontalPodAutoscaler{}, newHorizontalPodAutoscalerInformer) + return f.factory.InformerFor(&autoscaling_v2alpha1.HorizontalPodAutoscaler{}, defaultHorizontalPodAutoscalerInformer) } func (f *horizontalPodAutoscalerInformer) Lister() v2alpha1.HorizontalPodAutoscalerLister { diff --git a/informers/batch/v1/job.go b/informers/batch/v1/job.go index f467f9c3..a5a35680 100644 --- a/informers/batch/v1/job.go +++ b/informers/batch/v1/job.go @@ -41,26 +41,31 @@ type jobInformer struct { factory internalinterfaces.SharedInformerFactory } -func newJobInformer(client kubernetes.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 kubernetes.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) { - return client.BatchV1().Jobs(meta_v1.NamespaceAll).List(options) + return client.BatchV1().Jobs(namespace).List(options) }, WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) { - return client.BatchV1().Jobs(meta_v1.NamespaceAll).Watch(options) + return client.BatchV1().Jobs(namespace).Watch(options) }, }, &batch_v1.Job{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultJobInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewJobInformer(client, meta_v1.NamespaceAll, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *jobInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&batch_v1.Job{}, newJobInformer) + return f.factory.InformerFor(&batch_v1.Job{}, defaultJobInformer) } func (f *jobInformer) Lister() v1.JobLister { diff --git a/informers/batch/v2alpha1/cronjob.go b/informers/batch/v2alpha1/cronjob.go index 5848ac84..26ce57e5 100644 --- a/informers/batch/v2alpha1/cronjob.go +++ b/informers/batch/v2alpha1/cronjob.go @@ -41,26 +41,31 @@ type cronJobInformer struct { factory internalinterfaces.SharedInformerFactory } -func newCronJobInformer(client kubernetes.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 kubernetes.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.BatchV2alpha1().CronJobs(v1.NamespaceAll).List(options) + return client.BatchV2alpha1().CronJobs(namespace).List(options) }, WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - return client.BatchV2alpha1().CronJobs(v1.NamespaceAll).Watch(options) + return client.BatchV2alpha1().CronJobs(namespace).Watch(options) }, }, &batch_v2alpha1.CronJob{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultCronJobInformer(client kubernetes.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_v2alpha1.CronJob{}, newCronJobInformer) + return f.factory.InformerFor(&batch_v2alpha1.CronJob{}, defaultCronJobInformer) } func (f *cronJobInformer) Lister() v2alpha1.CronJobLister { diff --git a/informers/certificates/v1beta1/certificatesigningrequest.go b/informers/certificates/v1beta1/certificatesigningrequest.go index a251b6f6..3d949742 100644 --- a/informers/certificates/v1beta1/certificatesigningrequest.go +++ b/informers/certificates/v1beta1/certificatesigningrequest.go @@ -41,8 +41,11 @@ type certificateSigningRequestInformer struct { factory internalinterfaces.SharedInformerFactory } -func newCertificateSigningRequestInformer(client kubernetes.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 kubernetes.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options v1.ListOptions) (runtime.Object, error) { return client.CertificatesV1beta1().CertificateSigningRequests().List(options) @@ -53,14 +56,16 @@ func newCertificateSigningRequestInformer(client kubernetes.Interface, resyncPer }, &certificates_v1beta1.CertificateSigningRequest{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultCertificateSigningRequestInformer(client kubernetes.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_v1beta1.CertificateSigningRequest{}, newCertificateSigningRequestInformer) + return f.factory.InformerFor(&certificates_v1beta1.CertificateSigningRequest{}, defaultCertificateSigningRequestInformer) } func (f *certificateSigningRequestInformer) Lister() v1beta1.CertificateSigningRequestLister { diff --git a/informers/core/v1/componentstatus.go b/informers/core/v1/componentstatus.go index 1eb55f8e..f07f9120 100644 --- a/informers/core/v1/componentstatus.go +++ b/informers/core/v1/componentstatus.go @@ -41,8 +41,11 @@ type componentStatusInformer struct { factory internalinterfaces.SharedInformerFactory } -func newComponentStatusInformer(client kubernetes.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 kubernetes.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) { return client.CoreV1().ComponentStatuses().List(options) @@ -53,14 +56,16 @@ func newComponentStatusInformer(client kubernetes.Interface, resyncPeriod time.D }, &core_v1.ComponentStatus{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultComponentStatusInformer(client kubernetes.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(&core_v1.ComponentStatus{}, newComponentStatusInformer) + return f.factory.InformerFor(&core_v1.ComponentStatus{}, defaultComponentStatusInformer) } func (f *componentStatusInformer) Lister() v1.ComponentStatusLister { diff --git a/informers/core/v1/configmap.go b/informers/core/v1/configmap.go index ba0afb16..7a14f1db 100644 --- a/informers/core/v1/configmap.go +++ b/informers/core/v1/configmap.go @@ -41,26 +41,31 @@ type configMapInformer struct { factory internalinterfaces.SharedInformerFactory } -func newConfigMapInformer(client kubernetes.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 kubernetes.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) { - return client.CoreV1().ConfigMaps(meta_v1.NamespaceAll).List(options) + return client.CoreV1().ConfigMaps(namespace).List(options) }, WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) { - return client.CoreV1().ConfigMaps(meta_v1.NamespaceAll).Watch(options) + return client.CoreV1().ConfigMaps(namespace).Watch(options) }, }, &core_v1.ConfigMap{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultConfigMapInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewConfigMapInformer(client, meta_v1.NamespaceAll, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *configMapInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&core_v1.ConfigMap{}, newConfigMapInformer) + return f.factory.InformerFor(&core_v1.ConfigMap{}, defaultConfigMapInformer) } func (f *configMapInformer) Lister() v1.ConfigMapLister { diff --git a/informers/core/v1/endpoints.go b/informers/core/v1/endpoints.go index 7986e6d5..248aedfe 100644 --- a/informers/core/v1/endpoints.go +++ b/informers/core/v1/endpoints.go @@ -41,26 +41,31 @@ type endpointsInformer struct { factory internalinterfaces.SharedInformerFactory } -func newEndpointsInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - sharedIndexInformer := cache.NewSharedIndexInformer( +// NewEndpointsInformer constructs a new informer for Endpoints 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 NewEndpointsInformer(client kubernetes.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) { - return client.CoreV1().Endpoints(meta_v1.NamespaceAll).List(options) + return client.CoreV1().Endpoints(namespace).List(options) }, WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) { - return client.CoreV1().Endpoints(meta_v1.NamespaceAll).Watch(options) + return client.CoreV1().Endpoints(namespace).Watch(options) }, }, &core_v1.Endpoints{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultEndpointsInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewEndpointsInformer(client, meta_v1.NamespaceAll, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *endpointsInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&core_v1.Endpoints{}, newEndpointsInformer) + return f.factory.InformerFor(&core_v1.Endpoints{}, defaultEndpointsInformer) } func (f *endpointsInformer) Lister() v1.EndpointsLister { diff --git a/informers/core/v1/event.go b/informers/core/v1/event.go index f971fbd7..0751775c 100644 --- a/informers/core/v1/event.go +++ b/informers/core/v1/event.go @@ -41,26 +41,31 @@ type eventInformer struct { factory internalinterfaces.SharedInformerFactory } -func newEventInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - sharedIndexInformer := cache.NewSharedIndexInformer( +// NewEventInformer constructs a new informer for Event 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 NewEventInformer(client kubernetes.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) { - return client.CoreV1().Events(meta_v1.NamespaceAll).List(options) + return client.CoreV1().Events(namespace).List(options) }, WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) { - return client.CoreV1().Events(meta_v1.NamespaceAll).Watch(options) + return client.CoreV1().Events(namespace).Watch(options) }, }, &core_v1.Event{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultEventInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewEventInformer(client, meta_v1.NamespaceAll, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *eventInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&core_v1.Event{}, newEventInformer) + return f.factory.InformerFor(&core_v1.Event{}, defaultEventInformer) } func (f *eventInformer) Lister() v1.EventLister { diff --git a/informers/core/v1/limitrange.go b/informers/core/v1/limitrange.go index 38eecfc5..77ffbb6d 100644 --- a/informers/core/v1/limitrange.go +++ b/informers/core/v1/limitrange.go @@ -41,26 +41,31 @@ type limitRangeInformer struct { factory internalinterfaces.SharedInformerFactory } -func newLimitRangeInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - sharedIndexInformer := cache.NewSharedIndexInformer( +// NewLimitRangeInformer constructs a new informer for LimitRange 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 NewLimitRangeInformer(client kubernetes.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) { - return client.CoreV1().LimitRanges(meta_v1.NamespaceAll).List(options) + return client.CoreV1().LimitRanges(namespace).List(options) }, WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) { - return client.CoreV1().LimitRanges(meta_v1.NamespaceAll).Watch(options) + return client.CoreV1().LimitRanges(namespace).Watch(options) }, }, &core_v1.LimitRange{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultLimitRangeInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewLimitRangeInformer(client, meta_v1.NamespaceAll, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *limitRangeInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&core_v1.LimitRange{}, newLimitRangeInformer) + return f.factory.InformerFor(&core_v1.LimitRange{}, defaultLimitRangeInformer) } func (f *limitRangeInformer) Lister() v1.LimitRangeLister { diff --git a/informers/core/v1/namespace.go b/informers/core/v1/namespace.go index 29da7814..e37dccfd 100644 --- a/informers/core/v1/namespace.go +++ b/informers/core/v1/namespace.go @@ -41,8 +41,11 @@ type namespaceInformer struct { factory internalinterfaces.SharedInformerFactory } -func newNamespaceInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - sharedIndexInformer := cache.NewSharedIndexInformer( +// NewNamespaceInformer constructs a new informer for Namespace 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 NewNamespaceInformer(client kubernetes.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) { return client.CoreV1().Namespaces().List(options) @@ -53,14 +56,16 @@ func newNamespaceInformer(client kubernetes.Interface, resyncPeriod time.Duratio }, &core_v1.Namespace{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultNamespaceInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewNamespaceInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *namespaceInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&core_v1.Namespace{}, newNamespaceInformer) + return f.factory.InformerFor(&core_v1.Namespace{}, defaultNamespaceInformer) } func (f *namespaceInformer) Lister() v1.NamespaceLister { diff --git a/informers/core/v1/node.go b/informers/core/v1/node.go index e37212be..9cd065b2 100644 --- a/informers/core/v1/node.go +++ b/informers/core/v1/node.go @@ -41,8 +41,11 @@ type nodeInformer struct { factory internalinterfaces.SharedInformerFactory } -func newNodeInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - sharedIndexInformer := cache.NewSharedIndexInformer( +// NewNodeInformer constructs a new informer for Node 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 NewNodeInformer(client kubernetes.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) { return client.CoreV1().Nodes().List(options) @@ -53,14 +56,16 @@ func newNodeInformer(client kubernetes.Interface, resyncPeriod time.Duration) ca }, &core_v1.Node{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultNodeInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewNodeInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *nodeInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&core_v1.Node{}, newNodeInformer) + return f.factory.InformerFor(&core_v1.Node{}, defaultNodeInformer) } func (f *nodeInformer) Lister() v1.NodeLister { diff --git a/informers/core/v1/persistentvolume.go b/informers/core/v1/persistentvolume.go index 4d2dd4b4..c41e22f3 100644 --- a/informers/core/v1/persistentvolume.go +++ b/informers/core/v1/persistentvolume.go @@ -41,8 +41,11 @@ type persistentVolumeInformer struct { factory internalinterfaces.SharedInformerFactory } -func newPersistentVolumeInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - sharedIndexInformer := cache.NewSharedIndexInformer( +// NewPersistentVolumeInformer constructs a new informer for PersistentVolume 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 NewPersistentVolumeInformer(client kubernetes.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) { return client.CoreV1().PersistentVolumes().List(options) @@ -53,14 +56,16 @@ func newPersistentVolumeInformer(client kubernetes.Interface, resyncPeriod time. }, &core_v1.PersistentVolume{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultPersistentVolumeInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewPersistentVolumeInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *persistentVolumeInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&core_v1.PersistentVolume{}, newPersistentVolumeInformer) + return f.factory.InformerFor(&core_v1.PersistentVolume{}, defaultPersistentVolumeInformer) } func (f *persistentVolumeInformer) Lister() v1.PersistentVolumeLister { diff --git a/informers/core/v1/persistentvolumeclaim.go b/informers/core/v1/persistentvolumeclaim.go index 87ad7a8a..2d0364ca 100644 --- a/informers/core/v1/persistentvolumeclaim.go +++ b/informers/core/v1/persistentvolumeclaim.go @@ -41,26 +41,31 @@ type persistentVolumeClaimInformer struct { factory internalinterfaces.SharedInformerFactory } -func newPersistentVolumeClaimInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - sharedIndexInformer := cache.NewSharedIndexInformer( +// NewPersistentVolumeClaimInformer constructs a new informer for PersistentVolumeClaim 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 NewPersistentVolumeClaimInformer(client kubernetes.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) { - return client.CoreV1().PersistentVolumeClaims(meta_v1.NamespaceAll).List(options) + return client.CoreV1().PersistentVolumeClaims(namespace).List(options) }, WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) { - return client.CoreV1().PersistentVolumeClaims(meta_v1.NamespaceAll).Watch(options) + return client.CoreV1().PersistentVolumeClaims(namespace).Watch(options) }, }, &core_v1.PersistentVolumeClaim{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultPersistentVolumeClaimInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewPersistentVolumeClaimInformer(client, meta_v1.NamespaceAll, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *persistentVolumeClaimInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&core_v1.PersistentVolumeClaim{}, newPersistentVolumeClaimInformer) + return f.factory.InformerFor(&core_v1.PersistentVolumeClaim{}, defaultPersistentVolumeClaimInformer) } func (f *persistentVolumeClaimInformer) Lister() v1.PersistentVolumeClaimLister { diff --git a/informers/core/v1/pod.go b/informers/core/v1/pod.go index 30be2ff9..d926fbd0 100644 --- a/informers/core/v1/pod.go +++ b/informers/core/v1/pod.go @@ -41,26 +41,31 @@ type podInformer struct { factory internalinterfaces.SharedInformerFactory } -func newPodInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - sharedIndexInformer := cache.NewSharedIndexInformer( +// NewPodInformer constructs a new informer for Pod 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 NewPodInformer(client kubernetes.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) { - return client.CoreV1().Pods(meta_v1.NamespaceAll).List(options) + return client.CoreV1().Pods(namespace).List(options) }, WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) { - return client.CoreV1().Pods(meta_v1.NamespaceAll).Watch(options) + return client.CoreV1().Pods(namespace).Watch(options) }, }, &core_v1.Pod{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultPodInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewPodInformer(client, meta_v1.NamespaceAll, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *podInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&core_v1.Pod{}, newPodInformer) + return f.factory.InformerFor(&core_v1.Pod{}, defaultPodInformer) } func (f *podInformer) Lister() v1.PodLister { diff --git a/informers/core/v1/podtemplate.go b/informers/core/v1/podtemplate.go index b7632869..b61f8667 100644 --- a/informers/core/v1/podtemplate.go +++ b/informers/core/v1/podtemplate.go @@ -41,26 +41,31 @@ type podTemplateInformer struct { factory internalinterfaces.SharedInformerFactory } -func newPodTemplateInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - sharedIndexInformer := cache.NewSharedIndexInformer( +// NewPodTemplateInformer constructs a new informer for PodTemplate 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 NewPodTemplateInformer(client kubernetes.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) { - return client.CoreV1().PodTemplates(meta_v1.NamespaceAll).List(options) + return client.CoreV1().PodTemplates(namespace).List(options) }, WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) { - return client.CoreV1().PodTemplates(meta_v1.NamespaceAll).Watch(options) + return client.CoreV1().PodTemplates(namespace).Watch(options) }, }, &core_v1.PodTemplate{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultPodTemplateInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewPodTemplateInformer(client, meta_v1.NamespaceAll, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *podTemplateInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&core_v1.PodTemplate{}, newPodTemplateInformer) + return f.factory.InformerFor(&core_v1.PodTemplate{}, defaultPodTemplateInformer) } func (f *podTemplateInformer) Lister() v1.PodTemplateLister { diff --git a/informers/core/v1/replicationcontroller.go b/informers/core/v1/replicationcontroller.go index 78ed233c..f305994c 100644 --- a/informers/core/v1/replicationcontroller.go +++ b/informers/core/v1/replicationcontroller.go @@ -41,26 +41,31 @@ type replicationControllerInformer struct { factory internalinterfaces.SharedInformerFactory } -func newReplicationControllerInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - sharedIndexInformer := cache.NewSharedIndexInformer( +// NewReplicationControllerInformer constructs a new informer for ReplicationController 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 NewReplicationControllerInformer(client kubernetes.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) { - return client.CoreV1().ReplicationControllers(meta_v1.NamespaceAll).List(options) + return client.CoreV1().ReplicationControllers(namespace).List(options) }, WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) { - return client.CoreV1().ReplicationControllers(meta_v1.NamespaceAll).Watch(options) + return client.CoreV1().ReplicationControllers(namespace).Watch(options) }, }, &core_v1.ReplicationController{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultReplicationControllerInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewReplicationControllerInformer(client, meta_v1.NamespaceAll, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *replicationControllerInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&core_v1.ReplicationController{}, newReplicationControllerInformer) + return f.factory.InformerFor(&core_v1.ReplicationController{}, defaultReplicationControllerInformer) } func (f *replicationControllerInformer) Lister() v1.ReplicationControllerLister { diff --git a/informers/core/v1/resourcequota.go b/informers/core/v1/resourcequota.go index 8de233f6..ac69106c 100644 --- a/informers/core/v1/resourcequota.go +++ b/informers/core/v1/resourcequota.go @@ -41,26 +41,31 @@ type resourceQuotaInformer struct { factory internalinterfaces.SharedInformerFactory } -func newResourceQuotaInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - sharedIndexInformer := cache.NewSharedIndexInformer( +// NewResourceQuotaInformer constructs a new informer for ResourceQuota 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 NewResourceQuotaInformer(client kubernetes.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) { - return client.CoreV1().ResourceQuotas(meta_v1.NamespaceAll).List(options) + return client.CoreV1().ResourceQuotas(namespace).List(options) }, WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) { - return client.CoreV1().ResourceQuotas(meta_v1.NamespaceAll).Watch(options) + return client.CoreV1().ResourceQuotas(namespace).Watch(options) }, }, &core_v1.ResourceQuota{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultResourceQuotaInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewResourceQuotaInformer(client, meta_v1.NamespaceAll, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *resourceQuotaInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&core_v1.ResourceQuota{}, newResourceQuotaInformer) + return f.factory.InformerFor(&core_v1.ResourceQuota{}, defaultResourceQuotaInformer) } func (f *resourceQuotaInformer) Lister() v1.ResourceQuotaLister { diff --git a/informers/core/v1/secret.go b/informers/core/v1/secret.go index 00704fb7..0c7464bc 100644 --- a/informers/core/v1/secret.go +++ b/informers/core/v1/secret.go @@ -41,26 +41,31 @@ type secretInformer struct { factory internalinterfaces.SharedInformerFactory } -func newSecretInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - sharedIndexInformer := cache.NewSharedIndexInformer( +// NewSecretInformer constructs a new informer for Secret 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 NewSecretInformer(client kubernetes.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) { - return client.CoreV1().Secrets(meta_v1.NamespaceAll).List(options) + return client.CoreV1().Secrets(namespace).List(options) }, WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) { - return client.CoreV1().Secrets(meta_v1.NamespaceAll).Watch(options) + return client.CoreV1().Secrets(namespace).Watch(options) }, }, &core_v1.Secret{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultSecretInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewSecretInformer(client, meta_v1.NamespaceAll, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *secretInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&core_v1.Secret{}, newSecretInformer) + return f.factory.InformerFor(&core_v1.Secret{}, defaultSecretInformer) } func (f *secretInformer) Lister() v1.SecretLister { diff --git a/informers/core/v1/service.go b/informers/core/v1/service.go index 1ef70e73..bba8ab9d 100644 --- a/informers/core/v1/service.go +++ b/informers/core/v1/service.go @@ -41,26 +41,31 @@ type serviceInformer struct { factory internalinterfaces.SharedInformerFactory } -func newServiceInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - sharedIndexInformer := cache.NewSharedIndexInformer( +// NewServiceInformer constructs a new informer for Service 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 NewServiceInformer(client kubernetes.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) { - return client.CoreV1().Services(meta_v1.NamespaceAll).List(options) + return client.CoreV1().Services(namespace).List(options) }, WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) { - return client.CoreV1().Services(meta_v1.NamespaceAll).Watch(options) + return client.CoreV1().Services(namespace).Watch(options) }, }, &core_v1.Service{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultServiceInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewServiceInformer(client, meta_v1.NamespaceAll, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *serviceInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&core_v1.Service{}, newServiceInformer) + return f.factory.InformerFor(&core_v1.Service{}, defaultServiceInformer) } func (f *serviceInformer) Lister() v1.ServiceLister { diff --git a/informers/core/v1/serviceaccount.go b/informers/core/v1/serviceaccount.go index 22924448..d41667bb 100644 --- a/informers/core/v1/serviceaccount.go +++ b/informers/core/v1/serviceaccount.go @@ -41,26 +41,31 @@ type serviceAccountInformer struct { factory internalinterfaces.SharedInformerFactory } -func newServiceAccountInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - sharedIndexInformer := cache.NewSharedIndexInformer( +// NewServiceAccountInformer constructs a new informer for ServiceAccount 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 NewServiceAccountInformer(client kubernetes.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) { - return client.CoreV1().ServiceAccounts(meta_v1.NamespaceAll).List(options) + return client.CoreV1().ServiceAccounts(namespace).List(options) }, WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) { - return client.CoreV1().ServiceAccounts(meta_v1.NamespaceAll).Watch(options) + return client.CoreV1().ServiceAccounts(namespace).Watch(options) }, }, &core_v1.ServiceAccount{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultServiceAccountInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewServiceAccountInformer(client, meta_v1.NamespaceAll, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *serviceAccountInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&core_v1.ServiceAccount{}, newServiceAccountInformer) + return f.factory.InformerFor(&core_v1.ServiceAccount{}, defaultServiceAccountInformer) } func (f *serviceAccountInformer) Lister() v1.ServiceAccountLister { diff --git a/informers/extensions/v1beta1/daemonset.go b/informers/extensions/v1beta1/daemonset.go index 20020b5c..e203ea6f 100644 --- a/informers/extensions/v1beta1/daemonset.go +++ b/informers/extensions/v1beta1/daemonset.go @@ -41,26 +41,31 @@ type daemonSetInformer struct { factory internalinterfaces.SharedInformerFactory } -func newDaemonSetInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - sharedIndexInformer := cache.NewSharedIndexInformer( +// NewDaemonSetInformer constructs a new informer for DaemonSet 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 NewDaemonSetInformer(client kubernetes.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.ExtensionsV1beta1().DaemonSets(v1.NamespaceAll).List(options) + return client.ExtensionsV1beta1().DaemonSets(namespace).List(options) }, WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - return client.ExtensionsV1beta1().DaemonSets(v1.NamespaceAll).Watch(options) + return client.ExtensionsV1beta1().DaemonSets(namespace).Watch(options) }, }, &extensions_v1beta1.DaemonSet{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultDaemonSetInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewDaemonSetInformer(client, v1.NamespaceAll, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *daemonSetInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&extensions_v1beta1.DaemonSet{}, newDaemonSetInformer) + return f.factory.InformerFor(&extensions_v1beta1.DaemonSet{}, defaultDaemonSetInformer) } func (f *daemonSetInformer) Lister() v1beta1.DaemonSetLister { diff --git a/informers/extensions/v1beta1/deployment.go b/informers/extensions/v1beta1/deployment.go index 6acb26b1..4d20f8ab 100644 --- a/informers/extensions/v1beta1/deployment.go +++ b/informers/extensions/v1beta1/deployment.go @@ -41,26 +41,31 @@ type deploymentInformer struct { factory internalinterfaces.SharedInformerFactory } -func newDeploymentInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - sharedIndexInformer := cache.NewSharedIndexInformer( +// NewDeploymentInformer constructs a new informer for Deployment 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 NewDeploymentInformer(client kubernetes.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.ExtensionsV1beta1().Deployments(v1.NamespaceAll).List(options) + return client.ExtensionsV1beta1().Deployments(namespace).List(options) }, WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - return client.ExtensionsV1beta1().Deployments(v1.NamespaceAll).Watch(options) + return client.ExtensionsV1beta1().Deployments(namespace).Watch(options) }, }, &extensions_v1beta1.Deployment{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultDeploymentInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewDeploymentInformer(client, v1.NamespaceAll, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *deploymentInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&extensions_v1beta1.Deployment{}, newDeploymentInformer) + return f.factory.InformerFor(&extensions_v1beta1.Deployment{}, defaultDeploymentInformer) } func (f *deploymentInformer) Lister() v1beta1.DeploymentLister { diff --git a/informers/extensions/v1beta1/ingress.go b/informers/extensions/v1beta1/ingress.go index 2938a7e6..9280ffe3 100644 --- a/informers/extensions/v1beta1/ingress.go +++ b/informers/extensions/v1beta1/ingress.go @@ -41,26 +41,31 @@ type ingressInformer struct { factory internalinterfaces.SharedInformerFactory } -func newIngressInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - sharedIndexInformer := cache.NewSharedIndexInformer( +// NewIngressInformer constructs a new informer for Ingress 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 NewIngressInformer(client kubernetes.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.ExtensionsV1beta1().Ingresses(v1.NamespaceAll).List(options) + return client.ExtensionsV1beta1().Ingresses(namespace).List(options) }, WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - return client.ExtensionsV1beta1().Ingresses(v1.NamespaceAll).Watch(options) + return client.ExtensionsV1beta1().Ingresses(namespace).Watch(options) }, }, &extensions_v1beta1.Ingress{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultIngressInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewIngressInformer(client, v1.NamespaceAll, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *ingressInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&extensions_v1beta1.Ingress{}, newIngressInformer) + return f.factory.InformerFor(&extensions_v1beta1.Ingress{}, defaultIngressInformer) } func (f *ingressInformer) Lister() v1beta1.IngressLister { diff --git a/informers/extensions/v1beta1/podsecuritypolicy.go b/informers/extensions/v1beta1/podsecuritypolicy.go index d69ea7c0..59336b0e 100644 --- a/informers/extensions/v1beta1/podsecuritypolicy.go +++ b/informers/extensions/v1beta1/podsecuritypolicy.go @@ -41,8 +41,11 @@ type podSecurityPolicyInformer struct { factory internalinterfaces.SharedInformerFactory } -func newPodSecurityPolicyInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - sharedIndexInformer := cache.NewSharedIndexInformer( +// NewPodSecurityPolicyInformer constructs a new informer for PodSecurityPolicy 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 NewPodSecurityPolicyInformer(client kubernetes.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options v1.ListOptions) (runtime.Object, error) { return client.ExtensionsV1beta1().PodSecurityPolicies().List(options) @@ -53,14 +56,16 @@ func newPodSecurityPolicyInformer(client kubernetes.Interface, resyncPeriod time }, &extensions_v1beta1.PodSecurityPolicy{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultPodSecurityPolicyInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewPodSecurityPolicyInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *podSecurityPolicyInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&extensions_v1beta1.PodSecurityPolicy{}, newPodSecurityPolicyInformer) + return f.factory.InformerFor(&extensions_v1beta1.PodSecurityPolicy{}, defaultPodSecurityPolicyInformer) } func (f *podSecurityPolicyInformer) Lister() v1beta1.PodSecurityPolicyLister { diff --git a/informers/extensions/v1beta1/replicaset.go b/informers/extensions/v1beta1/replicaset.go index 80781bbe..8d1af811 100644 --- a/informers/extensions/v1beta1/replicaset.go +++ b/informers/extensions/v1beta1/replicaset.go @@ -41,26 +41,31 @@ type replicaSetInformer struct { factory internalinterfaces.SharedInformerFactory } -func newReplicaSetInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - sharedIndexInformer := cache.NewSharedIndexInformer( +// NewReplicaSetInformer constructs a new informer for ReplicaSet 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 NewReplicaSetInformer(client kubernetes.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.ExtensionsV1beta1().ReplicaSets(v1.NamespaceAll).List(options) + return client.ExtensionsV1beta1().ReplicaSets(namespace).List(options) }, WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - return client.ExtensionsV1beta1().ReplicaSets(v1.NamespaceAll).Watch(options) + return client.ExtensionsV1beta1().ReplicaSets(namespace).Watch(options) }, }, &extensions_v1beta1.ReplicaSet{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultReplicaSetInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewReplicaSetInformer(client, v1.NamespaceAll, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *replicaSetInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&extensions_v1beta1.ReplicaSet{}, newReplicaSetInformer) + return f.factory.InformerFor(&extensions_v1beta1.ReplicaSet{}, defaultReplicaSetInformer) } func (f *replicaSetInformer) Lister() v1beta1.ReplicaSetLister { diff --git a/informers/extensions/v1beta1/thirdpartyresource.go b/informers/extensions/v1beta1/thirdpartyresource.go index 4603b46e..62d02a54 100644 --- a/informers/extensions/v1beta1/thirdpartyresource.go +++ b/informers/extensions/v1beta1/thirdpartyresource.go @@ -41,8 +41,11 @@ type thirdPartyResourceInformer struct { factory internalinterfaces.SharedInformerFactory } -func newThirdPartyResourceInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - sharedIndexInformer := cache.NewSharedIndexInformer( +// NewThirdPartyResourceInformer constructs a new informer for ThirdPartyResource 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 NewThirdPartyResourceInformer(client kubernetes.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options v1.ListOptions) (runtime.Object, error) { return client.ExtensionsV1beta1().ThirdPartyResources().List(options) @@ -53,14 +56,16 @@ func newThirdPartyResourceInformer(client kubernetes.Interface, resyncPeriod tim }, &extensions_v1beta1.ThirdPartyResource{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultThirdPartyResourceInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewThirdPartyResourceInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *thirdPartyResourceInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&extensions_v1beta1.ThirdPartyResource{}, newThirdPartyResourceInformer) + return f.factory.InformerFor(&extensions_v1beta1.ThirdPartyResource{}, defaultThirdPartyResourceInformer) } func (f *thirdPartyResourceInformer) Lister() v1beta1.ThirdPartyResourceLister { diff --git a/informers/networking/v1/networkpolicy.go b/informers/networking/v1/networkpolicy.go index 0c0fab66..d8538459 100644 --- a/informers/networking/v1/networkpolicy.go +++ b/informers/networking/v1/networkpolicy.go @@ -41,26 +41,31 @@ type networkPolicyInformer struct { factory internalinterfaces.SharedInformerFactory } -func newNetworkPolicyInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - sharedIndexInformer := cache.NewSharedIndexInformer( +// NewNetworkPolicyInformer constructs a new informer for NetworkPolicy 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 NewNetworkPolicyInformer(client kubernetes.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) { - return client.NetworkingV1().NetworkPolicies(meta_v1.NamespaceAll).List(options) + return client.NetworkingV1().NetworkPolicies(namespace).List(options) }, WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) { - return client.NetworkingV1().NetworkPolicies(meta_v1.NamespaceAll).Watch(options) + return client.NetworkingV1().NetworkPolicies(namespace).Watch(options) }, }, &networking_v1.NetworkPolicy{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultNetworkPolicyInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewNetworkPolicyInformer(client, meta_v1.NamespaceAll, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *networkPolicyInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&networking_v1.NetworkPolicy{}, newNetworkPolicyInformer) + return f.factory.InformerFor(&networking_v1.NetworkPolicy{}, defaultNetworkPolicyInformer) } func (f *networkPolicyInformer) Lister() v1.NetworkPolicyLister { diff --git a/informers/policy/v1beta1/poddisruptionbudget.go b/informers/policy/v1beta1/poddisruptionbudget.go index 7c1eac85..b10ec42f 100644 --- a/informers/policy/v1beta1/poddisruptionbudget.go +++ b/informers/policy/v1beta1/poddisruptionbudget.go @@ -41,26 +41,31 @@ type podDisruptionBudgetInformer struct { factory internalinterfaces.SharedInformerFactory } -func newPodDisruptionBudgetInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - sharedIndexInformer := cache.NewSharedIndexInformer( +// NewPodDisruptionBudgetInformer constructs a new informer for PodDisruptionBudget 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 NewPodDisruptionBudgetInformer(client kubernetes.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.PolicyV1beta1().PodDisruptionBudgets(v1.NamespaceAll).List(options) + return client.PolicyV1beta1().PodDisruptionBudgets(namespace).List(options) }, WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - return client.PolicyV1beta1().PodDisruptionBudgets(v1.NamespaceAll).Watch(options) + return client.PolicyV1beta1().PodDisruptionBudgets(namespace).Watch(options) }, }, &policy_v1beta1.PodDisruptionBudget{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultPodDisruptionBudgetInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewPodDisruptionBudgetInformer(client, v1.NamespaceAll, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *podDisruptionBudgetInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&policy_v1beta1.PodDisruptionBudget{}, newPodDisruptionBudgetInformer) + return f.factory.InformerFor(&policy_v1beta1.PodDisruptionBudget{}, defaultPodDisruptionBudgetInformer) } func (f *podDisruptionBudgetInformer) Lister() v1beta1.PodDisruptionBudgetLister { diff --git a/informers/rbac/v1alpha1/clusterrole.go b/informers/rbac/v1alpha1/clusterrole.go index 10e468ae..435bec5a 100644 --- a/informers/rbac/v1alpha1/clusterrole.go +++ b/informers/rbac/v1alpha1/clusterrole.go @@ -41,8 +41,11 @@ type clusterRoleInformer struct { factory internalinterfaces.SharedInformerFactory } -func newClusterRoleInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - sharedIndexInformer := cache.NewSharedIndexInformer( +// NewClusterRoleInformer constructs a new informer for ClusterRole 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 NewClusterRoleInformer(client kubernetes.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options v1.ListOptions) (runtime.Object, error) { return client.RbacV1alpha1().ClusterRoles().List(options) @@ -53,14 +56,16 @@ func newClusterRoleInformer(client kubernetes.Interface, resyncPeriod time.Durat }, &rbac_v1alpha1.ClusterRole{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultClusterRoleInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewClusterRoleInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *clusterRoleInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&rbac_v1alpha1.ClusterRole{}, newClusterRoleInformer) + return f.factory.InformerFor(&rbac_v1alpha1.ClusterRole{}, defaultClusterRoleInformer) } func (f *clusterRoleInformer) Lister() v1alpha1.ClusterRoleLister { diff --git a/informers/rbac/v1alpha1/clusterrolebinding.go b/informers/rbac/v1alpha1/clusterrolebinding.go index 62030775..167a1887 100644 --- a/informers/rbac/v1alpha1/clusterrolebinding.go +++ b/informers/rbac/v1alpha1/clusterrolebinding.go @@ -41,8 +41,11 @@ type clusterRoleBindingInformer struct { factory internalinterfaces.SharedInformerFactory } -func newClusterRoleBindingInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - sharedIndexInformer := cache.NewSharedIndexInformer( +// NewClusterRoleBindingInformer constructs a new informer for ClusterRoleBinding 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 NewClusterRoleBindingInformer(client kubernetes.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options v1.ListOptions) (runtime.Object, error) { return client.RbacV1alpha1().ClusterRoleBindings().List(options) @@ -53,14 +56,16 @@ func newClusterRoleBindingInformer(client kubernetes.Interface, resyncPeriod tim }, &rbac_v1alpha1.ClusterRoleBinding{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultClusterRoleBindingInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewClusterRoleBindingInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *clusterRoleBindingInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&rbac_v1alpha1.ClusterRoleBinding{}, newClusterRoleBindingInformer) + return f.factory.InformerFor(&rbac_v1alpha1.ClusterRoleBinding{}, defaultClusterRoleBindingInformer) } func (f *clusterRoleBindingInformer) Lister() v1alpha1.ClusterRoleBindingLister { diff --git a/informers/rbac/v1alpha1/role.go b/informers/rbac/v1alpha1/role.go index 10697e0d..81ef493a 100644 --- a/informers/rbac/v1alpha1/role.go +++ b/informers/rbac/v1alpha1/role.go @@ -41,26 +41,31 @@ type roleInformer struct { factory internalinterfaces.SharedInformerFactory } -func newRoleInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - sharedIndexInformer := cache.NewSharedIndexInformer( +// NewRoleInformer constructs a new informer for Role 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 NewRoleInformer(client kubernetes.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.RbacV1alpha1().Roles(v1.NamespaceAll).List(options) + return client.RbacV1alpha1().Roles(namespace).List(options) }, WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - return client.RbacV1alpha1().Roles(v1.NamespaceAll).Watch(options) + return client.RbacV1alpha1().Roles(namespace).Watch(options) }, }, &rbac_v1alpha1.Role{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultRoleInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewRoleInformer(client, v1.NamespaceAll, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *roleInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&rbac_v1alpha1.Role{}, newRoleInformer) + return f.factory.InformerFor(&rbac_v1alpha1.Role{}, defaultRoleInformer) } func (f *roleInformer) Lister() v1alpha1.RoleLister { diff --git a/informers/rbac/v1alpha1/rolebinding.go b/informers/rbac/v1alpha1/rolebinding.go index 9242aa5c..bfc89657 100644 --- a/informers/rbac/v1alpha1/rolebinding.go +++ b/informers/rbac/v1alpha1/rolebinding.go @@ -41,26 +41,31 @@ type roleBindingInformer struct { factory internalinterfaces.SharedInformerFactory } -func newRoleBindingInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - sharedIndexInformer := cache.NewSharedIndexInformer( +// NewRoleBindingInformer constructs a new informer for RoleBinding 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 NewRoleBindingInformer(client kubernetes.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.RbacV1alpha1().RoleBindings(v1.NamespaceAll).List(options) + return client.RbacV1alpha1().RoleBindings(namespace).List(options) }, WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - return client.RbacV1alpha1().RoleBindings(v1.NamespaceAll).Watch(options) + return client.RbacV1alpha1().RoleBindings(namespace).Watch(options) }, }, &rbac_v1alpha1.RoleBinding{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultRoleBindingInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewRoleBindingInformer(client, v1.NamespaceAll, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *roleBindingInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&rbac_v1alpha1.RoleBinding{}, newRoleBindingInformer) + return f.factory.InformerFor(&rbac_v1alpha1.RoleBinding{}, defaultRoleBindingInformer) } func (f *roleBindingInformer) Lister() v1alpha1.RoleBindingLister { diff --git a/informers/rbac/v1beta1/clusterrole.go b/informers/rbac/v1beta1/clusterrole.go index 88e94fe5..9798b9b2 100644 --- a/informers/rbac/v1beta1/clusterrole.go +++ b/informers/rbac/v1beta1/clusterrole.go @@ -41,8 +41,11 @@ type clusterRoleInformer struct { factory internalinterfaces.SharedInformerFactory } -func newClusterRoleInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - sharedIndexInformer := cache.NewSharedIndexInformer( +// NewClusterRoleInformer constructs a new informer for ClusterRole 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 NewClusterRoleInformer(client kubernetes.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options v1.ListOptions) (runtime.Object, error) { return client.RbacV1beta1().ClusterRoles().List(options) @@ -53,14 +56,16 @@ func newClusterRoleInformer(client kubernetes.Interface, resyncPeriod time.Durat }, &rbac_v1beta1.ClusterRole{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultClusterRoleInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewClusterRoleInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *clusterRoleInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&rbac_v1beta1.ClusterRole{}, newClusterRoleInformer) + return f.factory.InformerFor(&rbac_v1beta1.ClusterRole{}, defaultClusterRoleInformer) } func (f *clusterRoleInformer) Lister() v1beta1.ClusterRoleLister { diff --git a/informers/rbac/v1beta1/clusterrolebinding.go b/informers/rbac/v1beta1/clusterrolebinding.go index 8f64a2d4..52370de1 100644 --- a/informers/rbac/v1beta1/clusterrolebinding.go +++ b/informers/rbac/v1beta1/clusterrolebinding.go @@ -41,8 +41,11 @@ type clusterRoleBindingInformer struct { factory internalinterfaces.SharedInformerFactory } -func newClusterRoleBindingInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - sharedIndexInformer := cache.NewSharedIndexInformer( +// NewClusterRoleBindingInformer constructs a new informer for ClusterRoleBinding 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 NewClusterRoleBindingInformer(client kubernetes.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options v1.ListOptions) (runtime.Object, error) { return client.RbacV1beta1().ClusterRoleBindings().List(options) @@ -53,14 +56,16 @@ func newClusterRoleBindingInformer(client kubernetes.Interface, resyncPeriod tim }, &rbac_v1beta1.ClusterRoleBinding{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultClusterRoleBindingInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewClusterRoleBindingInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *clusterRoleBindingInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&rbac_v1beta1.ClusterRoleBinding{}, newClusterRoleBindingInformer) + return f.factory.InformerFor(&rbac_v1beta1.ClusterRoleBinding{}, defaultClusterRoleBindingInformer) } func (f *clusterRoleBindingInformer) Lister() v1beta1.ClusterRoleBindingLister { diff --git a/informers/rbac/v1beta1/role.go b/informers/rbac/v1beta1/role.go index bd0531b4..7fcf97f2 100644 --- a/informers/rbac/v1beta1/role.go +++ b/informers/rbac/v1beta1/role.go @@ -41,26 +41,31 @@ type roleInformer struct { factory internalinterfaces.SharedInformerFactory } -func newRoleInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - sharedIndexInformer := cache.NewSharedIndexInformer( +// NewRoleInformer constructs a new informer for Role 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 NewRoleInformer(client kubernetes.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.RbacV1beta1().Roles(v1.NamespaceAll).List(options) + return client.RbacV1beta1().Roles(namespace).List(options) }, WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - return client.RbacV1beta1().Roles(v1.NamespaceAll).Watch(options) + return client.RbacV1beta1().Roles(namespace).Watch(options) }, }, &rbac_v1beta1.Role{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultRoleInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewRoleInformer(client, v1.NamespaceAll, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *roleInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&rbac_v1beta1.Role{}, newRoleInformer) + return f.factory.InformerFor(&rbac_v1beta1.Role{}, defaultRoleInformer) } func (f *roleInformer) Lister() v1beta1.RoleLister { diff --git a/informers/rbac/v1beta1/rolebinding.go b/informers/rbac/v1beta1/rolebinding.go index 0f5c1ffb..d6e93bec 100644 --- a/informers/rbac/v1beta1/rolebinding.go +++ b/informers/rbac/v1beta1/rolebinding.go @@ -41,26 +41,31 @@ type roleBindingInformer struct { factory internalinterfaces.SharedInformerFactory } -func newRoleBindingInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - sharedIndexInformer := cache.NewSharedIndexInformer( +// NewRoleBindingInformer constructs a new informer for RoleBinding 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 NewRoleBindingInformer(client kubernetes.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.RbacV1beta1().RoleBindings(v1.NamespaceAll).List(options) + return client.RbacV1beta1().RoleBindings(namespace).List(options) }, WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - return client.RbacV1beta1().RoleBindings(v1.NamespaceAll).Watch(options) + return client.RbacV1beta1().RoleBindings(namespace).Watch(options) }, }, &rbac_v1beta1.RoleBinding{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultRoleBindingInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewRoleBindingInformer(client, v1.NamespaceAll, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *roleBindingInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&rbac_v1beta1.RoleBinding{}, newRoleBindingInformer) + return f.factory.InformerFor(&rbac_v1beta1.RoleBinding{}, defaultRoleBindingInformer) } func (f *roleBindingInformer) Lister() v1beta1.RoleBindingLister { diff --git a/informers/scheduling/v1alpha1/priorityclass.go b/informers/scheduling/v1alpha1/priorityclass.go index 2f7f2a24..9b1361c0 100644 --- a/informers/scheduling/v1alpha1/priorityclass.go +++ b/informers/scheduling/v1alpha1/priorityclass.go @@ -41,8 +41,11 @@ type priorityClassInformer struct { factory internalinterfaces.SharedInformerFactory } -func newPriorityClassInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - sharedIndexInformer := cache.NewSharedIndexInformer( +// NewPriorityClassInformer constructs a new informer for PriorityClass 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 NewPriorityClassInformer(client kubernetes.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options v1.ListOptions) (runtime.Object, error) { return client.SchedulingV1alpha1().PriorityClasses().List(options) @@ -53,14 +56,16 @@ func newPriorityClassInformer(client kubernetes.Interface, resyncPeriod time.Dur }, &scheduling_v1alpha1.PriorityClass{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultPriorityClassInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewPriorityClassInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *priorityClassInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&scheduling_v1alpha1.PriorityClass{}, newPriorityClassInformer) + return f.factory.InformerFor(&scheduling_v1alpha1.PriorityClass{}, defaultPriorityClassInformer) } func (f *priorityClassInformer) Lister() v1alpha1.PriorityClassLister { diff --git a/informers/settings/v1alpha1/podpreset.go b/informers/settings/v1alpha1/podpreset.go index e5907c31..226cec52 100644 --- a/informers/settings/v1alpha1/podpreset.go +++ b/informers/settings/v1alpha1/podpreset.go @@ -41,26 +41,31 @@ type podPresetInformer struct { factory internalinterfaces.SharedInformerFactory } -func newPodPresetInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - sharedIndexInformer := cache.NewSharedIndexInformer( +// NewPodPresetInformer constructs a new informer for PodPreset 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 NewPodPresetInformer(client kubernetes.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.SettingsV1alpha1().PodPresets(v1.NamespaceAll).List(options) + return client.SettingsV1alpha1().PodPresets(namespace).List(options) }, WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - return client.SettingsV1alpha1().PodPresets(v1.NamespaceAll).Watch(options) + return client.SettingsV1alpha1().PodPresets(namespace).Watch(options) }, }, &settings_v1alpha1.PodPreset{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultPodPresetInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewPodPresetInformer(client, v1.NamespaceAll, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *podPresetInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&settings_v1alpha1.PodPreset{}, newPodPresetInformer) + return f.factory.InformerFor(&settings_v1alpha1.PodPreset{}, defaultPodPresetInformer) } func (f *podPresetInformer) Lister() v1alpha1.PodPresetLister { diff --git a/informers/storage/v1/storageclass.go b/informers/storage/v1/storageclass.go index ccde500b..397474c3 100644 --- a/informers/storage/v1/storageclass.go +++ b/informers/storage/v1/storageclass.go @@ -41,8 +41,11 @@ type storageClassInformer struct { factory internalinterfaces.SharedInformerFactory } -func newStorageClassInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - sharedIndexInformer := cache.NewSharedIndexInformer( +// NewStorageClassInformer constructs a new informer for StorageClass 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 NewStorageClassInformer(client kubernetes.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) { return client.StorageV1().StorageClasses().List(options) @@ -53,14 +56,16 @@ func newStorageClassInformer(client kubernetes.Interface, resyncPeriod time.Dura }, &storage_v1.StorageClass{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultStorageClassInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewStorageClassInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *storageClassInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&storage_v1.StorageClass{}, newStorageClassInformer) + return f.factory.InformerFor(&storage_v1.StorageClass{}, defaultStorageClassInformer) } func (f *storageClassInformer) Lister() v1.StorageClassLister { diff --git a/informers/storage/v1beta1/storageclass.go b/informers/storage/v1beta1/storageclass.go index 88e65bd4..404e0a16 100644 --- a/informers/storage/v1beta1/storageclass.go +++ b/informers/storage/v1beta1/storageclass.go @@ -41,8 +41,11 @@ type storageClassInformer struct { factory internalinterfaces.SharedInformerFactory } -func newStorageClassInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - sharedIndexInformer := cache.NewSharedIndexInformer( +// NewStorageClassInformer constructs a new informer for StorageClass 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 NewStorageClassInformer(client kubernetes.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options v1.ListOptions) (runtime.Object, error) { return client.StorageV1beta1().StorageClasses().List(options) @@ -53,14 +56,16 @@ func newStorageClassInformer(client kubernetes.Interface, resyncPeriod time.Dura }, &storage_v1beta1.StorageClass{}, resyncPeriod, - cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, + indexers, ) +} - return sharedIndexInformer +func defaultStorageClassInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewStorageClassInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) } func (f *storageClassInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&storage_v1beta1.StorageClass{}, newStorageClassInformer) + return f.factory.InformerFor(&storage_v1beta1.StorageClass{}, defaultStorageClassInformer) } func (f *storageClassInformer) Lister() v1beta1.StorageClassLister {