1/*
2Copyright The Kubernetes Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8    http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17// Code generated by informer-gen. DO NOT EDIT.
18
19package informers
20
21import (
22	reflect "reflect"
23	sync "sync"
24	time "time"
25
26	v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27	runtime "k8s.io/apimachinery/pkg/runtime"
28	schema "k8s.io/apimachinery/pkg/runtime/schema"
29	admissionregistration "k8s.io/client-go/informers/admissionregistration"
30	apps "k8s.io/client-go/informers/apps"
31	auditregistration "k8s.io/client-go/informers/auditregistration"
32	autoscaling "k8s.io/client-go/informers/autoscaling"
33	batch "k8s.io/client-go/informers/batch"
34	certificates "k8s.io/client-go/informers/certificates"
35	coordination "k8s.io/client-go/informers/coordination"
36	core "k8s.io/client-go/informers/core"
37	events "k8s.io/client-go/informers/events"
38	extensions "k8s.io/client-go/informers/extensions"
39	internalinterfaces "k8s.io/client-go/informers/internalinterfaces"
40	networking "k8s.io/client-go/informers/networking"
41	node "k8s.io/client-go/informers/node"
42	policy "k8s.io/client-go/informers/policy"
43	rbac "k8s.io/client-go/informers/rbac"
44	scheduling "k8s.io/client-go/informers/scheduling"
45	settings "k8s.io/client-go/informers/settings"
46	storage "k8s.io/client-go/informers/storage"
47	kubernetes "k8s.io/client-go/kubernetes"
48	cache "k8s.io/client-go/tools/cache"
49)
50
51// SharedInformerOption defines the functional option type for SharedInformerFactory.
52type SharedInformerOption func(*sharedInformerFactory) *sharedInformerFactory
53
54type sharedInformerFactory struct {
55	client           kubernetes.Interface
56	namespace        string
57	tweakListOptions internalinterfaces.TweakListOptionsFunc
58	lock             sync.Mutex
59	defaultResync    time.Duration
60	customResync     map[reflect.Type]time.Duration
61
62	informers map[reflect.Type]cache.SharedIndexInformer
63	// startedInformers is used for tracking which informers have been started.
64	// This allows Start() to be called multiple times safely.
65	startedInformers map[reflect.Type]bool
66}
67
68// WithCustomResyncConfig sets a custom resync period for the specified informer types.
69func WithCustomResyncConfig(resyncConfig map[v1.Object]time.Duration) SharedInformerOption {
70	return func(factory *sharedInformerFactory) *sharedInformerFactory {
71		for k, v := range resyncConfig {
72			factory.customResync[reflect.TypeOf(k)] = v
73		}
74		return factory
75	}
76}
77
78// WithTweakListOptions sets a custom filter on all listers of the configured SharedInformerFactory.
79func WithTweakListOptions(tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerOption {
80	return func(factory *sharedInformerFactory) *sharedInformerFactory {
81		factory.tweakListOptions = tweakListOptions
82		return factory
83	}
84}
85
86// WithNamespace limits the SharedInformerFactory to the specified namespace.
87func WithNamespace(namespace string) SharedInformerOption {
88	return func(factory *sharedInformerFactory) *sharedInformerFactory {
89		factory.namespace = namespace
90		return factory
91	}
92}
93
94// NewSharedInformerFactory constructs a new instance of sharedInformerFactory for all namespaces.
95func NewSharedInformerFactory(client kubernetes.Interface, defaultResync time.Duration) SharedInformerFactory {
96	return NewSharedInformerFactoryWithOptions(client, defaultResync)
97}
98
99// NewFilteredSharedInformerFactory constructs a new instance of sharedInformerFactory.
100// Listers obtained via this SharedInformerFactory will be subject to the same filters
101// as specified here.
102// Deprecated: Please use NewSharedInformerFactoryWithOptions instead
103func NewFilteredSharedInformerFactory(client kubernetes.Interface, defaultResync time.Duration, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerFactory {
104	return NewSharedInformerFactoryWithOptions(client, defaultResync, WithNamespace(namespace), WithTweakListOptions(tweakListOptions))
105}
106
107// NewSharedInformerFactoryWithOptions constructs a new instance of a SharedInformerFactory with additional options.
108func NewSharedInformerFactoryWithOptions(client kubernetes.Interface, defaultResync time.Duration, options ...SharedInformerOption) SharedInformerFactory {
109	factory := &sharedInformerFactory{
110		client:           client,
111		namespace:        v1.NamespaceAll,
112		defaultResync:    defaultResync,
113		informers:        make(map[reflect.Type]cache.SharedIndexInformer),
114		startedInformers: make(map[reflect.Type]bool),
115		customResync:     make(map[reflect.Type]time.Duration),
116	}
117
118	// Apply all options
119	for _, opt := range options {
120		factory = opt(factory)
121	}
122
123	return factory
124}
125
126// Start initializes all requested informers.
127func (f *sharedInformerFactory) Start(stopCh <-chan struct{}) {
128	f.lock.Lock()
129	defer f.lock.Unlock()
130
131	for informerType, informer := range f.informers {
132		if !f.startedInformers[informerType] {
133			go informer.Run(stopCh)
134			f.startedInformers[informerType] = true
135		}
136	}
137}
138
139// WaitForCacheSync waits for all started informers' cache were synced.
140func (f *sharedInformerFactory) WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool {
141	informers := func() map[reflect.Type]cache.SharedIndexInformer {
142		f.lock.Lock()
143		defer f.lock.Unlock()
144
145		informers := map[reflect.Type]cache.SharedIndexInformer{}
146		for informerType, informer := range f.informers {
147			if f.startedInformers[informerType] {
148				informers[informerType] = informer
149			}
150		}
151		return informers
152	}()
153
154	res := map[reflect.Type]bool{}
155	for informType, informer := range informers {
156		res[informType] = cache.WaitForCacheSync(stopCh, informer.HasSynced)
157	}
158	return res
159}
160
161// InternalInformerFor returns the SharedIndexInformer for obj using an internal
162// client.
163func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) cache.SharedIndexInformer {
164	f.lock.Lock()
165	defer f.lock.Unlock()
166
167	informerType := reflect.TypeOf(obj)
168	informer, exists := f.informers[informerType]
169	if exists {
170		return informer
171	}
172
173	resyncPeriod, exists := f.customResync[informerType]
174	if !exists {
175		resyncPeriod = f.defaultResync
176	}
177
178	informer = newFunc(f.client, resyncPeriod)
179	f.informers[informerType] = informer
180
181	return informer
182}
183
184// SharedInformerFactory provides shared informers for resources in all known
185// API group versions.
186type SharedInformerFactory interface {
187	internalinterfaces.SharedInformerFactory
188	ForResource(resource schema.GroupVersionResource) (GenericInformer, error)
189	WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool
190
191	Admissionregistration() admissionregistration.Interface
192	Apps() apps.Interface
193	Auditregistration() auditregistration.Interface
194	Autoscaling() autoscaling.Interface
195	Batch() batch.Interface
196	Certificates() certificates.Interface
197	Coordination() coordination.Interface
198	Core() core.Interface
199	Events() events.Interface
200	Extensions() extensions.Interface
201	Networking() networking.Interface
202	Node() node.Interface
203	Policy() policy.Interface
204	Rbac() rbac.Interface
205	Scheduling() scheduling.Interface
206	Settings() settings.Interface
207	Storage() storage.Interface
208}
209
210func (f *sharedInformerFactory) Admissionregistration() admissionregistration.Interface {
211	return admissionregistration.New(f, f.namespace, f.tweakListOptions)
212}
213
214func (f *sharedInformerFactory) Apps() apps.Interface {
215	return apps.New(f, f.namespace, f.tweakListOptions)
216}
217
218func (f *sharedInformerFactory) Auditregistration() auditregistration.Interface {
219	return auditregistration.New(f, f.namespace, f.tweakListOptions)
220}
221
222func (f *sharedInformerFactory) Autoscaling() autoscaling.Interface {
223	return autoscaling.New(f, f.namespace, f.tweakListOptions)
224}
225
226func (f *sharedInformerFactory) Batch() batch.Interface {
227	return batch.New(f, f.namespace, f.tweakListOptions)
228}
229
230func (f *sharedInformerFactory) Certificates() certificates.Interface {
231	return certificates.New(f, f.namespace, f.tweakListOptions)
232}
233
234func (f *sharedInformerFactory) Coordination() coordination.Interface {
235	return coordination.New(f, f.namespace, f.tweakListOptions)
236}
237
238func (f *sharedInformerFactory) Core() core.Interface {
239	return core.New(f, f.namespace, f.tweakListOptions)
240}
241
242func (f *sharedInformerFactory) Events() events.Interface {
243	return events.New(f, f.namespace, f.tweakListOptions)
244}
245
246func (f *sharedInformerFactory) Extensions() extensions.Interface {
247	return extensions.New(f, f.namespace, f.tweakListOptions)
248}
249
250func (f *sharedInformerFactory) Networking() networking.Interface {
251	return networking.New(f, f.namespace, f.tweakListOptions)
252}
253
254func (f *sharedInformerFactory) Node() node.Interface {
255	return node.New(f, f.namespace, f.tweakListOptions)
256}
257
258func (f *sharedInformerFactory) Policy() policy.Interface {
259	return policy.New(f, f.namespace, f.tweakListOptions)
260}
261
262func (f *sharedInformerFactory) Rbac() rbac.Interface {
263	return rbac.New(f, f.namespace, f.tweakListOptions)
264}
265
266func (f *sharedInformerFactory) Scheduling() scheduling.Interface {
267	return scheduling.New(f, f.namespace, f.tweakListOptions)
268}
269
270func (f *sharedInformerFactory) Settings() settings.Interface {
271	return settings.New(f, f.namespace, f.tweakListOptions)
272}
273
274func (f *sharedInformerFactory) Storage() storage.Interface {
275	return storage.New(f, f.namespace, f.tweakListOptions)
276}
277